From 873ef7dd23e396fcd1520449dfa4acc52130e93a Mon Sep 17 00:00:00 2001 From: ValentinRapp Date: Sat, 6 Jun 2026 14:56:06 +0200 Subject: [PATCH] auto-updating --- electrobun.config.ts | 6 +- src/bun/index.ts | 14 ++++ src/bun/updater.ts | 15 ++++ src/mainview/App.tsx | 106 +++++++++++++++++---------- src/mainview/components/Updating.tsx | 35 +++++++++ src/shared/types.ts | 6 ++ 6 files changed, 142 insertions(+), 40 deletions(-) create mode 100644 src/bun/updater.ts create mode 100644 src/mainview/components/Updating.tsx diff --git a/electrobun.config.ts b/electrobun.config.ts index 202a390..c511edb 100644 --- a/electrobun.config.ts +++ b/electrobun.config.ts @@ -4,7 +4,7 @@ export default { app: { name: "yafw", identifier: "yafw.electrobun.dev", - version: "0.0.1", + version: "0.7", }, build: { // Vite builds to dist/, Electrobun copies from there into the bundle @@ -26,4 +26,8 @@ export default { icon: "src/mainview/assets/logo.ico", }, }, + release: { + baseUrl: "https://github.com/ValentinRapp/yafw" + // baseUrl: "http://localhost:8000" + }, } satisfies ElectrobunConfig; diff --git a/src/bun/index.ts b/src/bun/index.ts index 73efe00..7639e75 100644 --- a/src/bun/index.ts +++ b/src/bun/index.ts @@ -2,6 +2,7 @@ import { BrowserWindow, BrowserView, Updater, Utils } from "electrobun/bun"; import { type AppRPCType } from "../shared/types"; import { basename, dirname, extname, join } from "path"; import { homedir } from "os"; +import { update } from "./updater"; const DEV_SERVER_PORT = 5173; const DEV_SERVER_URL = `http://localhost:${DEV_SERVER_PORT}`; @@ -255,6 +256,19 @@ const rpc = BrowserView.defineRPC({ return { supportedEncoders: [] }; } }, + + update: async () => { + console.log("[YAFW] update check called"); + try { + const check = await Updater.checkForUpdate(); + const updating = !!check.updateAvailable; + updating && update(); // Don't await, run in background + return { updating }; + } catch (err) { + console.error("[YAFW] update RPC handler failed:", err); + return { updating: false }; + } + } }, messages: {}, }, diff --git a/src/bun/updater.ts b/src/bun/updater.ts new file mode 100644 index 0000000..7b31c1c --- /dev/null +++ b/src/bun/updater.ts @@ -0,0 +1,15 @@ +import * as Electrobun from "electrobun"; + +export const update = async () => { + console.log("[YAFW Backend] Starting update download..."); + try { + // await Bun.sleep(3000); // Simulate delay for testing + await Electrobun.Updater.downloadUpdate(); + if (Electrobun.Updater.updateInfo()?.updateReady) { + console.log("[YAFW Backend] Update ready. Applying update..."); + await Electrobun.Updater.applyUpdate(); + } + } catch (err) { + console.error("[YAFW Backend] Background update execution failed:", err); + } +}; \ No newline at end of file diff --git a/src/mainview/App.tsx b/src/mainview/App.tsx index bad58d3..73620ba 100644 --- a/src/mainview/App.tsx +++ b/src/mainview/App.tsx @@ -1,10 +1,13 @@ -import { useLayoutEffect, useRef, useState } from "react"; +import { useEffect, useLayoutEffect, useRef, useState } from "react"; import { useVideoEditor } from "./hooks/useVideoEditor"; import { Header } from "./components/Header"; import { DownloadPage } from "./components/DownloadPage"; import { LandingPage } from "./components/LandingPage"; import { EditorPage } from "./components/EditorPage"; import { VideoEditorProvider } from "./context/VideoEditorContext"; +import { useElectrobun } from "./hooks/useElectrobun"; +import { Updating } from "./components/Updating"; +import { isMac } from "./env"; const App = () => { const editorState = useVideoEditor(); @@ -16,10 +19,28 @@ const App = () => { handleNativeBrowse, handleChangeVideo, } = editorState; + const { electroview, isStandalone } = useElectrobun(); + const [isUpdating, setIsUpdating] = useState(false); const cardRef = useRef(null); const [cardHeight, setCardHeight] = useState(undefined); + const handleUpdate = async () => { + try { + const { updating } = await electroview.rpc.request.update({}); + setIsUpdating(updating); + } catch (err) { + console.error("[YAFW] Failed to check for updates:", err); + } + } + + useEffect(() => { + // Updates on MacOS are meant to be handled by homebrew + if (isStandalone && electroview && !isMac) { + handleUpdate(); + } + }, [isStandalone, electroview]); + useLayoutEffect(() => { const element = cardRef.current; if (element) { @@ -36,46 +57,53 @@ const App = () => {
- {/* Navbar / Header */} -
+ {!isUpdating ? + <> + {/* Navbar / Header */} +
- {/* Main Content Area */} - {currentPage === "download" || !videoSrc ? ( -
-
-
- {currentPage === "download" ? ( - setCurrentPage("editor")} /> - ) : ( - setCurrentPage("download")} - /> - )} + {/* Main Content Area */} + {currentPage === "download" || !videoSrc ? ( +
+
+
+ {currentPage === "download" ? ( + setCurrentPage("editor")} /> + ) : ( + setCurrentPage("download")} + /> + )} +
+
-
-
- ) : ( - - - - )} + ) : ( + + + + )} + + : + + }
); }; diff --git a/src/mainview/components/Updating.tsx b/src/mainview/components/Updating.tsx new file mode 100644 index 0000000..9dbc0e6 --- /dev/null +++ b/src/mainview/components/Updating.tsx @@ -0,0 +1,35 @@ +import logoUrl from "../assets/logo.png"; + +export const Updating = () => { + return ( +
+
+ {/* Spinner + Logo Wrapper */} +
+ {/* Outer glowing pulsing ring */} +
+ {/* Spinning gradient border */} +
+
+ + {/* Center logo */} + YAFW Logo +
+ + {/* Typography */} +
+

+ Updating YAFW +

+

+ Please wait while we install the latest enhancements. This should only take a moment. +

+
+
+
+ ); +}; \ No newline at end of file diff --git a/src/shared/types.ts b/src/shared/types.ts index 9c8a27c..f1cdc4b 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -44,6 +44,12 @@ export type AppRPCType = { supportedEncoders: string[]; }; }; + update: { + params: {}; + response: { + updating: boolean; + }; + }; }; messages: {}; }>;