From 282d0c66302b49d67c62bac30199aec9789c1754 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sun, 2 Aug 2026 21:40:30 +0100 Subject: [PATCH] Add isElectrobunBridgeReady function and update error handling in AppUpdateContext - Introduced isElectrobunBridgeReady function to check if the Electrobun bridge is initialized and ready for RPC requests. - Updated error message in AppUpdateContext to provide clearer guidance when app updates fail, enhancing user experience. - Modified ElectronContext to utilize the new isElectrobunBridgeReady function for improved bridge readiness checks. - Adjusted RPC handling in the desktop module to ensure non-blocking app update progress reporting. --- src/components/Dashboard/context/AppUpdateContext.jsx | 4 +++- src/components/Dashboard/context/ElectronContext.jsx | 3 ++- src/desktop/rpc.js | 6 +++++- src/electrobun-bridge.js | 4 ++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/Dashboard/context/AppUpdateContext.jsx b/src/components/Dashboard/context/AppUpdateContext.jsx index dbcea60..f513fe0 100644 --- a/src/components/Dashboard/context/AppUpdateContext.jsx +++ b/src/components/Dashboard/context/AppUpdateContext.jsx @@ -255,7 +255,9 @@ export const AppUpdateProvider = ({ children }) => { const result = await startAppUpdate(update) if (!result) { - throw new Error('App updates are only available in the desktop app.') + throw new Error( + 'Failed to start the app update. Please restart the app and try again.' + ) } } catch (error) { setUpdateProgress({ diff --git a/src/components/Dashboard/context/ElectronContext.jsx b/src/components/Dashboard/context/ElectronContext.jsx index b448dc4..a051590 100644 --- a/src/components/Dashboard/context/ElectronContext.jsx +++ b/src/components/Dashboard/context/ElectronContext.jsx @@ -2,6 +2,7 @@ import { createContext, useCallback, useEffect, useRef, useState } from 'react' import PropTypes from 'prop-types' import { useNavigate } from 'react-router-dom' import desktopBridge, { + isElectrobunBridgeReady, isElectrobunDesktop } from '../../../electrobun-bridge.js' @@ -55,7 +56,7 @@ const ElectronProvider = ({ children }) => { const [isMaximized, setIsMaximized] = useState(false) const [isFullScreen, setIsFullScreen] = useState(false) const [electronAvailable] = useState(isElectron()) - const useElectrobun = isElectrobunDesktop() + const useElectrobun = isElectrobunBridgeReady() || isElectrobunDesktop() const navigate = useNavigate() const lastNavigationAtRef = useRef(0) diff --git a/src/desktop/rpc.js b/src/desktop/rpc.js index da21b7f..271a90d 100644 --- a/src/desktop/rpc.js +++ b/src/desktop/rpc.js @@ -59,7 +59,11 @@ export function createAppRpc() { }) } - await startAppUpdate(mainWindow, update, sendProgress) + // Updates can take several minutes; return immediately and report + // progress via appUpdateProgress messages instead of blocking RPC. + void startAppUpdate(mainWindow, update, sendProgress).catch((error) => { + console.error('App update failed:', error) + }) return { ok: true } }, resizeSpotlightWindow: async ({ height }) => ({ diff --git a/src/electrobun-bridge.js b/src/electrobun-bridge.js index 0309270..835afa4 100644 --- a/src/electrobun-bridge.js +++ b/src/electrobun-bridge.js @@ -12,6 +12,10 @@ export function isElectrobunDesktop() { ) } +export function isElectrobunBridgeReady() { + return initialized && Boolean(rpc?.request) +} + function dispatchMessage(channel, data) { const channelListeners = listeners.get(channel) if (!channelListeners?.size) {