Add isElectrobunBridgeReady function and update error handling in AppUpdateContext
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good

- 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.
This commit is contained in:
Tom Butcher 2026-08-02 21:40:30 +01:00
parent a196d0f26d
commit 282d0c6630
4 changed files with 14 additions and 3 deletions

View File

@ -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({

View File

@ -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)

View File

@ -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 }) => ({

View File

@ -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) {