@@ -32,11 +32,14 @@ import {
3232 ZOOM_PERCENT_ARRAY ,
3333} from '@main/modules/electron/electron.constants'
3434import { ElectronController } from '@main/modules/electron/electron.controller'
35+ import { electronStore } from '@main/modules/electron/electron.store'
3536import { AppControlAction } from '@main/modules/electron/types/app-control.type'
3637import { LanguageOption } from '@main/modules/electron/types/language.types'
3738
3839@Injectable ( )
3940export class ElectronService implements OnModuleInit , OnApplicationBootstrap {
41+ private readonly store = electronStore
42+
4043 public readonly APP_PATH = app . getAppPath ( )
4144 public readonly PROTOCOL = protocols . name
4245 public readonly IS_MAC = process . platform === 'darwin'
@@ -254,6 +257,8 @@ export const generatedIpcOnContext = {`
254257 return
255258 }
256259
260+ const windowPosition = this . store . get ( 'windowPosition' )
261+
257262 this . window = new BrowserWindow ( {
258263 width : this . APP_WIDTH ,
259264 height : this . APP_HEIGHT ,
@@ -264,6 +269,7 @@ export const generatedIpcOnContext = {`
264269 frame : false ,
265270 icon : this . ICON ,
266271 resizable : false ,
272+ ...windowPosition ,
267273 webPreferences : {
268274 preload : this . PRELOAD_PATH ,
269275 } ,
@@ -288,6 +294,10 @@ export const generatedIpcOnContext = {`
288294 this . window = null
289295 } )
290296
297+ this . window . on ( 'moved' , ( ) => {
298+ this . saveCurrentWindowPosition ( )
299+ } )
300+
291301 this . window . webContents . setWindowOpenHandler ( ( { url } ) => {
292302 if ( url . startsWith ( 'https:' ) ) {
293303 shell . openExternal ( url )
@@ -388,6 +398,14 @@ export const generatedIpcOnContext = {`
388398 await i18next . changeLanguage ( value ! )
389399 this . controller . onChangeLanguage ( value ! )
390400 } )
401+
402+ this . configService . onChange ( 'general.restoreWindowPosition' , value => {
403+ if ( value ) {
404+ this . saveCurrentWindowPosition ( )
405+ } else {
406+ this . store . delete ( 'windowPosition' )
407+ }
408+ } )
391409 }
392410
393411 private createTray ( ) {
@@ -399,13 +417,39 @@ export const generatedIpcOnContext = {`
399417 this . reloadContextMenu ( )
400418 }
401419
420+ private saveCurrentWindowPosition ( ) {
421+ if ( this . configService . get ( 'general.restoreWindowPosition' ) === false || ! this . window ) return
422+
423+ const { x, y } = this . window . getBounds ( )
424+
425+ this . store . set ( 'windowPosition' , {
426+ x,
427+ y,
428+ } )
429+ }
430+
431+ private resetWindowPosition ( ) {
432+ if ( this . window ) {
433+ this . window . center ( )
434+ this . window . focus ( )
435+ this . saveCurrentWindowPosition ( )
436+ } else {
437+ this . store . delete ( 'windowPosition' )
438+ }
439+ }
440+
402441 private reloadContextMenu ( ) {
403442 const template : MenuItemConstructorOptions [ ] = [
404443 {
405444 label : i18next . t ( 'main.contextMenu.showHome' ) ,
406445 type : 'normal' ,
407446 click : ( ) => this . createWindow ( ) ,
408447 } ,
448+ {
449+ label : i18next . t ( 'main.contextMenu.resetWindowPosition' ) ,
450+ type : 'normal' ,
451+ click : ( ) => this . resetWindowPosition ( ) ,
452+ } ,
409453 {
410454 label : i18next . t ( 'main.contextMenu.setAppZoom' ) ,
411455 type : 'submenu' ,
0 commit comments