Skip to content

Commit cbb74d0

Browse files
committed
Add update check and simulation to debug page
1 parent 5769271 commit cbb74d0

File tree

1 file changed

+78
-2
lines changed

1 file changed

+78
-2
lines changed

apps/desktop/src/routes/debug.tsx

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,54 @@
1+
import { useNavigate } from "@solidjs/router";
12
import { createQuery } from "@tanstack/solid-query";
2-
import { createUniqueId, For } from "solid-js";
3+
import { getVersion } from "@tauri-apps/api/app";
4+
import * as dialog from "@tauri-apps/plugin-dialog";
5+
import { check } from "@tauri-apps/plugin-updater";
6+
import { createSignal, createUniqueId, For, onMount } from "solid-js";
37
import { commands } from "~/utils/tauri";
48

59
export default function Debug() {
10+
const navigate = useNavigate();
11+
const [version, setVersion] = createSignal<string>("");
12+
const [updateStatus, setUpdateStatus] = createSignal<string>("");
13+
const [isChecking, setIsChecking] = createSignal(false);
14+
15+
onMount(async () => {
16+
const v = await getVersion();
17+
setVersion(v);
18+
});
19+
20+
const checkForUpdates = async () => {
21+
setIsChecking(true);
22+
setUpdateStatus("Checking...");
23+
try {
24+
const update = await check();
25+
if (update) {
26+
setUpdateStatus(`Update available: v${update.version}`);
27+
} else {
28+
setUpdateStatus("No update available");
29+
}
30+
} catch (e) {
31+
setUpdateStatus(`Error: ${e}`);
32+
}
33+
setIsChecking(false);
34+
};
35+
36+
const simulateUpdatePopup = async () => {
37+
const fakeVersion = "99.0.0";
38+
setUpdateStatus(`Simulating update to v${fakeVersion}...`);
39+
40+
const shouldUpdate = await dialog.confirm(
41+
`Version ${fakeVersion} of Cap is available, would you like to install it?`,
42+
{ title: "Update Cap", okLabel: "Update", cancelLabel: "Ignore" },
43+
);
44+
45+
if (shouldUpdate) {
46+
navigate("/update");
47+
} else {
48+
setUpdateStatus("User declined update");
49+
}
50+
};
51+
652
const fails = createQuery(() => ({
753
queryKey: ["fails"],
854
queryFn: () => commands.listFails(),
@@ -30,7 +76,37 @@ export default function Debug() {
3076
</button>
3177
</div>
3278

33-
<h2 class="text-2xl font-bold">Fail Points</h2>
79+
<h2 class="text-2xl font-bold mt-4">Updates</h2>
80+
<div class="p-2 mb-4">
81+
<p class="mb-2 text-sm text-[--text-secondary]">
82+
Current version: v{version()}
83+
</p>
84+
<div class="flex flex-row gap-2 items-center">
85+
<button
86+
class="bg-blue-500 hover:bg-blue-600 text-white font-medium py-2 px-4 rounded disabled:opacity-50"
87+
onClick={checkForUpdates}
88+
disabled={isChecking()}
89+
>
90+
Check for Updates
91+
</button>
92+
<button
93+
class="bg-green-500 hover:bg-green-600 text-white font-medium py-2 px-4 rounded"
94+
onClick={() => navigate("/update")}
95+
>
96+
Go to Update Page
97+
</button>
98+
<button
99+
class="bg-purple-500 hover:bg-purple-600 text-white font-medium py-2 px-4 rounded disabled:opacity-50"
100+
onClick={simulateUpdatePopup}
101+
disabled={isChecking()}
102+
>
103+
Simulate Update Flow
104+
</button>
105+
</div>
106+
{updateStatus() && <p class="mt-2 text-sm">{updateStatus()}</p>}
107+
</div>
108+
109+
<h2 class="text-2xl font-bold mt-4">Fail Points</h2>
34110
<ul class="p-2">
35111
<For each={orderedFails()}>
36112
{(fail) => {

0 commit comments

Comments
 (0)