forked from TTLApp/time-to-leave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreferences.js
45 lines (39 loc) · 1.54 KB
/
preferences.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const { ipcRenderer } = require('electron');
const { getUserPreferences } = require('../js/UserPreferences.js');
// Global values for preferences page
let usersStyles = getUserPreferences();
let preferences = {};
$(() => {
var inputs = document.getElementsByTagName('input');
$('input[type="checkbox"]').change(function() {
preferences[this.name] = this.checked;
ipcRenderer.send('PREFERENCE_SAVE_DATA_NEEDED', preferences);
});
$('input[type="time"]').change(function() {
preferences[this.name] = this.value;
ipcRenderer.send('PREFERENCE_SAVE_DATA_NEEDED', preferences);
});
$('#notification').change(function() {
preferences['notification'] = this.value;
ipcRenderer.send('PREFERENCE_SAVE_DATA_NEEDED', preferences);
});
for(var i = 0 ; i < inputs.length; i++) {
let input = inputs[i];
if (inputs[i].type == 'checkbox') {
if (input.name in usersStyles) {
input.checked = usersStyles[input.name];
}
preferences[input.name] = input.checked;
} else if (inputs[i].type == 'time') {
if (input.name in usersStyles) {
input.value = usersStyles[input.name];
}
preferences[input.name] = input.value;
}
}
let notification = 'notification';
if (notification in usersStyles) {
$('#' + notification).val(usersStyles[notification]);
}
preferences[notification] = $('#' + notification).children('option:selected').val();
});