-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabout.js
59 lines (53 loc) · 2.25 KB
/
about.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
document.addEventListener('DOMContentLoaded', (event) => {
const usageCollectionToggle = document.getElementById('usageCollectionToggle');
const { ipcRenderer } = require('electron');
// Get and display version
async function displayVersion() {
const version = await ipcRenderer.invoke('get-version');
const versionLink = document.querySelector('#version-number a');
versionLink.textContent = `Version ${version}`;
versionLink.href = 'https://github.com/hybes/pairkiller';
}
displayVersion();
// Load initial config
ipcRenderer.invoke('get-config').then(config => {
usageCollectionToggle.checked = config.anonymousUsage;
});
// Event Listeners
usageCollectionToggle.addEventListener('change', () => {
ipcRenderer.send('toggle-usage-collection', usageCollectionToggle.checked);
});
document.getElementById('checkForUpdatesButton').addEventListener('click', () => {
ipcRenderer.send('check-for-updates');
});
// Handle external links
document.querySelectorAll('.external-link').forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
ipcRenderer.send('open-link', e.target.closest('a').href);
});
});
ipcRenderer.on('update-status', (event, status, info) => {
let message = '';
switch (status) {
case 'available':
message = `Update to version ${info} is available and being downloaded.`;
break;
case 'downloaded':
const response = confirm(`Update to version ${info} has been downloaded. Would you like to install and restart now?`);
if (response) {
ipcRenderer.send('install-update');
}
return; // We don't want to show an alert after this since we already showed a confirmation dialog.
case 'not-available':
message = 'You have the latest version installed.';
break;
case 'error':
message = `Error checking for updates: ${info}`;
break;
}
if (message) {
alert(message); // Display the feedback message to the user
}
});
});