@@ -15,10 +15,14 @@ import ipcApi from './electron/ipc-api';
1515import Tray from './lib/Tray' ;
1616import Settings from './electron/Settings' ;
1717import handleDeepLink from './electron/deepLinking' ;
18+ import { isPositionValid } from './electron/windowUtils' ;
1819import { appId } from './package.json' ; // eslint-disable-line import/no-unresolved
1920import './electron/exception' ;
2021
21- import { DEFAULT_APP_SETTINGS } from './config' ;
22+ import {
23+ DEFAULT_APP_SETTINGS ,
24+ DEFAULT_WINDOW_OPTIONS ,
25+ } from './config' ;
2226/* eslint-enable import/first */
2327
2428const debug = require ( 'debug' ) ( 'Franz:App' ) ;
@@ -52,6 +56,15 @@ const isSecondInstance = app.makeSingleInstance((argv) => {
5256 }
5357 }
5458 }
59+
60+ if ( argv . includes ( '--reset-window' ) ) {
61+ // Needs to be delayed to not interfere with mainWindow.restore();
62+ setTimeout ( ( ) => {
63+ debug ( 'Resetting windows via Task' ) ;
64+ mainWindow . setPosition ( DEFAULT_WINDOW_OPTIONS . x + 100 , DEFAULT_WINDOW_OPTIONS . y + 100 ) ;
65+ mainWindow . setSize ( DEFAULT_WINDOW_OPTIONS . width , DEFAULT_WINDOW_OPTIONS . height ) ;
66+ } , 1 ) ;
67+ }
5568} ) ;
5669
5770if ( isSecondInstance ) {
@@ -78,14 +91,23 @@ if (!settings.get('enableGPUAcceleration')) {
7891const createWindow = ( ) => {
7992 // Remember window size
8093 const mainWindowState = windowStateKeeper ( {
81- defaultWidth : 800 ,
82- defaultHeight : 600 ,
94+ defaultWidth : DEFAULT_WINDOW_OPTIONS . width ,
95+ defaultHeight : DEFAULT_WINDOW_OPTIONS . height ,
8396 } ) ;
8497
98+ let posX = mainWindowState . x || DEFAULT_WINDOW_OPTIONS . x ;
99+ let posY = mainWindowState . y || DEFAULT_WINDOW_OPTIONS . y ;
100+
101+ if ( ! isPositionValid ( { x : posX , y : posY } ) ) {
102+ debug ( 'Window is out of screen bounds, resetting window' ) ;
103+ posX = DEFAULT_WINDOW_OPTIONS . x ;
104+ posY = DEFAULT_WINDOW_OPTIONS . y ;
105+ }
106+
85107 // Create the browser window.
86108 mainWindow = new BrowserWindow ( {
87- x : mainWindowState . x ,
88- y : mainWindowState . y ,
109+ x : posX ,
110+ y : posY ,
89111 width : mainWindowState . width ,
90112 height : mainWindowState . height ,
91113 minWidth : 600 ,
@@ -187,7 +209,20 @@ const createWindow = () => {
187209// This method will be called when Electron has finished
188210// initialization and is ready to create browser windows.
189211// Some APIs can only be used after this event occurs.
190- app . on ( 'ready' , createWindow ) ;
212+ app . on ( 'ready' , ( ) => {
213+ if ( process . platform === 'win32' ) {
214+ app . setUserTasks ( [ {
215+ program : process . execPath ,
216+ arguments : `${ isDevMode ? `${ __dirname } ` : '' } --reset-window` ,
217+ iconPath : path . join ( `${ __dirname } ` , '../src/assets/images/taskbar/win32/display.ico' ) ,
218+ iconIndex : 0 ,
219+ title : 'Move Franz to Current Display' ,
220+ description : 'Restore the position and size of Franz' ,
221+ } ] ) ;
222+ }
223+
224+ createWindow ( ) ;
225+ } ) ;
191226
192227// This is the worst possible implementation as the webview.webContents based callback doesn't work 🖕
193228app . on ( 'login' , ( event , webContents , request , authInfo , callback ) => {
0 commit comments