-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig-api.js
More file actions
72 lines (67 loc) · 2.42 KB
/
config-api.js
File metadata and controls
72 lines (67 loc) · 2.42 KB
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
new Vue({
el: '#config-api',
data: {
defaultTimeout: 10000,
selectedScreenshot: 'everyScreenshot',
isCloseBrowser: true,
fullScreenshot: false,
iteration: 1,
},
computed: {
isFullScreenshotEnabled() {
return this.selectedScreenshot !== 'neverScreenshot';
}
},
watch: {
defaultTimeout(newValue) {
this.defaultTimeout = this.validateValue(newValue);
},
iteration(newValue) {
this.iteration = this.validateValue(newValue);
}
},
methods: {
validateValue(value) {
return Math.max(1, Number(value));
},
saveConfig() {
const configapi = {
defaultTimeout: this.defaultTimeout,
selectedScreenshot: this.selectedScreenshot,
isCloseBrowser: this.isCloseBrowser,
fullScreenshot: this.fullScreenshot,
iteration: this.iteration,
};
localStorage.setItem('configapi', JSON.stringify(configapi));
alert('Configurações salvas com sucesso!');
},
loadConfig() {
const getConfig = localStorage.getItem('configapi');
if (getConfig) {
try {
const config = JSON.parse(getConfig);
this.defaultTimeout = config.defaultTimeout ?? this.defaultTimeout;
this.selectedScreenshot = config.selectedScreenshot ?? this.selectedScreenshot;
this.isCloseBrowser = config.isCloseBrowser ?? this.isCloseBrowser;
this.fullScreenshot = config.fullScreenshot ?? this.fullScreenshot;
this.iteration = config.iteration ?? this.iteration;
} catch (e) {
console.error('Erro ao carregar configuração:', e);
}
}
}
},
mounted() {
const theme = localStorage.getItem('theme') || 'dark';
document.documentElement.setAttribute('data-theme', theme);
window.electronAPI.onThemeChange((newTheme) => {
document.documentElement.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
});
this.loadConfig();
const btn = document.getElementById('saveSettings');
if (btn) {
btn.addEventListener('click', this.saveConfig);
}
}
});