From 8b5d9e1e2094ca3e6bce38431fb68ebc194f2f40 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 8 Oct 2025 11:49:30 -0700 Subject: [PATCH 1/2] Improve the auto-updater. --- app/src/components/updater.tsx | 129 ++++++++++++++++++ app/src/index.tsx | 5 +- app/src/layout/web.tsx | 28 ++-- app/src/room/gl/{shaders => }/background.frag | 0 app/src/room/gl/background.ts | 4 +- app/src/room/gl/{shaders => }/background.vert | 0 app/src/room/gl/{shaders => }/border.frag | 0 app/src/room/gl/border.ts | 4 +- app/src/room/gl/{shaders => }/border.vert | 0 app/src/room/gl/{shaders => }/broadcast.frag | 0 app/src/room/gl/broadcast.ts | 4 +- app/src/room/gl/{shaders => }/broadcast.vert | 0 app/src/room/gl/{shaders => }/outline.frag | 0 app/src/room/gl/outline.ts | 4 +- app/src/room/gl/{shaders => }/outline.vert | 0 app/src/tauri/constants.ts | 14 ++ app/src/tauri/index.ts | 17 +-- app/src/tauri/update.ts | 129 ++++++++++++++---- native/Cargo.toml | 4 +- native/src/lib.rs | 12 ++ native/src/update.rs | 61 +++++++++ native/tauri.conf.json | 1 - 22 files changed, 355 insertions(+), 61 deletions(-) create mode 100644 app/src/components/updater.tsx rename app/src/room/gl/{shaders => }/background.frag (100%) rename app/src/room/gl/{shaders => }/background.vert (100%) rename app/src/room/gl/{shaders => }/border.frag (100%) rename app/src/room/gl/{shaders => }/border.vert (100%) rename app/src/room/gl/{shaders => }/broadcast.frag (100%) rename app/src/room/gl/{shaders => }/broadcast.vert (100%) rename app/src/room/gl/{shaders => }/outline.frag (100%) rename app/src/room/gl/{shaders => }/outline.vert (100%) create mode 100644 app/src/tauri/constants.ts create mode 100644 native/src/update.rs diff --git a/app/src/components/updater.tsx b/app/src/components/updater.tsx new file mode 100644 index 00000000..9321ede4 --- /dev/null +++ b/app/src/components/updater.tsx @@ -0,0 +1,129 @@ +import { createSignal, onMount, Show } from "solid-js"; +import * as Tauri from "../tauri/constants"; +import Tooltip from "./tooltip"; + +const module = Tauri.DESKTOP ? await import("../tauri/update") : undefined; + +type Status = + | { + type: "downloading"; + version: string; + size?: number; + progress: number; + } + | { + type: "downloaded"; + version: string; + size: number; + } + | { + type: "installing"; + version: string; + } + | { + type: "error"; + error: string; + }; + +export default function UpdaterIcon() { + const [status, setStatus] = createSignal(); + + onMount(async () => { + // Import the update module + const updater = (await module)?.update; + if (!updater) return; + + // Subscribe to status changes + const dispose = updater.status.subscribe((newStatus) => { + setStatus(newStatus); + }); + + return () => dispose(); + }); + + const handleClick = async () => { + const s = status(); + if (!s || s.type !== "downloaded") return; + + const module = await import("../tauri/update"); + module.update.install(); + }; + + const tooltipContent = () => { + const s = status(); + if (!s) return ""; + + if (s.type === "error") return `Error: ${s.error}`; + if (s.type === "downloading") return `Downloading ${s.version}...`; + if (s.type === "downloaded") return `Update ${s.version} ready`; + if (s.type === "installing") return `Installing ${s.version}...`; + return ""; + }; + + const progressPercent = () => { + const s = status(); + if (!s || s.type !== "downloading" || !s.size) return 0; + return (s.progress / s.size) * 100; + }; + + return ( + + + + + + ); +} diff --git a/app/src/index.tsx b/app/src/index.tsx index 154b2c7d..d26e3f19 100644 --- a/app/src/index.tsx +++ b/app/src/index.tsx @@ -3,8 +3,9 @@ import "@kixelated/hang/support/element"; import * as Tauri from "./tauri"; -if (Tauri.ENABLED && Tauri.DESKTOP) { - import("./tauri/update").then((module) => module.run()); +// Import update module early if on desktop to ensure it runs even if UI breaks +if (Tauri.DESKTOP) { + import("./tauri/update"); } import solid from "@kixelated/signals/solid"; diff --git a/app/src/layout/web.tsx b/app/src/layout/web.tsx index 05485cd0..e323d178 100644 --- a/app/src/layout/web.tsx +++ b/app/src/layout/web.tsx @@ -1,6 +1,7 @@ -import { type JSX, Show } from "solid-js"; +import { type JSX, Match, Switch } from "solid-js"; import Divider from "../components/divider"; import Tooltip from "../components/tooltip"; +import UpdaterIcon from "../components/updater"; import * as Tauri from "../tauri"; import { Logo } from "./logo"; @@ -11,16 +12,21 @@ export default function Web(props: { children: JSX.Element; link?: string }) {