Add check for updates functionality in Electron context and menu
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good
- Implemented `onCheckForUpdatesRequest` in `ElectronContext` to handle update requests from the renderer. - Updated `AppUpdateProvider` to utilize the new check for updates functionality. - Added "Check For Updates..." option in the desktop menu to trigger the update check. - Enhanced event handling in the main window to support the new update check action, improving user experience for application updates.
This commit is contained in:
parent
3534a797fc
commit
e46e12f15d
@ -130,7 +130,8 @@ export const AppUpdateProvider = ({ children }) => {
|
||||
setAppSettings,
|
||||
getAppEngine,
|
||||
startAppUpdate,
|
||||
onAppUpdateProgress
|
||||
onAppUpdateProgress,
|
||||
onCheckForUpdatesRequest
|
||||
} = useContext(ElectronContext)
|
||||
const [checking, setChecking] = useState(false)
|
||||
const [noUpdateOpen, setNoUpdateOpen] = useState(false)
|
||||
@ -300,6 +301,14 @@ export const AppUpdateProvider = ({ children }) => {
|
||||
})
|
||||
}, [isElectron, onAppUpdateProgress])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isElectron || !onCheckForUpdatesRequest) return undefined
|
||||
|
||||
return onCheckForUpdatesRequest(() => {
|
||||
void checkForUpdates()
|
||||
})
|
||||
}, [isElectron, onCheckForUpdatesRequest, checkForUpdates])
|
||||
|
||||
const dismissUpdatePrompt = () => {
|
||||
if (availableUpdate) {
|
||||
saveDismissedUpdate(availableUpdate)
|
||||
|
||||
@ -321,6 +321,31 @@ const ElectronProvider = ({ children }) => {
|
||||
[electronAvailable, useElectrobun]
|
||||
)
|
||||
|
||||
const onCheckForUpdatesRequest = useCallback(
|
||||
(handler) => {
|
||||
if (!electronAvailable || typeof handler !== 'function') {
|
||||
return () => {}
|
||||
}
|
||||
|
||||
if (useElectrobun) {
|
||||
return desktopBridge.onMessage('checkForUpdates', handler)
|
||||
}
|
||||
|
||||
if (!ipcRenderer) return () => {}
|
||||
|
||||
const checkHandler = () => {
|
||||
handler()
|
||||
}
|
||||
|
||||
ipcRenderer.on('check-for-updates', checkHandler)
|
||||
|
||||
return () => {
|
||||
ipcRenderer.removeListener('check-for-updates', checkHandler)
|
||||
}
|
||||
},
|
||||
[electronAvailable, useElectrobun]
|
||||
)
|
||||
|
||||
const getToken = async () => {
|
||||
const session = await getAuthSession()
|
||||
return session?.token || null
|
||||
@ -395,6 +420,7 @@ const ElectronProvider = ({ children }) => {
|
||||
setAppSettings,
|
||||
startAppUpdate,
|
||||
onAppUpdateProgress,
|
||||
onCheckForUpdatesRequest,
|
||||
getToken,
|
||||
setToken,
|
||||
resizeSpotlightWindow,
|
||||
|
||||
@ -13,6 +13,11 @@ function buildMacAppMenu() {
|
||||
action: `${SIDEBAR_MENU_ACTION_PREFIX}/dashboard/management/about`,
|
||||
},
|
||||
{ type: "separator" },
|
||||
{
|
||||
label: "Check For Updates...",
|
||||
action: "check-for-updates",
|
||||
},
|
||||
{ type: "separator" },
|
||||
{ role: "hide" },
|
||||
{ role: "hideOthers" },
|
||||
{ role: "showAll" },
|
||||
@ -143,6 +148,7 @@ export function setSidebarViewMenu(sections) {
|
||||
export function setupApplicationMenuEvents({
|
||||
onNavigate,
|
||||
onToggleDevTools,
|
||||
onCheckForUpdates,
|
||||
}) {
|
||||
navigateHandler = onNavigate;
|
||||
|
||||
@ -155,6 +161,11 @@ export function setupApplicationMenuEvents({
|
||||
return;
|
||||
}
|
||||
|
||||
if (action === "check-for-updates") {
|
||||
onCheckForUpdates?.();
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.startsWith(SIDEBAR_MENU_ACTION_PREFIX)) {
|
||||
const path = action.slice(SIDEBAR_MENU_ACTION_PREFIX.length);
|
||||
navigateHandler?.(path || "/");
|
||||
|
||||
@ -266,6 +266,9 @@ export async function createMainWindow(rpc) {
|
||||
onNavigate: sendNavigateToRenderer,
|
||||
onToggleDevTools: () => {
|
||||
mainWindow?.webview?.toggleDevTools?.()
|
||||
},
|
||||
onCheckForUpdates: () => {
|
||||
sendToRenderer('checkForUpdates')
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user