Skip to content

Commit

Permalink
Added confirm close dialog preference
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan McDougall committed Dec 27, 2018
1 parent 9dcbb41 commit 7c65710
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/js/mainWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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'))
});
}
});
Expand Down
20 changes: 18 additions & 2 deletions src/js/prefWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand All @@ -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();
Expand All @@ -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.
Expand All @@ -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;
Expand All @@ -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;
}
});
});

Expand All @@ -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);
});
9 changes: 7 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const {
Tray,
dialog
} = electron;
app.showExitPrompt = true;

//Defining the window variables
let mainWindow;
Expand Down Expand Up @@ -93,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',
Expand All @@ -106,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 {
Expand Down
7 changes: 7 additions & 0 deletions src/windows/prefWindow.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ <h1>Preferences</h1>
<span class="slider"></span>
</label>
</div>
<div class="preference">
<p class="preference-header">Show confirmation dialog on exit</p>
<label class="preference-switch">
<input type="checkbox" id="exit-prompt-preference">
<span class="slider"></span>
</label>
</div>
<div class="preference-group">
<p class="preference-header">Notifications</p>
<ul class="sub-preferences">
Expand Down

0 comments on commit 7c65710

Please sign in to comment.