fix: change status page depending on desktop mode (#573)

* fix: change status page depending on desktop mode

* refactor: check desktop reachability periodically
This commit is contained in:
Cafe137
2022-11-07 14:02:22 +01:00
committed by GitHub
parent 693609810d
commit a4b8e7ca25
7 changed files with 77 additions and 14 deletions
+25 -1
View File
@@ -11,6 +11,7 @@ export interface LatestBeeReleaseHook {
}
export interface BeeDesktopHook {
reachable: boolean
error: Error | null
isLoading: boolean
beeDesktopVersion: string
@@ -22,11 +23,34 @@ export interface NewDesktopVersionHook {
}
export const useBeeDesktop = (isBeeDesktop = false, desktopUrl: string): BeeDesktopHook => {
const [reachable, setReachable] = useState(false)
const [desktopAutoUpdateEnabled, setDesktopAutoUpdateEnabled] = useState<boolean>(true)
const [beeDesktopVersion, setBeeDesktopVersion] = useState<string>('')
const [isLoading, setLoading] = useState<boolean>(true)
const [error, setError] = useState<Error | null>(null)
useEffect(() => {
if (!isBeeDesktop) {
return
}
function runReachabilityCheck() {
axios
.get(`${desktopUrl}/info`)
.then(() => {
setReachable(true)
})
.catch(() => {
setReachable(false)
})
}
runReachabilityCheck()
const interval = setInterval(runReachabilityCheck, 10_000)
return () => clearInterval(interval)
}, [desktopUrl, isBeeDesktop])
useEffect(() => {
if (!isBeeDesktop) {
setLoading(false)
@@ -48,7 +72,7 @@ export const useBeeDesktop = (isBeeDesktop = false, desktopUrl: string): BeeDesk
}
}, [desktopUrl, isBeeDesktop])
return { error, isLoading, beeDesktopVersion, desktopAutoUpdateEnabled }
return { error, isLoading, beeDesktopVersion, desktopAutoUpdateEnabled, reachable }
}
async function checkNewVersion(desktopUrl: string): Promise<string> {