forked from op7418/CodePilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseUpdate.ts
More file actions
38 lines (33 loc) · 949 Bytes
/
useUpdate.ts
File metadata and controls
38 lines (33 loc) · 949 Bytes
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
"use client";
import { createContext, useContext } from "react";
export interface UpdateInfo {
updateAvailable: boolean;
latestVersion: string;
currentVersion: string;
releaseName: string;
releaseNotes: string;
releaseUrl: string;
publishedAt: string;
downloadProgress: number | null;
readyToInstall: boolean;
isNativeUpdate: boolean;
lastError: string | null;
}
export interface UpdateContextValue {
updateInfo: UpdateInfo | null;
checking: boolean;
checkForUpdates: () => Promise<void>;
downloadUpdate: () => void;
dismissUpdate: () => void;
showDialog: boolean;
setShowDialog: (v: boolean) => void;
quitAndInstall: () => void;
}
export const UpdateContext = createContext<UpdateContextValue | null>(null);
export function useUpdate(): UpdateContextValue {
const ctx = useContext(UpdateContext);
if (!ctx) {
throw new Error("useUpdate must be used within an UpdateProvider");
}
return ctx;
}