From 8c8cf180fad2ad6951ad7ce6b74e6c163fa01d18 Mon Sep 17 00:00:00 2001 From: AAGaming Date: Thu, 14 Jul 2022 22:51:55 -0400 Subject: Updater for decky-loader (#117) * Add an updater in settings for decky-loader * add chmod * remove junk comments --- frontend/src/components/settings/index.tsx | 4 +- .../components/settings/pages/GeneralSettings.tsx | 30 -------- .../src/components/settings/pages/PluginList.tsx | 34 --------- .../components/settings/pages/general/Updater.tsx | 86 ++++++++++++++++++++++ .../components/settings/pages/general/index.tsx | 34 +++++++++ .../settings/pages/plugin_list/index.tsx | 34 +++++++++ frontend/src/index.tsx | 2 + frontend/src/updater.ts | 30 ++++++++ 8 files changed, 188 insertions(+), 66 deletions(-) delete mode 100644 frontend/src/components/settings/pages/GeneralSettings.tsx delete mode 100644 frontend/src/components/settings/pages/PluginList.tsx create mode 100644 frontend/src/components/settings/pages/general/Updater.tsx create mode 100644 frontend/src/components/settings/pages/general/index.tsx create mode 100644 frontend/src/components/settings/pages/plugin_list/index.tsx create mode 100644 frontend/src/updater.ts (limited to 'frontend/src') diff --git a/frontend/src/components/settings/index.tsx b/frontend/src/components/settings/index.tsx index f9c84c7b..eb3a8bbd 100644 --- a/frontend/src/components/settings/index.tsx +++ b/frontend/src/components/settings/index.tsx @@ -1,7 +1,7 @@ import { SidebarNavigation } from 'decky-frontend-lib'; -import GeneralSettings from './pages/GeneralSettings'; -import PluginList from './pages/PluginList'; +import GeneralSettings from './pages/general'; +import PluginList from './pages/plugin_list'; export default function SettingsPage() { return ( diff --git a/frontend/src/components/settings/pages/GeneralSettings.tsx b/frontend/src/components/settings/pages/GeneralSettings.tsx deleted file mode 100644 index 1cc8076d..00000000 --- a/frontend/src/components/settings/pages/GeneralSettings.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import { DialogButton, Field, TextField } from 'decky-frontend-lib'; -import { useState } from 'react'; -import { FaShapes } from 'react-icons/fa'; - -import { installFromURL } from '../../store/Store'; - -export default function GeneralSettings() { - const [pluginURL, setPluginURL] = useState(''); - // const [checked, setChecked] = useState(false); // store these in some kind of State instead - return ( -
- {/* } - > - setChecked(e)} - /> - */} - setPluginURL(e?.target.value)} />} - icon={} - > - installFromURL(pluginURL)}>Install - -
- ); -} diff --git a/frontend/src/components/settings/pages/PluginList.tsx b/frontend/src/components/settings/pages/PluginList.tsx deleted file mode 100644 index bf01f85a..00000000 --- a/frontend/src/components/settings/pages/PluginList.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import { DialogButton, staticClasses } from 'decky-frontend-lib'; -import { FaTrash } from 'react-icons/fa'; - -import { useDeckyState } from '../../DeckyState'; - -export default function PluginList() { - const { plugins } = useDeckyState(); - - if (plugins.length === 0) { - return ( -
-

No plugins installed

-
- ); - } - - return ( - - ); -} diff --git a/frontend/src/components/settings/pages/general/Updater.tsx b/frontend/src/components/settings/pages/general/Updater.tsx new file mode 100644 index 00000000..264acca2 --- /dev/null +++ b/frontend/src/components/settings/pages/general/Updater.tsx @@ -0,0 +1,86 @@ +import { DialogButton, Field, ProgressBarWithInfo, Spinner, sleep } from 'decky-frontend-lib'; +import { useEffect, useState } from 'react'; +import { FaArrowDown } from 'react-icons/fa'; + +import { callUpdaterMethod, finishUpdate } from '../../../../updater'; + +interface VerInfo { + current: string; + remote: { + assets: { + browser_download_url: string; + created_at: string; + }[]; + name: string; + body: string; + prerelease: boolean; + published_at: string; + tag_name: string; + } | null; + updatable: boolean; +} + +export default function UpdaterSettings() { + const [versionInfo, setVersionInfo] = useState(null); + const [updateProgress, setUpdateProgress] = useState(-1); + const [reloading, setReloading] = useState(false); + useEffect(() => { + (async () => { + const res = (await callUpdaterMethod('get_version')) as { result: VerInfo }; + setVersionInfo(res.result); + })(); + }, []); + + return ( + {`Current version: ${versionInfo.current}\n${ + versionInfo.updatable ? `Latest version: ${versionInfo.remote?.tag_name}` : '' + }`} + ) + } + icon={ + !versionInfo ? ( + + ) : ( + + ) + } + > + {updateProgress == -1 ? ( + { + window.DeckyUpdater = { + updateProgress: (i) => { + setUpdateProgress(i); + }, + finish: async () => { + setUpdateProgress(0); + setReloading(true); + await finishUpdate(); + }, + }; + setUpdateProgress(0); + callUpdaterMethod('do_update'); + }} + > + Update + + ) : ( + + )} + + ); +} diff --git a/frontend/src/components/settings/pages/general/index.tsx b/frontend/src/components/settings/pages/general/index.tsx new file mode 100644 index 00000000..7dc5cfa4 --- /dev/null +++ b/frontend/src/components/settings/pages/general/index.tsx @@ -0,0 +1,34 @@ +import { DialogButton, Field, TextField } from 'decky-frontend-lib'; +import { useState } from 'react'; +import { FaShapes } from 'react-icons/fa'; + +import { installFromURL } from '../../../store/Store'; +import UpdaterSettings from './Updater'; + +export default function GeneralSettings() { + const [pluginURL, setPluginURL] = useState(''); + // const [checked, setChecked] = useState(false); // store these in some kind of State instead + return ( +
+ {/* } + > + setChecked(e)} + /> + */} + + setPluginURL(e?.target.value)} />} + icon={} + > + installFromURL(pluginURL)}> + Install + + +
+ ); +} diff --git a/frontend/src/components/settings/pages/plugin_list/index.tsx b/frontend/src/components/settings/pages/plugin_list/index.tsx new file mode 100644 index 00000000..a554236a --- /dev/null +++ b/frontend/src/components/settings/pages/plugin_list/index.tsx @@ -0,0 +1,34 @@ +import { DialogButton, staticClasses } from 'decky-frontend-lib'; +import { FaTrash } from 'react-icons/fa'; + +import { useDeckyState } from '../../../DeckyState'; + +export default function PluginList() { + const { plugins } = useDeckyState(); + + if (plugins.length === 0) { + return ( +
+

No plugins installed

+
+ ); + } + + return ( +
    + {plugins.map(({ name }) => ( +
  • + {name} +
    + window.DeckyPluginLoader.uninstall_plugin(name)} + > + + +
    +
  • + ))} +
+ ); +} diff --git a/frontend/src/index.tsx b/frontend/src/index.tsx index 5cf2ed14..364ccb1b 100644 --- a/frontend/src/index.tsx +++ b/frontend/src/index.tsx @@ -1,8 +1,10 @@ import PluginLoader from './plugin-loader'; +import { DeckyUpdater } from './updater'; declare global { interface Window { DeckyPluginLoader: PluginLoader; + DeckyUpdater?: DeckyUpdater; importDeckyPlugin: Function; syncDeckyPlugins: Function; } diff --git a/frontend/src/updater.ts b/frontend/src/updater.ts new file mode 100644 index 00000000..692a7a70 --- /dev/null +++ b/frontend/src/updater.ts @@ -0,0 +1,30 @@ +import { sleep } from 'decky-frontend-lib'; + +export enum Branches { + Release, + Prerelease, + Nightly, +} + +export interface DeckyUpdater { + updateProgress: (val: number) => void; + finish: () => void; +} + +export async function callUpdaterMethod(methodName: string, args = {}) { + const response = await fetch(`http://127.0.0.1:1337/updater/${methodName}`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(args), + }); + + return response.json(); +} + +export async function finishUpdate() { + callUpdaterMethod('do_restart'); + await sleep(3000); + location.reload(); +} -- cgit v1.2.3