From f166dee3b8d5873a5d11277530ad6f9814adfce9 Mon Sep 17 00:00:00 2001 From: honjow Date: Sat, 1 Feb 2025 03:13:13 +0800 Subject: [PATCH 1/2] Migrating to the new decky API 3 --- Makefile | 6 +- decky.pyi | 184 ++++++++++++++++++++++ main.py | 9 +- package.json | 34 ++-- plugin.json | 1 + py_modules/update.py | 5 +- py_modules/utils.py | 13 +- rollup.config.js | 41 +---- src/backend.ts | 70 ++++---- src/index.tsx | 20 +-- src/pages/About.tsx | 6 +- src/pages/Debug.tsx | 6 +- src/pages/Subscriptions.tsx | 6 +- src/pages/Version.tsx | 6 +- src/pages/components/SubList.tsx | 6 +- src/pages/components/actionButtonItem.tsx | 2 +- src/types/global.d.ts | 9 ++ tsconfig.json | 7 +- 18 files changed, 305 insertions(+), 126 deletions(-) create mode 100644 decky.pyi create mode 100644 src/types/global.d.ts diff --git a/Makefile b/Makefile index 7ca0103..2703454 100644 --- a/Makefile +++ b/Makefile @@ -28,9 +28,11 @@ init: ## Initialize project @echo -e "3. Build your code with \`\033[0;36mmake build\033[0m\` or \`\033[0;36mmake docker-build\033[0m\` to build inside a docker container" @echo -e "4. Deploy your plugin code to steamdeck with \`\033[0;36mmake deploy\033[0m\`" -update-frontend-lib: ## Update decky-frontend-lib +update-decky-ui: ## Update @decky/ui @decky/api @echo "+ $@" - @pnpm update decky-frontend-lib --latest + @pnpm update @decky/ui --latest + @pnpm update @decky/api --latest + @pnpm update @decky/rollup --latest download: @echo "+ $@" diff --git a/decky.pyi b/decky.pyi new file mode 100644 index 0000000..a72c74c --- /dev/null +++ b/decky.pyi @@ -0,0 +1,184 @@ +""" +This module exposes various constants and helpers useful for decky plugins. + +* Plugin's settings and configurations should be stored under `DECKY_PLUGIN_SETTINGS_DIR`. +* Plugin's runtime data should be stored under `DECKY_PLUGIN_RUNTIME_DIR`. +* Plugin's persistent log files should be stored under `DECKY_PLUGIN_LOG_DIR`. + +Avoid writing outside of `DECKY_HOME`, storing under the suggested paths is strongly recommended. + +Some basic migration helpers are available: `migrate_any`, `migrate_settings`, `migrate_runtime`, `migrate_logs`. + +A logging facility `logger` is available which writes to the recommended location. +""" + +__version__ = '1.0.0' + +import logging + +from typing import Any + +""" +Constants +""" + +HOME: str +""" +The home directory of the effective user running the process. +Environment variable: `HOME`. +If `root` was specified in the plugin's flags it will be `/root` otherwise the user whose home decky resides in. +e.g.: `/home/deck` +""" + +USER: str +""" +The effective username running the process. +Environment variable: `USER`. +It would be `root` if `root` was specified in the plugin's flags otherwise the user whose home decky resides in. +e.g.: `deck` +""" + +DECKY_VERSION: str +""" +The version of the decky loader. +Environment variable: `DECKY_VERSION`. +e.g.: `v2.5.0-pre1` +""" + +DECKY_USER: str +""" +The user whose home decky resides in. +Environment variable: `DECKY_USER`. +e.g.: `deck` +""" + +DECKY_USER_HOME: str +""" +The home of the user where decky resides in. +Environment variable: `DECKY_USER_HOME`. +e.g.: `/home/deck` +""" + +DECKY_HOME: str +""" +The root of the decky folder. +Environment variable: `DECKY_HOME`. +e.g.: `/home/deck/homebrew` +""" + +DECKY_PLUGIN_SETTINGS_DIR: str +""" +The recommended path in which to store configuration files (created automatically). +Environment variable: `DECKY_PLUGIN_SETTINGS_DIR`. +e.g.: `/home/deck/homebrew/settings/decky-plugin-template` +""" + +DECKY_PLUGIN_RUNTIME_DIR: str +""" +The recommended path in which to store runtime data (created automatically). +Environment variable: `DECKY_PLUGIN_RUNTIME_DIR`. +e.g.: `/home/deck/homebrew/data/decky-plugin-template` +""" + +DECKY_PLUGIN_LOG_DIR: str +""" +The recommended path in which to store persistent logs (created automatically). +Environment variable: `DECKY_PLUGIN_LOG_DIR`. +e.g.: `/home/deck/homebrew/logs/decky-plugin-template` +""" + +DECKY_PLUGIN_DIR: str +""" +The root of the plugin's directory. +Environment variable: `DECKY_PLUGIN_DIR`. +e.g.: `/home/deck/homebrew/plugins/decky-plugin-template` +""" + +DECKY_PLUGIN_NAME: str +""" +The name of the plugin as specified in the 'plugin.json'. +Environment variable: `DECKY_PLUGIN_NAME`. +e.g.: `Example Plugin` +""" + +DECKY_PLUGIN_VERSION: str +""" +The version of the plugin as specified in the 'package.json'. +Environment variable: `DECKY_PLUGIN_VERSION`. +e.g.: `0.0.1` +""" + +DECKY_PLUGIN_AUTHOR: str +""" +The author of the plugin as specified in the 'plugin.json'. +Environment variable: `DECKY_PLUGIN_AUTHOR`. +e.g.: `John Doe` +""" + +DECKY_PLUGIN_LOG: str +""" +The path to the plugin's main logfile. +Environment variable: `DECKY_PLUGIN_LOG`. +e.g.: `/home/deck/homebrew/logs/decky-plugin-template/plugin.log` +""" + +""" +Migration helpers +""" + + +def migrate_any(target_dir: str, *files_or_directories: str) -> dict[str, str]: + """ + Migrate files and directories to a new location and remove old locations. + Specified files will be migrated to `target_dir`. + Specified directories will have their contents recursively migrated to `target_dir`. + + Returns the mapping of old -> new location. + """ + + +def migrate_settings(*files_or_directories: str) -> dict[str, str]: + """ + Migrate files and directories relating to plugin settings to the recommended location and remove old locations. + Specified files will be migrated to `DECKY_PLUGIN_SETTINGS_DIR`. + Specified directories will have their contents recursively migrated to `DECKY_PLUGIN_SETTINGS_DIR`. + + Returns the mapping of old -> new location. + """ + + +def migrate_runtime(*files_or_directories: str) -> dict[str, str]: + """ + Migrate files and directories relating to plugin runtime data to the recommended location and remove old locations + Specified files will be migrated to `DECKY_PLUGIN_RUNTIME_DIR`. + Specified directories will have their contents recursively migrated to `DECKY_PLUGIN_RUNTIME_DIR`. + + Returns the mapping of old -> new location. + """ + + +def migrate_logs(*files_or_directories: str) -> dict[str, str]: + """ + Migrate files and directories relating to plugin logs to the recommended location and remove old locations. + Specified files will be migrated to `DECKY_PLUGIN_LOG_DIR`. + Specified directories will have their contents recursively migrated to `DECKY_PLUGIN_LOG_DIR`. + + Returns the mapping of old -> new location. + """ + + +""" +Logging +""" + +logger: logging.Logger +"""The main plugin logger writing to `DECKY_PLUGIN_LOG`.""" + +""" +Event handling +""" +# TODO better docstring im lazy +async def emit(event: str, *args: Any) -> None: + """ + Send an event to the frontend. + """ \ No newline at end of file diff --git a/main.py b/main.py index c40a3b2..dc6926a 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,9 @@ -import logging import subprocess import asyncio import os from config import logger, setup_logger import update -import decky_plugin +import decky import utils class Plugin: @@ -16,10 +15,10 @@ async def _main(self): utils.write_font_config() logger.info("Start Tomoon.") - os.system('chmod -R a+x ' + decky_plugin.DECKY_PLUGIN_DIR) + os.system('chmod -R a+x ' + decky.DECKY_PLUGIN_DIR) # 切换到工作目录 - os.chdir(decky_plugin.DECKY_PLUGIN_DIR) - self.backend_proc = subprocess.Popen([decky_plugin.DECKY_PLUGIN_DIR + "/bin/tomoon"]) + os.chdir(decky.DECKY_PLUGIN_DIR) + self.backend_proc = subprocess.Popen([decky.DECKY_PLUGIN_DIR + "/bin/tomoon"]) while True: await asyncio.sleep(1) diff --git a/package.json b/package.json index 3614611..ac4db97 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "tomoon", "version": "0.2.5", "description": "SteamOS Network Tools Box.", + "type": "module", "scripts": { "preinstall": "cp -r usdpl src/", "build": "shx rm -rf dist && rollup -c", @@ -26,24 +27,27 @@ }, "homepage": "https://github.com/SteamDeckHomebrew/decky-plugin-template#readme", "devDependencies": { - "@rollup/plugin-commonjs": "^21.1.0", - "@rollup/plugin-json": "^4.1.0", - "@rollup/plugin-node-resolve": "^13.3.0", - "@rollup/plugin-replace": "^4.0.0", - "@rollup/plugin-typescript": "^8.5.0", - "@types/react": "16.14.0", - "@types/webpack": "^5.28.0", - "decky-frontend-lib": "^3.24.5", - "rollup": "^2.79.1", - "rollup-plugin-import-assets": "^1.1.1", + "@decky/rollup": "^1.0.1", + "@decky/ui": "^4.9.1", + "@rollup/plugin-commonjs": "^28.0.2", + "@rollup/plugin-json": "^6.1.0", + "@rollup/plugin-node-resolve": "^16.0.0", + "@rollup/plugin-replace": "^6.0.2", + "@rollup/plugin-typescript": "^12.1.2", + "@types/react": "19.0.8", + "@types/react-dom": "^19.0.3", + "@types/webpack": "^5.28.5", + "rollup": "^4.32.1", "shx": "^0.3.4", - "tslib": "^2.4.0", - "typescript": "^4.8.4" + "tslib": "^2.8.1", + "typescript": "^5.7.3" }, "dependencies": { - "axios": "^1.2.2", - "qrcode.react": "^3.1.0", - "react-icons": "^4.6.0", + "@decky/api": "^1.1.2", + "axios": "^1.7.9", + "qrcode.react": "^4.2.0", + "react": "^19.0.0", + "react-icons": "^5.4.0", "usdpl-front": "file:src/usdpl" }, "pnpm": { diff --git a/plugin.json b/plugin.json index 32bdf1b..cb4a0c3 100644 --- a/plugin.json +++ b/plugin.json @@ -2,6 +2,7 @@ "name": "To Moon", "author": "Sayo Kurisu", "flags": ["root"], + "api_version": 1, "publish": { "tags": ["root", "network"], "description": "SteamOS Network Tools Box.", diff --git a/py_modules/update.py b/py_modules/update.py index 87fa918..12fb6f9 100644 --- a/py_modules/update.py +++ b/py_modules/update.py @@ -4,11 +4,11 @@ import ssl import stat import subprocess - import urllib.request -from config import logger, API_URL import decky_plugin +from config import API_URL, logger +from utils import get_env def recursive_chmod(path, perms): @@ -58,6 +58,7 @@ def update_latest(): text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + env=get_env(), ) logger.info(result.stdout) return result diff --git a/py_modules/utils.py b/py_modules/utils.py index 3c0f007..62c0f56 100644 --- a/py_modules/utils.py +++ b/py_modules/utils.py @@ -1,5 +1,6 @@ import os -import decky_plugin + +import decky from config import logger FONT_CONFIG = """ @@ -32,7 +33,7 @@ """ -FONT_CONF_DIR = f"{decky_plugin.DECKY_USER_HOME}/.config/fontconfig" +FONT_CONF_DIR = f"{decky.DECKY_USER_HOME}/.config/fontconfig" FONT_CONF_D_DIR = f"{FONT_CONF_DIR}/conf.d" FONT_CONF_FILE = f"{FONT_CONF_D_DIR}/76-noto-cjk.conf" @@ -59,7 +60,7 @@ def write_font_config(): f.write(FONT_CONFIG) f.close() - user = decky_plugin.DECKY_USER + user = decky.DECKY_USER # change fontconfig owner os.system(f"chown -R {user}:{user} {FONT_CONF_DIR}") @@ -73,3 +74,9 @@ def remove_font_config(): if "" in content: logger.info(f"Removing fontconfig file: {FONT_CONF_FILE}") os.remove(FONT_CONF_FILE) + + +def get_env(): + env = os.environ.copy() + env["LD_LIBRARY_PATH"] = "" + return env diff --git a/rollup.config.js b/rollup.config.js index 9615f95..17e71a7 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,38 +1,5 @@ -import commonjs from '@rollup/plugin-commonjs'; -import json from '@rollup/plugin-json'; -import { nodeResolve } from '@rollup/plugin-node-resolve'; -import replace from '@rollup/plugin-replace'; -import typescript from '@rollup/plugin-typescript'; -import { defineConfig } from 'rollup'; -import importAssets from 'rollup-plugin-import-assets'; +import deckyPlugin from "@decky/rollup"; -import { name } from "./plugin.json"; - -export default defineConfig({ - input: './src/index.tsx', - plugins: [ - commonjs(), - nodeResolve({ browser: true }), - typescript(), - json(), - replace({ - preventAssignment: false, - 'process.env.NODE_ENV': JSON.stringify('production'), - }), - importAssets({ - publicPath: `http://127.0.0.1:1337/plugins/${name}/` - }) - ], - context: 'window', - external: ['react', 'react-dom', 'decky-frontend-lib'], - output: { - file: 'dist/index.js', - globals: { - react: 'SP_REACT', - 'react-dom': 'SP_REACTDOM', - 'decky-frontend-lib': 'DFL', - }, - format: 'iife', - exports: 'default', - }, -}); +export default deckyPlugin({ + // Add your extra Rollup options here +}) \ No newline at end of file diff --git a/src/backend.ts b/src/backend.ts index aa9c289..f12df6f 100644 --- a/src/backend.ts +++ b/src/backend.ts @@ -1,4 +1,4 @@ -import { ServerAPI } from "decky-frontend-lib"; +import { call } from "@decky/api"; import { init_usdpl, init_embedded, call_backend } from "usdpl-front"; const USDPL_PORT: number = 55555; @@ -86,31 +86,37 @@ export async function getCurrentSub(): Promise { } export class PyBackendData { - private serverAPI: ServerAPI | undefined; private current_version = ""; private latest_version = ""; - public async init(serverAPI: ServerAPI) { - this.serverAPI = serverAPI; - - await this.serverAPI!.callPluginMethod<{}, string>("get_version", {}).then( - (res) => { - if (res.success) { - console.info("current_version = " + res.result); - this.current_version = res.result; - } - } - ); - - await this.serverAPI!.callPluginMethod<{}, string>( - "get_latest_version", - {} - ).then((res) => { - if (res.success) { - console.info("latest_version = " + res.result); - this.latest_version = res.result; - } - }); + public async init() { + // await this.serverAPI!.callPluginMethod<{}, string>("get_version", {}).then( + // (res) => { + // if (res.success) { + // console.info("current_version = " + res.result); + // this.current_version = res.result; + // } + // } + // ); + + const version = await call("get_version", []) as string | undefined; + if (version) { + this.current_version = version; + } + + // await this.serverAPI!.callPluginMethod<{}, string>( + // "get_latest_version", + // {} + // ).then((res) => { + // if (res.success) { + // console.info("latest_version = " + res.result); + // this.latest_version = res.result; + // } + // }); + const latest_version = await call("get_latest_version", []) as string | undefined; + if (latest_version) { + this.latest_version = latest_version; + } } public getCurrentVersion() { @@ -131,19 +137,15 @@ export class PyBackendData { } export class PyBackend { - private static serverAPI: ServerAPI; public static data: PyBackendData; - public static async init(serverAPI: ServerAPI) { - this.serverAPI = serverAPI; + public static async init() { this.data = new PyBackendData(); - this.data.init(serverAPI); + this.data.init(); } public static async getLatestVersion(): Promise { - const version = ( - await this.serverAPI!.callPluginMethod("get_latest_version", {}) - ).result as string; + const version = await call("get_latest_version", []) as string || ""; const versionReg = /^\d+\.\d+\.\d+$/; if (!versionReg.test(version)) { @@ -154,12 +156,14 @@ export class PyBackend { // updateLatest public static async updateLatest() { - await this.serverAPI!.callPluginMethod("update_latest", {}); + // await this.serverAPI!.callPluginMethod("update_latest", {}); + await call("update_latest", []); } // get_version public static async getVersion() { - return (await this.serverAPI!.callPluginMethod("get_version", {})) - .result as string; + // return (await this.serverAPI!.callPluginMethod("get_version", {})) + // .result as string; + return (await call("get_version", [])) as string; } } diff --git a/src/index.tsx b/src/index.tsx index 02b85a6..6871640 100755 --- a/src/index.tsx +++ b/src/index.tsx @@ -4,7 +4,6 @@ import { PanelSection, PanelSectionRow, Router, - ServerAPI, staticClasses, ToggleField, SidebarNavigation, @@ -13,8 +12,9 @@ import { DropdownItem, SliderField, NotchLabel, -} from "decky-frontend-lib"; -import { VFC, useEffect, useState } from "react"; +} from "@decky/ui"; +import { routerHook } from "@decky/api"; +import { FC, useEffect, useState } from "react"; import { GiEgyptianBird } from "react-icons/gi"; import { @@ -41,7 +41,7 @@ let subs_option: any[]; let current_sub = ''; let enhanced_mode = EnhancedMode.FakeIp; -const Content: VFC<{ serverAPI: ServerAPI }> = ({ }) => { +const Content: FC<{ }> = ({ }) => { if (!usdplReady) { return ( @@ -299,7 +299,7 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({ }) => { ); }; -const DeckyPluginRouterTest: VFC = () => { +const DeckyPluginRouterTest: FC = () => { return ( { ); }; -export default definePlugin((serverApi: ServerAPI) => { +export default definePlugin(() => { // init USDPL WASM and connection to back-end (async function () { await backend.initBackend(); - await backend.PyBackend.init(serverApi); + await backend.PyBackend.init(); usdplReady = true; backend.resolve(backend.getEnabled(), (v: boolean) => { enabledGlobal = v; @@ -344,14 +344,14 @@ export default definePlugin((serverApi: ServerAPI) => { })(); - serverApi.routerHook.addRoute("/tomoon-config", DeckyPluginRouterTest); + routerHook.addRoute("/tomoon-config", DeckyPluginRouterTest); return { title:
To Moon
, - content: , + content: , icon: , onDismount() { - serverApi.routerHook.removeRoute("/tomoon-config"); + routerHook.removeRoute("/tomoon-config"); }, }; }); diff --git a/src/pages/About.tsx b/src/pages/About.tsx index a447aad..02900be 100644 --- a/src/pages/About.tsx +++ b/src/pages/About.tsx @@ -1,10 +1,10 @@ -import { VFC } from "react"; -import { ButtonItem, PanelSectionRow, Navigation } from "decky-frontend-lib"; +import { FC } from "react"; +import { ButtonItem, PanelSectionRow, Navigation } from "@decky/ui"; import { FiGithub } from "react-icons/fi"; import { FaSteamSymbol } from "react-icons/fa" import { TbBrandTelegram } from "react-icons/tb" -export const About: VFC = () => { +export const About: FC = () => { return ( // The outermost div is to push the content down into the visible area <> diff --git a/src/pages/Debug.tsx b/src/pages/Debug.tsx index fe86b1f..3872013 100644 --- a/src/pages/Debug.tsx +++ b/src/pages/Debug.tsx @@ -1,10 +1,10 @@ -import { VFC } from "react"; -import { ButtonItem, PanelSectionRow } from "decky-frontend-lib"; +import { FC } from "react"; +import { ButtonItem, PanelSectionRow } from "@decky/ui"; import { VscDebug } from "react-icons/vsc" import * as backend from "../backend"; -export const Debug: VFC = () => { +export const Debug: FC = () => { return ( // The outermost div is to push the content down into the visible area <> diff --git a/src/pages/Subscriptions.tsx b/src/pages/Subscriptions.tsx index 46691d1..adc2c0a 100644 --- a/src/pages/Subscriptions.tsx +++ b/src/pages/Subscriptions.tsx @@ -1,5 +1,5 @@ -import { PanelSectionRow, TextField, ButtonItem } from "decky-frontend-lib"; -import { useReducer, useState, VFC } from "react"; +import { PanelSectionRow, TextField, ButtonItem } from "@decky/ui"; +import { useReducer, useState, FC } from "react"; import { cleanPadding } from "../style"; import { SubList } from "./components/SubList"; import { QRCodeCanvas } from 'qrcode.react'; @@ -11,7 +11,7 @@ interface SubProp { Subscriptions: Array, } -export const Subscriptions: VFC = ({ Subscriptions }) => { +export const Subscriptions: FC = ({ Subscriptions }) => { const [text, setText] = useState(""); const [downloadTips, setDownloadTips] = useState(""); const [subscriptions, updateSubscriptions] = useState(Subscriptions); diff --git a/src/pages/Version.tsx b/src/pages/Version.tsx index 7fb50b2..7d472ac 100644 --- a/src/pages/Version.tsx +++ b/src/pages/Version.tsx @@ -1,10 +1,10 @@ -import { PanelSection, PanelSectionRow, Field } from "decky-frontend-lib"; -import { VFC, useEffect, useState } from "react"; +import { PanelSection, PanelSectionRow, Field } from "@decky/ui"; +import { FC, useEffect, useState } from "react"; import { PyBackend } from "../backend"; import { ActionButtonItem } from "./components/actionButtonItem"; -export const VersionComponent: VFC = () => { +export const VersionComponent: FC = () => { const [currentVersion, _] = useState(PyBackend.data.getCurrentVersion()); const [latestVersion, setLatestVersion] = useState(PyBackend.data.getLatestVersion()); diff --git a/src/pages/components/SubList.tsx b/src/pages/components/SubList.tsx index 7fdb845..f0702a4 100644 --- a/src/pages/components/SubList.tsx +++ b/src/pages/components/SubList.tsx @@ -1,5 +1,5 @@ -import { ButtonItem } from "decky-frontend-lib"; -import { VFC } from "react"; +import { ButtonItem } from "@decky/ui"; +import { FC } from "react"; import * as backend from "../../backend"; interface appProp { Subscriptions: Array, @@ -8,7 +8,7 @@ interface appProp { } -export const SubList: VFC = ({ Subscriptions, UpdateSub, Refresh }) => { +export const SubList: FC = ({ Subscriptions, UpdateSub, Refresh }) => { return (
{ diff --git a/src/pages/components/actionButtonItem.tsx b/src/pages/components/actionButtonItem.tsx index b8293bb..820db56 100644 --- a/src/pages/components/actionButtonItem.tsx +++ b/src/pages/components/actionButtonItem.tsx @@ -1,4 +1,4 @@ -import { ButtonItem, ButtonItemProps, Spinner } from "decky-frontend-lib"; +import { ButtonItem, ButtonItemProps, Spinner } from "@decky/ui"; import { FC, useState } from "react"; export interface ActionButtonItemProps extends ButtonItemProps { diff --git a/src/types/global.d.ts b/src/types/global.d.ts new file mode 100644 index 0000000..6426e42 --- /dev/null +++ b/src/types/global.d.ts @@ -0,0 +1,9 @@ +import * as React from 'react'; + +declare global { + namespace JSX { + interface IntrinsicElements { + [elemName: string]: any; + } + } +} diff --git a/tsconfig.json b/tsconfig.json index 7e88185..a6f8c2c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,10 +15,11 @@ "noImplicitThis": true, "noImplicitAny": true, "strict": true, - "suppressImplicitAnyIndexErrors": true, "allowSyntheticDefaultImports": true, - "skipLibCheck": true + "skipLibCheck": true, + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "types": ["react/jsx-runtime", "react-dom"] }, "include": ["src"], "exclude": ["node_modules"] -} +} \ No newline at end of file From c76258061e6a0450a98623d2c4e2f7fd1fc369b6 Mon Sep 17 00:00:00 2001 From: honjow Date: Sat, 1 Feb 2025 19:03:24 +0800 Subject: [PATCH 2/2] fix api --- py_modules/update.py | 12 ++++++------ src/backend.ts | 31 +++++-------------------------- 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/py_modules/update.py b/py_modules/update.py index 12fb6f9..e5f2ef8 100644 --- a/py_modules/update.py +++ b/py_modules/update.py @@ -6,7 +6,7 @@ import subprocess import urllib.request -import decky_plugin +import decky from config import API_URL, logger from utils import get_env @@ -23,7 +23,7 @@ def update_latest(): downloaded_filepath = download_latest_build() if os.path.exists(downloaded_filepath): - plugin_dir = decky_plugin.DECKY_PLUGIN_DIR + plugin_dir = decky.DECKY_PLUGIN_DIR try: logger.info(f"removing old plugin from {plugin_dir}") @@ -40,14 +40,14 @@ def update_latest(): # extract files to decky plugins dir shutil.unpack_archive( downloaded_filepath, - f"{decky_plugin.DECKY_USER_HOME}/homebrew/plugins", + f"{decky.DECKY_USER_HOME}/homebrew/plugins", format="zip", ) # cleanup downloaded files os.remove(downloaded_filepath) except Exception as e: - decky_plugin.logger.error(f"error during ota file extraction {e}") + logger.error(f"error during ota file extraction {e}") logger.info("restarting plugin_loader.service") cmd = "systemctl restart plugin_loader.service" @@ -77,7 +77,7 @@ def download_latest_build(): logger.info(download_url) - file_path = f"/tmp/{decky_plugin.DECKY_PLUGIN_NAME}.zip" + file_path = f"/tmp/{decky.DECKY_PLUGIN_NAME}.zip" with urllib.request.urlopen(download_url, context=gcontext) as response, open( file_path, "wb" @@ -89,7 +89,7 @@ def download_latest_build(): def get_version(): - return f"{decky_plugin.DECKY_PLUGIN_VERSION}" + return f"{decky.DECKY_PLUGIN_VERSION}" def get_latest_version(): diff --git a/src/backend.ts b/src/backend.ts index f12df6f..33bdbba 100644 --- a/src/backend.ts +++ b/src/backend.ts @@ -90,30 +90,12 @@ export class PyBackendData { private latest_version = ""; public async init() { - // await this.serverAPI!.callPluginMethod<{}, string>("get_version", {}).then( - // (res) => { - // if (res.success) { - // console.info("current_version = " + res.result); - // this.current_version = res.result; - // } - // } - // ); - - const version = await call("get_version", []) as string | undefined; + const version = await call("get_version") as string || ""; if (version) { this.current_version = version; } - // await this.serverAPI!.callPluginMethod<{}, string>( - // "get_latest_version", - // {} - // ).then((res) => { - // if (res.success) { - // console.info("latest_version = " + res.result); - // this.latest_version = res.result; - // } - // }); - const latest_version = await call("get_latest_version", []) as string | undefined; + const latest_version = await call("get_latest_version") as string || ""; if (latest_version) { this.latest_version = latest_version; } @@ -145,7 +127,7 @@ export class PyBackend { } public static async getLatestVersion(): Promise { - const version = await call("get_latest_version", []) as string || ""; + const version = await call("get_latest_version") as string || ""; const versionReg = /^\d+\.\d+\.\d+$/; if (!versionReg.test(version)) { @@ -156,14 +138,11 @@ export class PyBackend { // updateLatest public static async updateLatest() { - // await this.serverAPI!.callPluginMethod("update_latest", {}); - await call("update_latest", []); + await call("update_latest"); } // get_version public static async getVersion() { - // return (await this.serverAPI!.callPluginMethod("get_version", {})) - // .result as string; - return (await call("get_version", [])) as string; + return (await call("get_version")) as string; } }