-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.ts
More file actions
57 lines (50 loc) · 1.76 KB
/
update.ts
File metadata and controls
57 lines (50 loc) · 1.76 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
// Copyright © 2025-2026 OpenVCS Contributors
// SPDX-License-Identifier: GPL-3.0-or-later
import { TAURI } from '../lib/tauri';
import { openModal, closeModal } from '../ui/modals';
import { notify } from '../lib/notify';
interface UpdateStatus {
available: boolean;
version: string | null;
current_version: string | null;
body: string | null;
date: string | null;
}
export function wireUpdate() {
const modal = document.getElementById('update-modal') as HTMLElement | null;
if (!modal || (modal as any).__wired) return;
(modal as any).__wired = true;
const installBtn = modal.querySelector('#update-install') as HTMLButtonElement | null;
installBtn?.addEventListener('click', async () => {
try {
if (!TAURI.has) return;
notify('Downloading update…');
await TAURI.invoke('updater_install_now');
notify('Update installed. Restart to apply.');
closeModal('update-modal');
} catch {
notify('Update failed');
}
});
}
export async function showUpdateDialog(_data: any) {
try {
if (!TAURI.has) return;
const status = await TAURI.invoke<UpdateStatus>('get_update_status');
if (!status.available) {
notify('Already up to date');
return;
}
openModal('update-modal');
const modal = document.getElementById('update-modal') as HTMLElement | null;
if (!modal) return;
const verEl = modal.querySelector('#update-version');
const notesEl = modal.querySelector('#update-notes');
const v = status.version || '';
const body = String(status.body || '').trim();
if (verEl) verEl.textContent = v ? `Version ${v}` : 'Update available';
if (notesEl) (notesEl as HTMLElement).textContent = body || '(No changelog provided)';
} catch {
notify('Update check failed');
}
}