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,
|
setAppSettings,
|
||||||
getAppEngine,
|
getAppEngine,
|
||||||
startAppUpdate,
|
startAppUpdate,
|
||||||
onAppUpdateProgress
|
onAppUpdateProgress,
|
||||||
|
onCheckForUpdatesRequest
|
||||||
} = useContext(ElectronContext)
|
} = useContext(ElectronContext)
|
||||||
const [checking, setChecking] = useState(false)
|
const [checking, setChecking] = useState(false)
|
||||||
const [noUpdateOpen, setNoUpdateOpen] = useState(false)
|
const [noUpdateOpen, setNoUpdateOpen] = useState(false)
|
||||||
@ -300,6 +301,14 @@ export const AppUpdateProvider = ({ children }) => {
|
|||||||
})
|
})
|
||||||
}, [isElectron, onAppUpdateProgress])
|
}, [isElectron, onAppUpdateProgress])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isElectron || !onCheckForUpdatesRequest) return undefined
|
||||||
|
|
||||||
|
return onCheckForUpdatesRequest(() => {
|
||||||
|
void checkForUpdates()
|
||||||
|
})
|
||||||
|
}, [isElectron, onCheckForUpdatesRequest, checkForUpdates])
|
||||||
|
|
||||||
const dismissUpdatePrompt = () => {
|
const dismissUpdatePrompt = () => {
|
||||||
if (availableUpdate) {
|
if (availableUpdate) {
|
||||||
saveDismissedUpdate(availableUpdate)
|
saveDismissedUpdate(availableUpdate)
|
||||||
|
|||||||
@ -321,6 +321,31 @@ const ElectronProvider = ({ children }) => {
|
|||||||
[electronAvailable, useElectrobun]
|
[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 getToken = async () => {
|
||||||
const session = await getAuthSession()
|
const session = await getAuthSession()
|
||||||
return session?.token || null
|
return session?.token || null
|
||||||
@ -395,6 +420,7 @@ const ElectronProvider = ({ children }) => {
|
|||||||
setAppSettings,
|
setAppSettings,
|
||||||
startAppUpdate,
|
startAppUpdate,
|
||||||
onAppUpdateProgress,
|
onAppUpdateProgress,
|
||||||
|
onCheckForUpdatesRequest,
|
||||||
getToken,
|
getToken,
|
||||||
setToken,
|
setToken,
|
||||||
resizeSpotlightWindow,
|
resizeSpotlightWindow,
|
||||||
|
|||||||
@ -13,6 +13,11 @@ function buildMacAppMenu() {
|
|||||||
action: `${SIDEBAR_MENU_ACTION_PREFIX}/dashboard/management/about`,
|
action: `${SIDEBAR_MENU_ACTION_PREFIX}/dashboard/management/about`,
|
||||||
},
|
},
|
||||||
{ type: "separator" },
|
{ type: "separator" },
|
||||||
|
{
|
||||||
|
label: "Check For Updates...",
|
||||||
|
action: "check-for-updates",
|
||||||
|
},
|
||||||
|
{ type: "separator" },
|
||||||
{ role: "hide" },
|
{ role: "hide" },
|
||||||
{ role: "hideOthers" },
|
{ role: "hideOthers" },
|
||||||
{ role: "showAll" },
|
{ role: "showAll" },
|
||||||
@ -143,6 +148,7 @@ export function setSidebarViewMenu(sections) {
|
|||||||
export function setupApplicationMenuEvents({
|
export function setupApplicationMenuEvents({
|
||||||
onNavigate,
|
onNavigate,
|
||||||
onToggleDevTools,
|
onToggleDevTools,
|
||||||
|
onCheckForUpdates,
|
||||||
}) {
|
}) {
|
||||||
navigateHandler = onNavigate;
|
navigateHandler = onNavigate;
|
||||||
|
|
||||||
@ -155,6 +161,11 @@ export function setupApplicationMenuEvents({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (action === "check-for-updates") {
|
||||||
|
onCheckForUpdates?.();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (action.startsWith(SIDEBAR_MENU_ACTION_PREFIX)) {
|
if (action.startsWith(SIDEBAR_MENU_ACTION_PREFIX)) {
|
||||||
const path = action.slice(SIDEBAR_MENU_ACTION_PREFIX.length);
|
const path = action.slice(SIDEBAR_MENU_ACTION_PREFIX.length);
|
||||||
navigateHandler?.(path || "/");
|
navigateHandler?.(path || "/");
|
||||||
|
|||||||
@ -266,6 +266,9 @@ export async function createMainWindow(rpc) {
|
|||||||
onNavigate: sendNavigateToRenderer,
|
onNavigate: sendNavigateToRenderer,
|
||||||
onToggleDevTools: () => {
|
onToggleDevTools: () => {
|
||||||
mainWindow?.webview?.toggleDevTools?.()
|
mainWindow?.webview?.toggleDevTools?.()
|
||||||
|
},
|
||||||
|
onCheckForUpdates: () => {
|
||||||
|
sendToRenderer('checkForUpdates')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user