Move to using deckyState

This commit is contained in:
TrainDoctor
2022-08-24 13:47:21 -07:00
parent de1c89af21
commit d0fd2ac674
2 changed files with 11 additions and 6 deletions

View File

@@ -66,6 +66,7 @@ export class DeckyState {
}
interface DeckyStateContext extends PublicDeckyState {
setIsLoaderUpdating(hasUpdate: boolean): void;
setActivePlugin(name: string): void;
closeActivePlugin(): void;
}
@@ -91,11 +92,14 @@ export const DeckyStateContextProvider: FC<Props> = ({ children, deckyState }) =
return () => deckyState.eventBus.removeEventListener('update', onUpdate);
}, []);
const setIsLoaderUpdating = (hasUpdate: boolean) => deckyState.setIsLoaderUpdating(hasUpdate);
const setActivePlugin = (name: string) => deckyState.setActivePlugin(name);
const closeActivePlugin = () => deckyState.closeActivePlugin();
return (
<DeckyStateContext.Provider value={{ ...publicDeckyState, setActivePlugin, closeActivePlugin }}>
<DeckyStateContext.Provider
value={{ ...publicDeckyState, setIsLoaderUpdating, setActivePlugin, closeActivePlugin }}
>
{children}
</DeckyStateContext.Provider>
);

View File

@@ -3,13 +3,14 @@ import { useEffect, useState } from 'react';
import { FaArrowDown } from 'react-icons/fa';
import { VerInfo, callUpdaterMethod, finishUpdate } from '../../../../updater';
import { useDeckyState } from '../../../DeckyState';
export default function UpdaterSettings() {
const [versionInfo, setVersionInfo] = useState<VerInfo | null>(null);
const [checkingForUpdates, setCheckingForUpdates] = useState<boolean>(false);
const { isLoaderUpdating, setIsLoaderUpdating } = useDeckyState();
const [updateProgress, setUpdateProgress] = useState<number>(-1);
const [reloading, setReloading] = useState<boolean>(false);
const [checkingForUpdates, setCheckingForUpdates] = useState<boolean>(false);
const [loaderUpdating, setLoaderUpdating] = useState<boolean>(false);
useEffect(() => {
(async () => {
@@ -38,7 +39,7 @@ export default function UpdaterSettings() {
>
{updateProgress == -1 ? (
<DialogButton
disabled={!versionInfo?.updatable || checkingForUpdates || loaderUpdating}
disabled={!versionInfo?.updatable || checkingForUpdates || isLoaderUpdating}
onClick={
!versionInfo?.remote || versionInfo?.remote?.tag_name == versionInfo?.current
? async () => {
@@ -51,12 +52,12 @@ export default function UpdaterSettings() {
window.DeckyUpdater = {
updateProgress: (i) => {
setUpdateProgress(i);
setLoaderUpdating(true);
setIsLoaderUpdating(true);
},
finish: async () => {
setUpdateProgress(0);
setReloading(true);
setLoaderUpdating(false);
setIsLoaderUpdating(false);
await finishUpdate();
},
};