Merge pull request #827 from feross/window-position

remember window position
This commit is contained in:
Dan Flettre
2016-09-19 16:04:46 -05:00
committed by GitHub
4 changed files with 41 additions and 11 deletions

View File

@@ -19,7 +19,7 @@ console.log('Production: %s portable: %s test: %s',
IS_PRODUCTION, IS_PORTABLE, IS_TEST)
if (IS_PORTABLE) console.log('Portable path: %s', PORTABLE_PATH)
module.exports = {
let cfg = {
ANNOUNCEMENT_URL: 'https://webtorrent.io/desktop/announcement',
AUTO_UPDATE_URL: 'https://webtorrent.io/desktop/update',
CRASH_REPORT_URL: 'https://webtorrent.io/desktop/crash-report',
@@ -94,9 +94,19 @@ module.exports = {
WINDOW_WEBTORRENT: 'file://' + path.join(__dirname, '..', 'static', 'webtorrent.html'),
WINDOW_MIN_HEIGHT: 38 + (120 * 2), // header height + 2 torrents
WINDOW_MIN_WIDTH: 425
WINDOW_MIN_WIDTH: 425,
UI_HEADER_HEIGHT: 38,
UI_TORRENT_HEIGHT: 100
}
cfg.DEFAULT_BOUNDS = {
width: 500,
height: cfg.UI_HEADER_HEIGHT + (cfg.UI_TORRENT_HEIGHT * (cfg.DEFAULT_TORRENTS.length + 1))
}
module.exports = cfg
function getConfigPath () {
if (IS_PORTABLE) {
return PORTABLE_PATH

View File

@@ -13,6 +13,7 @@ const ipc = require('./ipc')
const log = require('./log')
const menu = require('./menu')
const squirrelWin32 = require('./squirrel-win32')
const State = require('../renderer/lib/state')
const tray = require('./tray')
const updater = require('./updater')
const userTasks = require('./user-tasks')
@@ -72,7 +73,10 @@ function init () {
app.on('ready', function () {
isReady = true
windows.main.init({hidden: hidden})
State.load(function (err, state) {
if (err) throw err
windows.main.init(state, {hidden: hidden})
})
windows.webtorrent.init()
menu.init()

View File

@@ -23,13 +23,13 @@ const log = require('../log')
const menu = require('../menu')
const tray = require('../tray')
const HEADER_HEIGHT = 38
const TORRENT_HEIGHT = 100
function init (options) {
function init (state, options) {
if (main.win) {
return main.win.show()
}
const initialBounds = Object.assign(config.DEFAULT_BOUNDS, state.saved.bounds)
const win = main.win = new electron.BrowserWindow({
backgroundColor: '#282828',
darkTheme: true, // Forces dark theme (GTK+3)
@@ -39,14 +39,16 @@ function init (options) {
title: config.APP_WINDOW_TITLE,
titleBarStyle: 'hidden-inset', // Hide title bar (Mac)
useContentSize: true, // Specify web page size without OS chrome
width: 500,
height: HEADER_HEIGHT + (TORRENT_HEIGHT * 6), // header height + 5 torrents
show: !options.hidden
show: !options.hidden,
width: initialBounds.width,
height: initialBounds.height,
x: initialBounds.x,
y: initialBounds.y
})
win.loadURL(config.WINDOW_MAIN)
if (win.setSheetOffset) win.setSheetOffset(HEADER_HEIGHT)
if (win.setSheetOffset) win.setSheetOffset(config.UI_HEADER_HEIGHT)
win.webContents.on('dom-ready', function () {
menu.onToggleFullScreen(main.win.isFullScreen())
@@ -70,6 +72,14 @@ function init (options) {
win.setMenuBarVisibility(true)
})
win.on('move', function (e) {
send('windowBoundsChanged', e.sender.getBounds())
})
win.on('resize', function (e) {
send('windowBoundsChanged', e.sender.getBounds())
})
win.on('close', function (e) {
if (process.platform !== 'darwin' && !tray.hasTray()) {
app.quit()

View File

@@ -288,6 +288,7 @@ function setupIpc () {
ipcRenderer.on('dispatch', (e, ...args) => dispatch(...args))
ipcRenderer.on('fullscreenChanged', onFullscreenChanged)
ipcRenderer.on('windowBoundsChanged', onWindowBoundsChanged)
const tc = controllers.torrent
ipcRenderer.on('wt-infohash', (e, ...args) => tc.torrentInfoHash(...args))
@@ -462,6 +463,11 @@ function onFullscreenChanged (e, isFullScreen) {
update()
}
function onWindowBoundsChanged (e, newBounds) {
state.saved.bounds = newBounds
dispatch('saveStateThrottled')
}
function checkDownloadPath () {
fs.stat(state.saved.prefs.downloadPath, function (err, stat) {
if (err) {