diff --git a/src/config.js b/src/config.js index 95e4c177..8c5a0866 100644 --- a/src/config.js +++ b/src/config.js @@ -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 diff --git a/src/main/index.js b/src/main/index.js index 02b54228..c82d8846 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -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() diff --git a/src/main/windows/main.js b/src/main/windows/main.js index 9e652ff9..8e64ed42 100644 --- a/src/main/windows/main.js +++ b/src/main/windows/main.js @@ -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() diff --git a/src/renderer/main.js b/src/renderer/main.js index 3c2cbdf0..d0104e31 100644 --- a/src/renderer/main.js +++ b/src/renderer/main.js @@ -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) {