File tree Expand file tree Collapse file tree 4 files changed +33
-4
lines changed Expand file tree Collapse file tree 4 files changed +33
-4
lines changed Original file line number Diff line number Diff line change 66 getAllFiles
77} = require ( './helpers.js' )
88
9- module . exports = function registerIPCHandlers ( win , ipcMain ) {
9+ module . exports = function registerIPCHandlers ( win , ipcMain , app ) {
1010 ipcMain . handle ( 'open-folder' , async ( event ) => {
1111 console . log ( 'ipcMain' , 'open-folder' )
1212 const folder = await openFolderDialog ( win )
@@ -107,4 +107,15 @@ module.exports = function registerIPCHandlers(win, ipcMain) {
107107
108108 win . setMinimumSize ( minWidth , minHeight )
109109 } )
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+ } )
110121}
Original file line number Diff line number Diff line change @@ -23,11 +23,17 @@ function createWindow () {
2323 // and load the index.html of the app.
2424 win . loadFile ( 'ui/arduino/index.html' )
2525
26- registerIPCHandlers ( win , ipcMain )
26+ registerIPCHandlers ( win , ipcMain , app )
2727 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+ // })
2835}
2936
3037
3138// TODO: Loading splash screen
32-
3339app . whenReady ( ) . then ( createWindow )
Original file line number Diff line number Diff line change @@ -151,9 +151,12 @@ const Disk = {
151151const Window = {
152152 setWindowSize : ( minWidth , minHeight ) => {
153153 ipcRenderer . invoke ( 'set-window-size' , minWidth , minHeight )
154- }
154+ } ,
155+ beforeClose : ( callback ) => ipcRenderer . on ( 'check-before-close' , callback ) ,
156+ confirmClose : ( ) => ipcRenderer . invoke ( 'confirm-close' )
155157}
156158
159+
157160contextBridge . exposeInMainWorld ( 'BridgeSerial' , Serial )
158161contextBridge . exposeInMainWorld ( 'BridgeDisk' , Disk )
159162contextBridge . exposeInMainWorld ( 'BridgeWindow' , Window )
Original file line number Diff line number Diff line change @@ -1303,6 +1303,15 @@ async function store(state, emitter) {
13031303 emitter . emit ( 'render' )
13041304 } )
13051305
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+
13061315 function createFile ( args ) {
13071316 const {
13081317 source,
You can’t perform that action at this time.
0 commit comments