Skip to content

Commit 2a71bfc

Browse files
committed
feat: toast when upgrade
Signed-off-by: Innei <i@innei.in>
1 parent 124b0bd commit 2a71bfc

File tree

4 files changed

+61
-18
lines changed

4 files changed

+61
-18
lines changed

src/renderer/src/App.tsx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Outlet } from "react-router-dom"
55
import { env } from "../../env.js"
66
import { useAppIsReady } from "./atoms/app"
77
import { useUISettingKey } from "./atoms/settings/ui"
8+
import { applyAfterReadyCallbacks } from "./initialize/queue.js"
89
import { appLog } from "./lib/log"
910
import { cn, getOS } from "./lib/utils"
1011
import { Titlebar } from "./modules/app/Titlebar.js"
@@ -43,22 +44,20 @@ function App() {
4344

4445
const windowsElectron = window.electron && getOS() === "Windows"
4546
return (
46-
<>
47-
<RootProviders>
48-
{window.electron && (
49-
<div
50-
className={cn(
51-
"drag-region absolute inset-x-0 top-0 h-12 shrink-0",
52-
windowsElectron && "pointer-events-none z-[9999]",
53-
)}
54-
aria-hidden
55-
>
56-
{windowsElectron && <Titlebar />}
57-
</div>
58-
)}
59-
<AppLayer />
60-
</RootProviders>
61-
</>
47+
<RootProviders>
48+
{window.electron && (
49+
<div
50+
className={cn(
51+
"drag-region absolute inset-x-0 top-0 h-12 shrink-0",
52+
windowsElectron && "pointer-events-none z-[9999]",
53+
)}
54+
aria-hidden
55+
>
56+
{windowsElectron && <Titlebar />}
57+
</div>
58+
)}
59+
<AppLayer />
60+
</RootProviders>
6261
)
6362
}
6463

@@ -71,6 +70,8 @@ const AppLayer = () => {
7170
time: doneTime,
7271
})
7372
appLog("App is ready", `${doneTime}ms`)
73+
74+
applyAfterReadyCallbacks()
7475
}, [appIsReady])
7576

7677
return appIsReady ? <Outlet /> : <AppSkeleton />

src/renderer/src/atoms/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getStorageNS } from "@renderer/lib/ns"
33
import { atom } from "jotai"
44
import { atomWithStorage } from "jotai/utils"
55

6-
export const [, , useAppIsReady, , , setAppIsReady] = createAtomHooks(
6+
export const [, , useAppIsReady, , appIsReady, setAppIsReady] = createAtomHooks(
77
atom(false),
88
)
99

src/renderer/src/initialize/index.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import duration from "dayjs/plugin/duration"
1313
import localizedFormat from "dayjs/plugin/localizedFormat"
1414
import relativeTime from "dayjs/plugin/relativeTime"
1515
import { enableMapSet } from "immer"
16+
import { createElement } from "react"
1617
import { toast } from "sonner"
1718

1819
import { subscribeNetworkStatus } from "../atoms/network"
@@ -27,6 +28,7 @@ import {
2728
setHydrated,
2829
} from "./hydrate"
2930
import { initPostHog } from "./posthog"
31+
import { pushAfterReadyCallback } from "./queue"
3032
import { initSentry } from "./sentry"
3133

3234
const cleanup = subscribeShouldUseIndexedDB((value) => {
@@ -64,7 +66,31 @@ export const initializeApp = async () => {
6466

6567
if (lastVersion && lastVersion !== APP_VERSION) {
6668
appLog(`Upgrade from ${lastVersion} to ${APP_VERSION}`)
67-
// TODO
69+
70+
pushAfterReadyCallback(() => {
71+
setTimeout(() => {
72+
toast.success(
73+
// `App is upgraded to ${APP_VERSION}, enjoy the new features! 🎉`,
74+
createElement("div", {
75+
children: [
76+
"App is upgraded to ",
77+
createElement(
78+
"a",
79+
{
80+
href: `${repository.url}/releases/tag/${APP_VERSION}`,
81+
target: "_blank",
82+
className: "underline",
83+
},
84+
createElement("strong", {
85+
children: APP_VERSION,
86+
}),
87+
),
88+
", enjoy the new features! 🎉",
89+
],
90+
}),
91+
)
92+
}, 1000)
93+
})
6894
}
6995
localStorage.setItem(appVersionKey, APP_VERSION)
7096

src/renderer/src/initialize/queue.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { appIsReady } from "@renderer/atoms/app"
2+
3+
const afterReadyCallbackQueue = [] as Array<() => void>
4+
5+
export const pushAfterReadyCallback = (callback: () => void) => {
6+
if (appIsReady()) {
7+
callback()
8+
} else {
9+
afterReadyCallbackQueue.push(callback)
10+
}
11+
}
12+
13+
export const applyAfterReadyCallbacks = () => {
14+
afterReadyCallbackQueue.forEach((callback) => callback())
15+
afterReadyCallbackQueue.length = 0
16+
}

0 commit comments

Comments
 (0)