File tree 4 files changed +33
-4
lines changed
4 files changed +33
-4
lines changed Original file line number Diff line number Diff line change 6
6
getAllFiles
7
7
} = require ( './helpers.js' )
8
8
9
- module . exports = function registerIPCHandlers ( win , ipcMain ) {
9
+ module . exports = function registerIPCHandlers ( win , ipcMain , app ) {
10
10
ipcMain . handle ( 'open-folder' , async ( event ) => {
11
11
console . log ( 'ipcMain' , 'open-folder' )
12
12
const folder = await openFolderDialog ( win )
@@ -107,4 +107,15 @@ module.exports = function registerIPCHandlers(win, ipcMain) {
107
107
108
108
win . setMinimumSize ( minWidth , minHeight )
109
109
} )
110
+
111
+ ipcMain . handle ( 'confirm-close' , ( ) => {
112
+ console . log ( 'ipcMain' , 'confirm-close' )
113
+ app . exit ( )
114
+ } )
115
+
116
+ win . on ( 'close' , ( event ) => {
117
+ console . log ( 'BrowserWindow' , 'close' )
118
+ event . preventDefault ( )
119
+ win . webContents . send ( 'check-before-close' )
120
+ } )
110
121
}
Original file line number Diff line number Diff line change @@ -23,11 +23,17 @@ function createWindow () {
23
23
// and load the index.html of the app.
24
24
win . loadFile ( 'ui/arduino/index.html' )
25
25
26
- registerIPCHandlers ( win , ipcMain )
26
+ registerIPCHandlers ( win , ipcMain , app )
27
27
registerMenu ( win )
28
+
29
+ app . on ( 'activate' , ( ) => {
30
+ if ( BrowserWindow . getAllWindows ( ) . length === 0 ) createWindow ( )
31
+ } )
32
+ // app.on('window-all-closed', () => {
33
+ // if (process.platform !== 'darwin') app.quit()
34
+ // })
28
35
}
29
36
30
37
31
38
// TODO: Loading splash screen
32
-
33
39
app . whenReady ( ) . then ( createWindow )
Original file line number Diff line number Diff line change @@ -151,9 +151,12 @@ const Disk = {
151
151
const Window = {
152
152
setWindowSize : ( minWidth , minHeight ) => {
153
153
ipcRenderer . invoke ( 'set-window-size' , minWidth , minHeight )
154
- }
154
+ } ,
155
+ beforeClose : ( callback ) => ipcRenderer . on ( 'check-before-close' , callback ) ,
156
+ confirmClose : ( ) => ipcRenderer . invoke ( 'confirm-close' )
155
157
}
156
158
159
+
157
160
contextBridge . exposeInMainWorld ( 'BridgeSerial' , Serial )
158
161
contextBridge . exposeInMainWorld ( 'BridgeDisk' , Disk )
159
162
contextBridge . exposeInMainWorld ( 'BridgeWindow' , Window )
Original file line number Diff line number Diff line change @@ -1303,6 +1303,15 @@ async function store(state, emitter) {
1303
1303
emitter . emit ( 'render' )
1304
1304
} )
1305
1305
1306
+ win . beforeClose ( async ( ) => {
1307
+ const hasChanges = ! ! state . openFiles . find ( f => f . parentFolder && f . hasChanges )
1308
+ if ( hasChanges ) {
1309
+ const response = await confirm ( 'You may have unsaved changes. Are you sure you want to proceed?' , 'Yes' , 'Cancel' )
1310
+ if ( ! response ) return false
1311
+ }
1312
+ await win . confirmClose ( )
1313
+ } )
1314
+
1306
1315
function createFile ( args ) {
1307
1316
const {
1308
1317
source,
You can’t perform that action at this time.
0 commit comments