feat(updater): implement auto-install countdown and cancellation for updates (#151)
This commit is contained in:
@@ -35,12 +35,15 @@ interface UpdateState {
|
||||
progress: ProgressInfo | null;
|
||||
error: string | null;
|
||||
isInitialized: boolean;
|
||||
/** Seconds remaining before auto-install, or null if inactive. */
|
||||
autoInstallCountdown: number | null;
|
||||
|
||||
// Actions
|
||||
init: () => Promise<void>;
|
||||
checkForUpdates: () => Promise<void>;
|
||||
downloadUpdate: () => Promise<void>;
|
||||
installUpdate: () => void;
|
||||
cancelAutoInstall: () => Promise<void>;
|
||||
setChannel: (channel: 'stable' | 'beta' | 'dev') => Promise<void>;
|
||||
setAutoDownload: (enable: boolean) => Promise<void>;
|
||||
clearError: () => void;
|
||||
@@ -53,6 +56,7 @@ export const useUpdateStore = create<UpdateState>((set, get) => ({
|
||||
progress: null,
|
||||
error: null,
|
||||
isInitialized: false,
|
||||
autoInstallCountdown: null,
|
||||
|
||||
init: async () => {
|
||||
if (get().isInitialized) return;
|
||||
@@ -101,6 +105,11 @@ export const useUpdateStore = create<UpdateState>((set, get) => ({
|
||||
});
|
||||
});
|
||||
|
||||
window.electron.ipcRenderer.on('update:auto-install-countdown', (data) => {
|
||||
const { seconds, cancelled } = data as { seconds: number; cancelled?: boolean };
|
||||
set({ autoInstallCountdown: cancelled ? null : seconds });
|
||||
});
|
||||
|
||||
set({ isInitialized: true });
|
||||
|
||||
// Apply persisted settings from the settings store
|
||||
@@ -180,6 +189,14 @@ export const useUpdateStore = create<UpdateState>((set, get) => ({
|
||||
window.electron.ipcRenderer.invoke('update:install');
|
||||
},
|
||||
|
||||
cancelAutoInstall: async () => {
|
||||
try {
|
||||
await window.electron.ipcRenderer.invoke('update:cancelAutoInstall');
|
||||
} catch (error) {
|
||||
console.error('Failed to cancel auto-install:', error);
|
||||
}
|
||||
},
|
||||
|
||||
setChannel: async (channel) => {
|
||||
try {
|
||||
await window.electron.ipcRenderer.invoke('update:setChannel', channel);
|
||||
|
||||
Reference in New Issue
Block a user