diff --git a/electron.js b/electron.js index 5811ade6a5..32b570f8ff 100644 --- a/electron.js +++ b/electron.js @@ -107,7 +107,7 @@ nativeTheme.on('updated', () => { }); function createMainWindow () { - mainWindow = WindowManager.createMain({ withState: true }); + mainWindow = WindowManager.createMain({ withState: true, route: Util.getRouteFromUrl(deeplinkingUrl) }); mainWindow.once('ready-to-show', () => { mainWindow.show(); @@ -123,6 +123,27 @@ function createMainWindow () { ); }; + mainWindow.on('close', (e) => { + Util.log('info', 'closeMain: ' + app.isQuiting); + + if (app.isQuiting) { + return; + }; + + e.preventDefault(); + if (!is.linux) { + if (win.isFullScreen()) { + win.setFullScreen(false); + win.once('leave-full-screen', () => { win.hide(); }); + } else { + win.hide(); + }; + } else { + this.exit(false); + }; + return false; + }); + registerIpcEventsMain(); registerIpcEventsWindow(); @@ -143,16 +164,7 @@ function createMainWindow () { }; function createChildWindow (route) { - const win = WindowManager.createMain({ withState: false }); - - win.once('ready-to-show', () => { - win.show(); - - if (route) { - Util.send(win, 'route', route); - }; - }); - + WindowManager.createMain({ withState: false, route: route }); registerIpcEventsWindow(); }; diff --git a/electron/js/window.js b/electron/js/window.js index 1ec1b98ec8..56496f71e1 100644 --- a/electron/js/window.js +++ b/electron/js/window.js @@ -9,6 +9,8 @@ const port = process.env.SERVER_PORT; const MenuManager = require('./menu.js'); const Util = require('./util.js'); +const DEFAULT_WIDTH = 800; +const DEFAULT_HEIGHT = 600; const MIN_WIDTH = 752; const MIN_HEIGHT = 480; @@ -43,14 +45,17 @@ class WindowManager { }; createMain (options) { - const { withState } = options; + const { withState, route } = options; const image = nativeImage.createFromPath(path.join(Util.imagePath(), 'icon512x512.png')); - const state = windowStateKeeper({ defaultWidth: 800, defaultHeight: 600 }); + const state = windowStateKeeper({ defaultWidth: DEFAULT_WIDTH, defaultHeight: DEFAULT_HEIGHT }); let param = { minWidth: MIN_WIDTH, minHeight: MIN_HEIGHT, + width: DEFAULT_WIDTH, + height: DEFAULT_HEIGHT, + webPreferences: { nativeWindowOpen: true, nodeIntegration: true, @@ -101,30 +106,17 @@ class WindowManager { win.loadFile('./dist/index.html'); }; + win.once('ready-to-show', () => { + win.show(); + + if (route) { + Util.send(win, 'route', route); + }; + }); + win.on('enter-full-screen', () => { Util.send(win, 'enter-full-screen'); }); win.on('leave-full-screen', () => { Util.send(win, 'leave-full-screen'); }); - win.on('close', (e) => { - Util.log('info', 'close: ' + app.isQuiting); - - if (app.isQuiting) { - return; - }; - - e.preventDefault(); - if (!is.linux) { - if (win.isFullScreen()) { - win.setFullScreen(false); - win.once('leave-full-screen', () => { win.hide(); }); - } else { - win.hide(); - }; - } else { - this.exit(false); - }; - return false; - }); - return win; }; diff --git a/src/ts/app.tsx b/src/ts/app.tsx index 957169e21a..8b0cf24ece 100644 --- a/src/ts/app.tsx +++ b/src/ts/app.tsx @@ -332,7 +332,10 @@ class App extends React.Component { keyboard.init(); analytics.init(); - this.setIpcEvents(); + this.registerIpcEvents(); + + $(window).off('beforeunload').on('beforeunload', () => { + }); }; initStorage () { @@ -400,7 +403,7 @@ class App extends React.Component { Util.addBodyClass('theme', theme); }; - setIpcEvents () { + registerIpcEvents () { const node = $(ReactDOM.findDOMNode(this)); const logo = node.find('#logo'); const logsDir = path.join(userPath, 'logs');