diff --git a/src/js/mainWindow.js b/src/js/mainWindow.js index bf6f99de..87ba95cd 100644 --- a/src/js/mainWindow.js +++ b/src/js/mainWindow.js @@ -42,6 +42,12 @@ function getSetPrefs() { } else { localStorage.setItem('toggle-sound-preference', true); } + + if (localStorage.getItem('exit-prompt-preference')) { + soundPref = localStorage.getItem('exit-prompt-preference'); + } else { + localStorage.setItem('exit-prompt-preference', true); + } } getSetPrefs(); @@ -53,7 +59,8 @@ ipcRenderer.on('sendPreferencesBool', function(e, bool) { persistTheme: JSON.parse(localStorage.getItem('persist-theme-preference')), toggleNotifications: JSON.parse(localStorage.getItem('toggle-notifications-preference')), toggleSound: JSON.parse(localStorage.getItem('toggle-sound-preference')), - toggleTray: JSON.parse(localStorage.getItem('toggle-tray-preference')) + toggleTray: JSON.parse(localStorage.getItem('toggle-tray-preference')), + showExitPrompt: JSON.parse(localStorage.getItem('exit-prompt-preference')) }); } }); diff --git a/src/js/prefWindow.js b/src/js/prefWindow.js index df16e5c9..e73c135a 100644 --- a/src/js/prefWindow.js +++ b/src/js/prefWindow.js @@ -7,11 +7,12 @@ const { } = remote; const fs = require('fs'); -var persistTheme, toggleNotifications, toggleMessagePreview, toggleSound; +var persistTheme, toggleNotifications, toggleMessagePreview, toggleSound, showExitPrompt; persistTheme = localStorage.getItem('persist-theme-preference'); toggleNotifications = localStorage.getItem('toggle-notifications-preference'); toggleSound = localStorage.getItem('toggle-sound-preference'); toggleTray = localStorage.getItem('toggle-tray-preference'); +showExitPrompt = localStorage.getItem('exit-prompt-preference'); function loadSettings() { if (document.querySelector('#persist-theme-preference')) { @@ -30,6 +31,10 @@ function loadSettings() { let checked = toggleTray == "true" ? true : false; document.querySelector('#toggle-tray-preference').checked = checked; } + if (document.querySelector('#exit-prompt-preference')) { + let checked = showExitPrompt == "true" ? true : false; + document.querySelector('#exit-prompt-preference').checked = checked; + } } loadSettings(); @@ -51,7 +56,8 @@ document.querySelector('#export').addEventListener('click', function(e) { persistTheme: persistTheme, toggleNotifications: toggleNotifications, toggleSound: toggleSound, - toggleTray: toggleTray + toggleTray: toggleTray, + showExitPrompt: showExitPrompt }); // fileName is a string that contains the path and filename created in the save file dialog. @@ -77,6 +83,7 @@ document.querySelector('#import').addEventListener('click', function(e) { JSONtoggleNotifications = JSONsettings.toggleNotifications; JSONtoggleSound = JSONsettings.toggleSound; JSONtoggleTray = JSONsettings.toggleTray; + JSONshowExitPrompt = JSONsettings.showExitPrompt; if (document.querySelector('#persist-theme-preference')) { let checked = JSONpersistTheme == "true" ? true : false; @@ -94,6 +101,10 @@ document.querySelector('#import').addEventListener('click', function(e) { let checked = JSONtoggleTray == "true" ? true : false; document.querySelector('#toggle-tray-preference').checked = checked; } + if (document.querySelector('#exit-prompt-preference')) { + let checked = JSONshowExitPrompt == "true" ? true : false; + document.querySelector('#exit-prompt-preference').checked = checked; + } }); }); @@ -118,6 +129,11 @@ document.querySelector('#save').addEventListener('click', function(e) { } else { localStorage.setItem('toggle-tray-preference', false); } + if (document.querySelector('#exit-prompt-preference').checked) { + localStorage.setItem('exit-prompt-preference', true); + } else { + localStorage.setItem('exit-prompt-preference', false); + } ipcRenderer.send('settingsChanged', true); }); \ No newline at end of file diff --git a/src/main.js b/src/main.js index 19d99fef..32caafcf 100644 --- a/src/main.js +++ b/src/main.js @@ -49,8 +49,15 @@ if (!singleInstanceLock) { })); const mainMenu = Menu.buildFromTemplate(mainMenuTemp); //Applies the main menu template Menu.setApplicationMenu(mainMenu); //Sets the main menu + + mainWindow.on('close', function (e) { // Confirm dialog when user closes window + if (app.showExitPrompt) { + e.preventDefault(); + confirmExit(); + } + }); mainWindow.on('closed', function() { //Quits app when main window is closed - mainWindow = null + mainWindow = null; app.quit(); }); @@ -85,7 +92,7 @@ if (!singleInstanceLock) { }); function init() { - var theme, persistTheme, toggleNotifications, toggleSound, toggleTray; + var theme, persistTheme, toggleNotifications, toggleSound, toggleTray, showExitPrompt; ipcMain.on('preferences', function(e, pref) { theme = pref.theme || { name: 'default-theme', @@ -98,6 +105,12 @@ if (!singleInstanceLock) { toggleTray = true; } + if (typeof pref.showExitPrompt !== "undefined") { + app.showExitPrompt = pref.showExitPrompt; + } else { + app.showExitPrompt = true; + } + if (typeof pref.persistTheme !== "undefined") { persistTheme = pref.persistTheme; } else { @@ -156,17 +169,7 @@ if (!singleInstanceLock) { }, { label: 'Exit', click() { - dialog.showMessageBox({ - type: 'question', - buttons: ["OK", "Cancel"], - title: "Exit", - message: "Are you sure you want to exit?" - }, function(res) { - if (res == 0) { - app.quit(); - return; - } - }); + app.quit(); } }]); if (process.platform !== "darwin") { @@ -206,6 +209,21 @@ if (!singleInstanceLock) { }); } +function confirmExit() { + dialog.showMessageBox({ + type: 'question', + buttons: ["OK", "Cancel"], + title: "Exit", + message: "Are you sure you want to exit?" + }, function(res) { + if (res == 0) { + app.showExitPrompt = false; + app.quit(); + return; + } + }); +} + function createAboutWindow() { if (typeof aboutWindow == 'object') { aboutWindow.show(); diff --git a/src/windows/prefWindow.html b/src/windows/prefWindow.html index 979531fd..fe13859b 100644 --- a/src/windows/prefWindow.html +++ b/src/windows/prefWindow.html @@ -24,6 +24,13 @@
Show confirmation dialog on exit
+ +Notifications