remember window position
This commit is contained in:
@@ -18,7 +18,7 @@ console.log('Production: %s portable: %s test: %s',
|
|||||||
IS_PRODUCTION, IS_PORTABLE, IS_TEST)
|
IS_PRODUCTION, IS_PORTABLE, IS_TEST)
|
||||||
if (IS_PORTABLE) console.log('Portable path: %s', PORTABLE_PATH)
|
if (IS_PORTABLE) console.log('Portable path: %s', PORTABLE_PATH)
|
||||||
|
|
||||||
module.exports = {
|
let cfg = {
|
||||||
ANNOUNCEMENT_URL: 'https://webtorrent.io/desktop/announcement',
|
ANNOUNCEMENT_URL: 'https://webtorrent.io/desktop/announcement',
|
||||||
AUTO_UPDATE_URL: 'https://webtorrent.io/desktop/update',
|
AUTO_UPDATE_URL: 'https://webtorrent.io/desktop/update',
|
||||||
CRASH_REPORT_URL: 'https://webtorrent.io/desktop/crash-report',
|
CRASH_REPORT_URL: 'https://webtorrent.io/desktop/crash-report',
|
||||||
@@ -93,9 +93,19 @@ module.exports = {
|
|||||||
WINDOW_WEBTORRENT: 'file://' + path.join(__dirname, '..', 'static', 'webtorrent.html'),
|
WINDOW_WEBTORRENT: 'file://' + path.join(__dirname, '..', 'static', 'webtorrent.html'),
|
||||||
|
|
||||||
WINDOW_MIN_HEIGHT: 38 + (120 * 2), // header height + 2 torrents
|
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 () {
|
function getConfigPath () {
|
||||||
if (IS_PORTABLE) {
|
if (IS_PORTABLE) {
|
||||||
return PORTABLE_PATH
|
return PORTABLE_PATH
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ const ipc = require('./ipc')
|
|||||||
const log = require('./log')
|
const log = require('./log')
|
||||||
const menu = require('./menu')
|
const menu = require('./menu')
|
||||||
const squirrelWin32 = require('./squirrel-win32')
|
const squirrelWin32 = require('./squirrel-win32')
|
||||||
|
const State = require('../renderer/lib/state')
|
||||||
const tray = require('./tray')
|
const tray = require('./tray')
|
||||||
const updater = require('./updater')
|
const updater = require('./updater')
|
||||||
const userTasks = require('./user-tasks')
|
const userTasks = require('./user-tasks')
|
||||||
@@ -72,7 +73,10 @@ function init () {
|
|||||||
app.on('ready', function () {
|
app.on('ready', function () {
|
||||||
isReady = true
|
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()
|
windows.webtorrent.init()
|
||||||
menu.init()
|
menu.init()
|
||||||
|
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ const log = require('../log')
|
|||||||
const menu = require('../menu')
|
const menu = require('../menu')
|
||||||
const tray = require('../tray')
|
const tray = require('../tray')
|
||||||
|
|
||||||
const HEADER_HEIGHT = 38
|
function init (state, options) {
|
||||||
const TORRENT_HEIGHT = 100
|
|
||||||
|
|
||||||
function init (options) {
|
|
||||||
if (main.win) {
|
if (main.win) {
|
||||||
return main.win.show()
|
return main.win.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const initialBounds = Object.assign(config.DEFAULT_BOUNDS, state.saved.bounds)
|
||||||
|
|
||||||
const win = main.win = new electron.BrowserWindow({
|
const win = main.win = new electron.BrowserWindow({
|
||||||
backgroundColor: '#282828',
|
backgroundColor: '#282828',
|
||||||
darkTheme: true, // Forces dark theme (GTK+3)
|
darkTheme: true, // Forces dark theme (GTK+3)
|
||||||
@@ -39,14 +39,16 @@ function init (options) {
|
|||||||
title: config.APP_WINDOW_TITLE,
|
title: config.APP_WINDOW_TITLE,
|
||||||
titleBarStyle: 'hidden-inset', // Hide title bar (Mac)
|
titleBarStyle: 'hidden-inset', // Hide title bar (Mac)
|
||||||
useContentSize: true, // Specify web page size without OS chrome
|
useContentSize: true, // Specify web page size without OS chrome
|
||||||
width: 500,
|
show: !options.hidden,
|
||||||
height: HEADER_HEIGHT + (TORRENT_HEIGHT * 6), // header height + 5 torrents
|
width: initialBounds.width,
|
||||||
show: !options.hidden
|
height: initialBounds.height,
|
||||||
|
x: initialBounds.x,
|
||||||
|
y: initialBounds.y
|
||||||
})
|
})
|
||||||
|
|
||||||
win.loadURL(config.WINDOW_MAIN)
|
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 () {
|
win.webContents.on('dom-ready', function () {
|
||||||
menu.onToggleFullScreen(main.win.isFullScreen())
|
menu.onToggleFullScreen(main.win.isFullScreen())
|
||||||
@@ -70,6 +72,14 @@ function init (options) {
|
|||||||
win.setMenuBarVisibility(true)
|
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) {
|
win.on('close', function (e) {
|
||||||
if (process.platform !== 'darwin' && !tray.hasTray()) {
|
if (process.platform !== 'darwin' && !tray.hasTray()) {
|
||||||
app.quit()
|
app.quit()
|
||||||
|
|||||||
@@ -288,6 +288,7 @@ function setupIpc () {
|
|||||||
ipcRenderer.on('dispatch', (e, ...args) => dispatch(...args))
|
ipcRenderer.on('dispatch', (e, ...args) => dispatch(...args))
|
||||||
|
|
||||||
ipcRenderer.on('fullscreenChanged', onFullscreenChanged)
|
ipcRenderer.on('fullscreenChanged', onFullscreenChanged)
|
||||||
|
ipcRenderer.on('windowBoundsChanged', onWindowBoundsChanged)
|
||||||
|
|
||||||
const tc = controllers.torrent
|
const tc = controllers.torrent
|
||||||
ipcRenderer.on('wt-infohash', (e, ...args) => tc.torrentInfoHash(...args))
|
ipcRenderer.on('wt-infohash', (e, ...args) => tc.torrentInfoHash(...args))
|
||||||
@@ -462,6 +463,11 @@ function onFullscreenChanged (e, isFullScreen) {
|
|||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onWindowBoundsChanged (e, newBounds) {
|
||||||
|
state.saved.bounds = newBounds
|
||||||
|
dispatch('saveStateThrottled')
|
||||||
|
}
|
||||||
|
|
||||||
function checkDownloadPath () {
|
function checkDownloadPath () {
|
||||||
fs.stat(state.saved.prefs.downloadPath, function (err, stat) {
|
fs.stat(state.saved.prefs.downloadPath, function (err, stat) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user