-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
248 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { type ProgressInfo } from "electron-updater"; | ||
import { LucideLoader } from "lucide-react"; | ||
import { useEffect, useState } from "react"; | ||
|
||
export default function UpdateBar() { | ||
const [checkingUpdate, setCheckingUpdate] = useState(true); | ||
const [isLatest, setLatest] = useState(false); | ||
const [isComplete, setComplete] = useState(false); | ||
const [progress, setProgress] = useState<ProgressInfo>(); | ||
|
||
// Update is not avaliable | ||
useEffect(() => { | ||
const handler = () => { | ||
setCheckingUpdate(false); | ||
setLatest(true); | ||
}; | ||
|
||
window.outerbaseIpc.on("update-not-available", handler); | ||
return () => { | ||
window.outerbaseIpc.off("update-not-available", handler); | ||
}; | ||
}, []); | ||
|
||
// Progress bar | ||
useEffect(() => { | ||
const handler = (_: unknown, info: ProgressInfo) => { | ||
setCheckingUpdate(false); | ||
setProgress(info); | ||
}; | ||
|
||
window.outerbaseIpc.on("update-download-progress", handler); | ||
|
||
return () => { | ||
window.outerbaseIpc.off("update-download-progress", handler); | ||
}; | ||
}, []); | ||
|
||
// Completed event | ||
useEffect(() => { | ||
const handler = () => { | ||
setComplete(true); | ||
setCheckingUpdate(false); | ||
}; | ||
|
||
window.outerbaseIpc.on("update-downloaded", handler); | ||
|
||
return () => { | ||
window.outerbaseIpc.off("update-downloaded", handler); | ||
}; | ||
}, []); | ||
|
||
if (checkingUpdate) { | ||
return ( | ||
<div className="flex items-center justify-end pr-2"> | ||
<LucideLoader | ||
className="mr-2 inline-block h-4 w-4 animate-spin" | ||
size={16} | ||
/> | ||
Checking for update | ||
</div> | ||
); | ||
} | ||
|
||
if (isComplete) { | ||
return ( | ||
<div className="flex items-center justify-end pr-2"> | ||
Update downloaded. Restart to apply changes. | ||
</div> | ||
); | ||
} | ||
|
||
if (isLatest) { | ||
return ( | ||
<div className="flex items-center justify-end pr-2">Latest version</div> | ||
); | ||
} | ||
|
||
if (progress) { | ||
return ( | ||
<div className="flex items-center justify-end pr-2"> | ||
<LucideLoader | ||
className="mr-2 inline-block h-4 w-4 animate-spin" | ||
size={16} | ||
/> | ||
Downloading update {progress.percent.toFixed(2)}% | ||
</div> | ||
); | ||
} | ||
|
||
return <div className="flex items-center justify-end pr-2"></div>; | ||
} |
Oops, something went wrong.