11import { app , BrowserWindow , ipcMain , session , dialog } from 'electron' ;
22import { join } from 'path' ;
3- import { initialize , enable } from '@electron/remote/main' ;
3+ import { initialize , enable } from '@electron/remote/main/index.js' ;
4+ import Store from 'electron-store' ;
45
56initialize ( ) ;
67
8+ // Window Constants
9+ const WINDOW_MIN_WIDTH = 1280 ;
10+ const WINDOW_MIN_HEIGHT = 800 ;
11+
12+ // For electron-store Type-Safety
13+ type SchemaType = {
14+ dimensions : {
15+ width : number ,
16+ height : number
17+ } ,
18+ position : {
19+ x : number ,
20+ y : number
21+ }
22+ } ;
23+
24+ const windowStore = new Store < SchemaType > ( { schema : {
25+ dimensions : {
26+ type : 'object' ,
27+ properties : {
28+ width : {
29+ type : 'number' ,
30+ minimum : WINDOW_MIN_WIDTH ,
31+ default : WINDOW_MIN_WIDTH
32+ } ,
33+ height : {
34+ type : 'number' ,
35+ minimum : WINDOW_MIN_HEIGHT ,
36+ default : WINDOW_MIN_HEIGHT
37+ } ,
38+ } ,
39+ required : [ 'width' , 'height' ]
40+ } ,
41+ position : {
42+ type : 'object' ,
43+ properties : {
44+ x : {
45+ type : 'number'
46+ } ,
47+ y : {
48+ type : 'number'
49+ }
50+ } ,
51+ required : [ 'x' , 'y' ]
52+ }
53+ } } ) ;
54+
755let mainWindow : BrowserWindow | null = null ;
856
957function createWindow ( ) {
@@ -19,12 +67,12 @@ function createWindow() {
1967 }
2068
2169 mainWindow = new BrowserWindow ( {
22- minWidth : 1280 ,
23- minHeight : 800 ,
24- width : 1280 ,
25- height : 800 ,
26- y : 0 ,
27- x : 500 ,
70+ minWidth : WINDOW_MIN_WIDTH ,
71+ minHeight : WINDOW_MIN_HEIGHT ,
72+ width : windowStore . get ( 'dimensions.width' ) ,
73+ height : windowStore . get ( 'dimensions.height' ) ,
74+ x : windowStore . get ( 'position.x' ) ,
75+ y : windowStore . get ( 'position.y' ) ,
2876 transparent : false ,
2977 frame : false ,
3078 webPreferences : {
@@ -34,6 +82,20 @@ function createWindow() {
3482 }
3583 } ) ;
3684
85+ mainWindow . on ( 'close' , ( ) => {
86+ const bounds = mainWindow ?. getBounds ( ) ;
87+
88+ windowStore . set ( 'dimensions' , {
89+ width : bounds ?. width ,
90+ height : bounds ?. height
91+ } ) ;
92+
93+ windowStore . set ( 'position' , {
94+ x : bounds ?. x ,
95+ y : bounds ?. y
96+ } ) ;
97+ } ) ;
98+
3799 enable ( mainWindow . webContents ) ;
38100
39101 if ( process . env . NODE_ENV === 'development' ) {
0 commit comments