checking for update

This commit is contained in:
SPRINX0\prochazka
2024-09-09 15:44:34 +02:00
parent 3303fd1ee9
commit 703a4bdb57
7 changed files with 125 additions and 1 deletions

View File

@@ -21,6 +21,7 @@
import AppStartInfo from './widgets/AppStartInfo.svelte';
import SettingsListener from './utility/SettingsListener.svelte';
import { handleAuthOnStartup } from './clientAuth';
import { initializeAppUpdates } from './utility/appUpdate';
export let isAdminPage = false;
@@ -49,6 +50,7 @@
subscribeConnectionPingers();
subscribePermissionCompiler();
installNewVolatileConnectionListener();
initializeAppUpdates();
}
loadedApi = loadedApiValue;

View File

@@ -3,6 +3,7 @@ import {
currentTheme,
emptyConnectionGroupNames,
extensions,
getAppUpdaterActive,
getExtensions,
getVisibleToolbar,
visibleToolbar,
@@ -585,6 +586,17 @@ registerCommand({
onClick: () => disconnectServerConnection(getCurrentConfig()?.singleConnection?._id),
});
registerCommand({
id: 'file.checkForUpdates',
category: 'App',
name: 'Check for updates',
// testEnabled: () => true,
testEnabled: () => getAppUpdaterActive(),
onClick: () => getElectron().send('check-for-updates'),
});
export function registerFileCommands({
idPrefix,
category,

View File

@@ -123,6 +123,8 @@ export const commandsCustomized = derived([commands, commandsSettings], ([$comma
...$commandsSettings[k],
}))
);
export const appUpdateStatus = writable('');
export const appUpdaterActive = writable(false);
export const draggingTab = writable(null);
export const draggingTabTarget = writable(null);
@@ -303,3 +305,9 @@ currentArchive.subscribe(value => {
currentArchiveValue = value;
});
export const getCurrentArchive = () => currentArchiveValue;
let appUpdaterActiveValue = false;
appUpdaterActive.subscribe(value => {
appUpdaterActiveValue = value;
});
export const getAppUpdaterActive = () => appUpdaterActiveValue;

View File

@@ -0,0 +1,48 @@
import { appUpdaterActive, appUpdateStatus } from '../stores';
import getElectron from './getElectron';
import { showSnackbar } from './snackbar';
export function initializeAppUpdates() {
const electron = getElectron();
if (!electron) {
return;
}
electron.addEventListener('update-available', (e, version) => {
showSnackbar({
message: `Update available: ${version}`,
allowClose: true,
buttons: [
{
label: 'Download',
onClick: () => {
electron.send('downloadUpdate');
},
},
],
});
});
electron.addEventListener('app-update-status', (e, text) => {
appUpdateStatus.set(text);
});
electron.addEventListener('downloaded-new-version', (e, version) => {
showSnackbar({
message: `New version ${version} downloaded`,
allowClose: true,
buttons: [
{
label: 'Restart',
onClick: () => {
electron.send('applyUpdate');
},
},
],
});
});
electron.addEventListener('setAppUpdaterActive', (e, error) => {
appUpdaterActive.set(true);
});
}

View File

@@ -8,6 +8,7 @@
import {
activeTabId,
appUpdateStatus,
currentArchive,
currentDatabase,
currentThemeDefinition,
@@ -169,6 +170,12 @@
{item.text}
</div>
{/each}
{#if $appUpdateStatus}
<div class="item">
{$appUpdateStatus}
</div>
{/if}
</div>
</div>