Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
move updater to js
Brendan Allanbd7eb52813c4
diff --git a/apps/desktop/package.json b/apps/desktop/package.jsonindex 25b45f1f6..462f85d3c 100644--- a/apps/desktop/package.json+++ b/apps/desktop/package.json@@ -36,6 +36,7 @@"@tauri-apps/plugin-process": "2.0.0-rc.0","@tauri-apps/plugin-shell": ">=2.0.0-rc.0","@tauri-apps/plugin-store": "2.0.0-rc.0",+ "@tauri-apps/plugin-updater": "2.0.0-rc.0","@types/react-tooltip": "^4.2.4","cva": "npm:class-variance-authority@^0.7.0","effect": "^3.7.2",diff --git a/apps/desktop/src-tauri/capabilities/default.json b/apps/desktop/src-tauri/capabilities/default.jsonindex bac3b6bb3..981681fb1 100644--- a/apps/desktop/src-tauri/capabilities/default.json+++ b/apps/desktop/src-tauri/capabilities/default.json@@ -20,9 +20,10 @@"core:webview:allow-create-webview-window","shell:default","fs:default",- "dialog:allow-save",+ "dialog:default","store:default","process:default",- "oauth:allow-start"+ "oauth:allow-start",+ "updater:default"]}diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rsindex 44fce599e..70edd3345 100644--- a/apps/desktop/src-tauri/src/lib.rs+++ b/apps/desktop/src-tauri/src/lib.rs@@ -10,7 +10,6 @@ mod playback;mod project_recordings;mod recording;mod tray;-mod updater;mod upload;use auth::AuthStore;@@ -30,6 +29,7 @@ use serde_json::json;use specta::Type;use std::fs::File;use std::io::{BufReader, Write};+use std::sync::atomic::AtomicBool;use std::{collections::HashMap, marker::PhantomData, path::PathBuf, process::Command, sync::Arc,time::Duration,@@ -1137,8 +1137,6 @@ async fn list_audio_devices() -> Result<Vec<String>, ()> {#[tauri::command(async)]#[specta::specta]fn open_main_window(app: AppHandle) {- tokio::spawn(updater::check_for_updates(app.clone()));-if let Some(window) = app.get_webview_window("main") {window.set_focus().ok();return;@@ -1244,7 +1242,6 @@ struct RecordingMetaChanged {#[tauri::command(async)]#[specta::specta]fn get_recording_meta(app: AppHandle, id: String) -> RecordingMeta {-RecordingMeta::load_for_project(&recording_path(&app, &id)).unwrap()}diff --git a/apps/desktop/src-tauri/src/updater.rs b/apps/desktop/src-tauri/src/updater.rsdeleted file mode 100644index 30129b7f3..000000000--- a/apps/desktop/src-tauri/src/updater.rs+++ /dev/null@@ -1,64 +0,0 @@--use tauri::AppHandle;-use tauri_plugin_dialog::DialogExt;-use tauri_plugin_updater::UpdaterExt;--#[tauri::command]-#[specta::specta]-pub async fn check_for_updates(app: AppHandle) -> Result<(), ()> {- let Some(update) = app- .updater()- .map_err(|_| {})?- .check()- .await- .map_err(|_| {})?- else {- return Ok(());- };-- let (tx, rx) = tokio::sync::oneshot::channel();-- app.dialog()- .message(format!(- "Version {} of Cap is available, would you like to install it?",- update.version- ))- .title("Update Cap")- .ok_button_label("Update")- .cancel_button_label("Ignore")- .show(move |install| {- tx.send(install).ok();- });-- if !rx.await.unwrap() {- return Ok(());- }-- update- .download_and_install(- |_, _| {},- || {- },- )- .await- .unwrap();-- let (tx, rx) = tokio::sync::oneshot::channel();- app.dialog()- .message(format!(- "Cap v{} has been installed, restart Cap to finish updating.",- update.version- ))- .title("Update Cap")- .ok_button_label("Restart Now")- .cancel_button_label("Restart Later")- .show(|restart| {- tx.send(restart).ok();- });-- if rx.await.unwrap() {- app.restart();- }-- Ok(())-}diff --git a/apps/desktop/src/routes/(main)/index.tsx b/apps/desktop/src/routes/(main)/index.tsxindex 8cccbb98c..8dd04d1a5 100644--- a/apps/desktop/src/routes/(main)/index.tsx+++ b/apps/desktop/src/routes/(main)/index.tsx@@ -11,7 +11,7 @@ import { Select as KSelect } from "@kobalte/core/select";import { SwitchTab, Button } from "@cap/ui-solid";import { createMutation } from "@tanstack/solid-query";import { createEventListener } from "@solid-primitives/event-listener";-import { cache, createAsync, redirect } from "@solidjs/router";+import { cache, createAsync, redirect, useNavigate } from "@solidjs/router";import { createCameraForLabel, createCameras } from "../../utils/media";import {@@ -83,6 +83,8 @@ export default function () {const audioDevicesData = createMemo(() => audioDevices.data ?? []);const camerasData = createMemo(() => cameras() ?? []);+ createUpdateCheck();+return (<div class="flex flex-col p-[1rem] gap-[0.75rem] text-[0.875rem] font-[400] bg-gray-50"><Show when={auth() && options.data}>@@ -370,3 +372,29 @@ export default function () {</div>);}++import * as dialog from "@tauri-apps/plugin-dialog";+import * as updater from "@tauri-apps/plugin-updater";++let hasChecked = false;+function createUpdateCheck() {+ const navigate = useNavigate();++ onMount(async () => {+ if (hasChecked) return;+ hasChecked = true;++ await new Promise((res) => setTimeout(res, 1000));++ const update = await updater.check();+ if (!update) return;++ const shouldUpdate = await dialog.confirm(+ `Version ${update.version} of Cap is available, would you like to install it?`,+ { title: "Update Cap", okLabel: "Update", cancelLabel: "Ignore" }+ );++ if (!shouldUpdate) return;+ navigate("/update");+ });+}diff --git a/apps/desktop/src/routes/(main)/update.tsx b/apps/desktop/src/routes/(main)/update.tsxnew file mode 100644index 000000000..62a0b10d2--- /dev/null+++ b/apps/desktop/src/routes/(main)/update.tsx@@ -0,0 +1,116 @@+import { useNavigate } from "@solidjs/router";+import { check } from "@tauri-apps/plugin-updater";+import {+ createResource,+ createSignal,+ Match,+ onMount,+ Show,+ Switch,+} from "solid-js";+import * as dialog from "@tauri-apps/plugin-dialog";+import { relaunch } from "@tauri-apps/plugin-process";+import { Button } from "@cap/ui-solid";++export default function () {+ const navigate = useNavigate();++ const [update] = createResource(async () => {+ const update = await check();+ if (!update) return;++ return update;+ });++ return (+ <div class="flex flex-col justify-center flex-1 items-center gap-[3rem] p-[1rem] text-[0.875rem] font-[400] h-full">+ <Show when={update()} fallback="No update available" keyed>+ {(update) => {+ type UpdateStatus =+ | { type: "downloading"; progress: number; contentLength?: number }+ | { type: "done" };++ const [updateStatus, updateStatusActions] =+ createResource<UpdateStatus>(+ () =>+ new Promise<UpdateStatus>((resolve) => {+ update+ .downloadAndInstall((e) => {+ if (e.event === "Started") {+ resolve({+ type: "downloading",+ progress: 0,+ contentLength: e.data.contentLength,+ });+ } else if (e.event === "Progress") {+ const status = updateStatus();+ if (+ !status ||+ status.type !== "downloading" ||+ status.contentLength === undefined+ )+ return;+ updateStatusActions.mutate({+ ...status,+ progress: e.data.chunkLength + status.progress,+ });+ }+ })+ .then(async () => {+ updateStatusActions.mutate({ type: "done" });+ })+ .catch(() => navigate("/"));+ })+ );++ return (+ <div>+ <Switch fallback={<IconCapLogo class="animate-spin size-4" />}>+ <Match when={updateStatus()?.type === "done"}>+ Update has been installed. Restart Cap to finish updating.+ <div class="flex flex-row gap-4">+ <Button variant="secondary" onClick={() => navigate("/")}>+ Restart Later+ </Button>+ <Button onClick={() => relaunch()}>Restart Now</Button>+ </div>+ </Match>+ <Match+ when={(() => {+ const s = updateStatus();+ if (+ s &&+ s.type === "downloading" &&+ s.contentLength !== undefined+ )+ return s;+ })()}+ >+ {(status) => (+ <>+ <h1>Installing Update</h1>++ <div class="w-full bg-gray-200 rounded-full h-2.5">+ <div+ class="bg-blue-300 h-2.5 rounded-full"+ style={{+ width: `${Math.min(+ ((status()?.progress ?? 0) /+ (status()?.contentLength ?? 0)) *+ 100,+ 100+ )}%`,+ }}+ />+ </div>+ </>+ )}+ </Match>+ </Switch>+ </div>+ );+ }}+ </Show>+ </div>+ );+}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex b1febdf6e..c858aa59e 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -113,6 +113,9 @@ importers:'@tauri-apps/plugin-store':specifier: 2.0.0-rc.0version: 2.0.0-rc.0+ '@tauri-apps/plugin-updater':+ specifier: 2.0.0-rc.0+ version: 2.0.0-rc.0'@types/react-tooltip':specifier: ^4.2.4@@ -4864,11 +4867,11 @@ packages:react-dom:optional: true- '@storybook/[email protected]':- resolution: {integrity: sha512-ngdtu1Dn9cq2GoK7RL0cTDxnRZ4altblAW7bX9U6WXHHAxP83mIDvbnm+7IDoYuSRwm9KgLf+k8YiarCZTBEHQ==}+ '@storybook/[email protected]':+ resolution: {integrity: sha512-gFeW+fuUN4s9rzGZAUZunU6n1+Ck7js29f6DRyUGSSwXxGwgwvqT8MdS5v1tqEdoKG+QwLNek1pTY6s6UugLdg==}peerDependencies:'@preact/preset-vite': '*'- storybook: ^8.3.0-beta.4+ storybook: ^8.4.0-alpha.0typescript: '>= 4.3.x'vite: ^4.0.0 || ^5.0.0vite-plugin-glimmerx: '*'@@ -4891,10 +4894,10 @@ packages:peerDependencies:storybook: ^8.2.9- '@storybook/[email protected]':- resolution: {integrity: sha512-VgldiH9nC/P97KEnXyDkS63GxXlfaz7BWdnkqJk+mmnLCnxqJMckQ8fOdjuKOdmOSQMF8r1NjVpRHnMJeCpg3A==}+ '@storybook/[email protected]':+ resolution: {integrity: sha512-BAhSUEBd+y314f2DEdSSPddpgzk9fTk2lXP205HGZESaP1bpBbMdIEqM6wC/BuX7Em/HZ8iZIhHqFKnX9XknIQ==}peerDependencies:- storybook: ^8.3.0-beta.4+ storybook: ^8.4.0-alpha.0'@storybook/[email protected]':resolution: {integrity: sha512-dHYFQH3mA+EtnCkHXzicbLgsvzYjcDJ1JWsogbItZogkPHgSJM/Wr71uMkcvw8v9mmCyP4NpXJuu6bPoVsOnzg==}@@ -5139,6 +5142,9 @@ packages:'@tauri-apps/[email protected]':resolution: {integrity: sha512-KqiEzq6EdRwxrl0/FwyNLwumDBM91xTchdu2a8vfkNub30GuP9z7RskP9ifVRI1gbxfa5TUDi0hKFk/SP7TANQ==}+ '@tauri-apps/[email protected]':+ resolution: {integrity: sha512-EKajf/sBpFif0cwXhTo3BmNvTZ2t2DDLRyhA8FFKugZNoOeqU97bHhPT5DIqMUPRE1tyDk9o7sXm8dKf7oz+EA==}+'@testing-library/[email protected]':resolution: {integrity: sha512-wdsYKy5zupPyLCW2Je5DLHSxSfbIp6h80WoHOQc+RPtmPGA52O9x5MJEkv92Sjonpq+poOAtUKhh1kBGAXBrNA==}engines: {node: '>=18'}@@ -16806,9 +16812,9 @@ snapshots:react: 18.2.0react-dom: 18.2.0([email protected])- '@storybook/[email protected]([email protected](@babel/[email protected](@babel/[email protected]))([email protected])([email protected]))([email protected])([email protected](@types/[email protected])([email protected]))':+ '@storybook/[email protected]([email protected](@babel/[email protected](@babel/[email protected]))([email protected])([email protected]))([email protected])([email protected](@types/[email protected])([email protected]))':dependencies:- '@storybook/csf-plugin': 8.3.0-beta.4([email protected](@babel/[email protected](@babel/[email protected]))([email protected])([email protected]))+ '@storybook/csf-plugin': 8.4.0-alpha.0([email protected](@babel/[email protected](@babel/[email protected]))([email protected])([email protected]))'@types/find-cache-dir': 3.2.1browser-assert: 1.2.1es-module-lexer: 1.5.4@@ -16867,7 +16873,7 @@ snapshots:storybook: 8.2.9(@babel/[email protected](@babel/[email protected]))([email protected])([email protected])unplugin: 1.12.1- '@storybook/[email protected]([email protected](@babel/[email protected](@babel/[email protected]))([email protected])([email protected]))':+ '@storybook/[email protected]([email protected](@babel/[email protected](@babel/[email protected]))([email protected])([email protected]))':dependencies:storybook: 8.2.9(@babel/[email protected](@babel/[email protected]))([email protected])([email protected])unplugin: 1.12.1@@ -17094,6 +17100,10 @@ snapshots:dependencies:'@tauri-apps/api': 2.0.0-rc.4+ '@tauri-apps/[email protected]':+ dependencies:+ '@tauri-apps/api': 2.0.0-rc.4+'@testing-library/[email protected]':dependencies:'@babel/code-frame': 7.24.7@@ -23936,7 +23946,7 @@ snapshots:[email protected]([email protected](@babel/[email protected](@babel/[email protected]))([email protected])([email protected]))([email protected])([email protected](@types/[email protected])([email protected])):dependencies:- '@storybook/builder-vite': 8.3.0-beta.4([email protected](@babel/[email protected](@babel/[email protected]))([email protected])([email protected]))([email protected])([email protected](@types/[email protected])([email protected]))+ '@storybook/builder-vite': 8.4.0-alpha.0([email protected](@babel/[email protected](@babel/[email protected]))([email protected])([email protected]))([email protected])([email protected](@types/[email protected])([email protected]))transitivePeerDependencies:- '@preact/preset-vite'- storybook