-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathsettings.ts
129 lines (99 loc) · 3.41 KB
/
settings.ts
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import * as Toastify from 'toastify-js';
(window as any).toastify = Toastify;
const fs = require('fs');
const path = require('path');
const Store = require('electron-store');
const config = new Store({
projectName: 'SwitchDock',
});
import * as Sentry from '@sentry/browser';
Sentry.init({
dsn: 'https://[email protected]/1540999',
});
export class Settings {
constructor() {
if (process.platform == 'darwin') this.macOSCleanUp();
window.onload = () => {
this.updateUI();
}
this.getAppVersion();
}
getSavedFromStore() {
const settings = config.get('config');
if (settings == null) {
const initial = {
autoHide: true,
maximize: true,
placement: 'right',
};
config.set('config', initial)
return initial;
} else {
return settings;
}
}
getShowIntro() {
const status = config.get('showIntro');
return status == null ? true : status;
}
getDisableAltGr() {
const status = config.get('disableAltGr');
return status == null ? false : status;
}
updateUI() {
const data = this.getSavedFromStore();
document.clear();
this.setCheckedValue('auto_hide', data.autoHide);
this.setCheckedValue('maximize', data.maximize);
this.setCheckedValue('intro', this.getShowIntro());
this.setSelectedValue('placement', data.placement);
this.setCheckedValue('disableAltGr', this.getDisableAltGr());
}
getCheckedValue(id: string): boolean {
return (document.getElementById(id) as HTMLInputElement).checked;
}
setCheckedValue(id: string, value: boolean) {
(document.getElementById(id) as HTMLInputElement).checked = value;
}
setSelectedValue(id: string, value: string) {
(document.getElementById(id) as HTMLInputElement).value = value;
}
getValue(id: string) {
return (document.getElementById(id) as HTMLInputElement).value;
}
saveSettings() {
const autoHide = this.getCheckedValue('auto_hide');
const maximize = this.getCheckedValue('maximize');
const intro = this.getCheckedValue('intro');
const placement = this.getValue('placement');
const disableAltGr = this.getCheckedValue('disableAltGr');
config.set('config', {
autoHide: autoHide,
maximize: maximize,
placement: placement
});
config.set('showIntro', intro);
config.set('disableAltGr', disableAltGr);
(window as any).toastify({
text: "🦄 Saved!",
duration: 3000,
gravity: "bottom",
position: 'left',
className: 'toast-left',
backgroundColor: "linear-gradient(to right, #ff5f6d, #ffc371)",
}).showToast();
}
getAppVersion() {
fs.readFile(path.join(__dirname, '../package.json'), (err, data) => {
if (err) throw new Error(err);
const parse = JSON.parse(data);
document.getElementById('ver').innerText = `v${parse.version}`
});
}
macOSCleanUp() {
let $macHides = document.getElementsByClassName('mac-hide');
for (let i = 0; i < $macHides.length; i++) {
($macHides.item(i) as HTMLElement).style.opacity = '0';
}
}
}