fix(update): ensure update check is only performed in Tauri environment

This commit is contained in:
4gray committed 2025-03-01 14:22:54 +01:00
1 parent 01bbf396a9
commit 8222d82b01
1 file changed
+34 -32
+34 -32
View File
@@ -121,41 +121,43 @@ export class AppComponent {
}
async checkForUpdates() {
const update = await check();
if (update?.available) {
console.log(
`found update ${update.version} from ${update.date} with notes ${update.body}`
);
let downloaded = 0;
let contentLength = 0;
if (isTauri()) {
const update = await check();
if (update?.available) {
console.log(
`found update ${update.version} from ${update.date} with notes ${update.body}`
);
let downloaded = 0;
let contentLength = 0;
const wantsUpdate = await ask(
`New version ${update.version} is available. Do you want to update now?`
);
const wantsUpdate = await ask(
`New version ${update.version} is available. Do you want to update now?`
);
if (wantsUpdate) {
await update.downloadAndInstall((event) => {
switch (event.event) {
case 'Started':
contentLength = event.data.contentLength;
console.log(
`started downloading ${event.data.contentLength} bytes`
);
break;
case 'Progress':
downloaded += event.data.chunkLength;
console.log(
`downloaded ${downloaded} from ${contentLength}`
);
break;
case 'Finished':
console.log('download finished');
break;
}
});
if (wantsUpdate) {
await update.downloadAndInstall((event) => {
switch (event.event) {
case 'Started':
contentLength = event.data.contentLength;
console.log(
`started downloading ${event.data.contentLength} bytes`
);
break;
case 'Progress':
downloaded += event.data.chunkLength;
console.log(
`downloaded ${downloaded} from ${contentLength}`
);
break;
case 'Finished':
console.log('download finished');
break;
}
});
console.log('update installed');
await relaunch();
console.log('update installed');
await relaunch();
}
}
}
}