Skip to content

Commit

Permalink
refactor: Use new decky plugin format (#35)
Browse files Browse the repository at this point in the history
* refactor: Use new decky plugin format

* replace usage of decky-frontend-lib with @decky/api & @decky/ui
* use @decky/rollup to do rollup configuration
* upgrade outdated dependencies
* update ci to use pnpm@9 specifically

Signed-off-by: eXhumer <[email protected]>

* replace deprecated `VFC` with `FC`

* style: Add eslint to lint frontend source

* add CI job to lint source

Signed-off-by: eXhumer <[email protected]>

* chore: Remove unused backend methods

* add CI job to lint backend code

Signed-off-by: eXhumer <[email protected]>

* fix custom options

Signed-off-by: eXhumer <[email protected]>

* chore: dependency changes
* change @decky/ui to dev dependency
* remove shx (not needed as @decky/rollup takes care of cleaning dist directory)
* add tslib as normal dependency
* upgrade rollup to 4.22.5

Signed-off-by: eXhumer <[email protected]>

---------

Signed-off-by: eXhumer <[email protected]>
Co-authored-by: sheffey <[email protected]>
  • Loading branch information
eXhumer and SheffeyG authored Sep 29, 2024
1 parent 68591f5 commit a11014c
Show file tree
Hide file tree
Showing 23 changed files with 3,270 additions and 843 deletions.
48 changes: 42 additions & 6 deletions .github/workflows/dev-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
workflow_dispatch:

jobs:
build-plugin:
lint-frontend:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -18,13 +18,49 @@ jobs:
with:
node-version: latest

- name: Setup latest PNPM
uses: pnpm/action-setup@v2
- name: Setup PNPM@9
uses: pnpm/action-setup@v4
with:
version: latest
version: 9

- name: Lint frontend source
run: |
pnpm i
pnpm run lint:frontend
lint-backend:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup latest Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
check-latest: true

- name: Install flake8
run: pip install flake8

- name: Lint backend source
run: flake8 main.py

- name: Update decky-frontend-lib
run: pnpm update decky-frontend-lib --latest
build-plugin:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup latest Node.js
uses: actions/setup-node@v4
with:
node-version: latest

- name: Setup PNPM@9
uses: pnpm/action-setup@v4
with:
version: 9

- name: Build frontend from source
run: |
Expand Down
14 changes: 12 additions & 2 deletions decky_plugin.pyi → decky.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ Some basic migration helpers are available: `migrate_any`, `migrate_settings`, `
A logging facility `logger` is available which writes to the recommended location.
"""

__version__ = '0.1.0'
__version__ = '1.0.0'

import logging

from typing import Any

"""
Constants
"""
Expand Down Expand Up @@ -50,7 +52,6 @@ Environment variable: `DECKY_USER`.
e.g.: `deck`
"""


DECKY_USER_HOME: str
"""
The home of the user where decky resides in.
Expand Down Expand Up @@ -172,3 +173,12 @@ 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.
"""
32 changes: 32 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginReact from "eslint-plugin-react";
import stylistic from "@stylistic/eslint-plugin";

export default [
{
ignores: ["dist/*"],
},
{
settings: {
react: {
version: "18.3",
},
},
},
stylistic.configs.customize({
indent: 2,
quotes: "double",
semi: true,
jsx: true,
}),
pluginJs.configs.recommended,
...tseslint.configs.recommended,
pluginReact.configs.flat.recommended,
{
files: ["src/**/*.{js,mjs,cjs,ts,jsx,tsx}"],
rules: {
"react/react-in-jsx-scope": "off",
},
},
];
93 changes: 51 additions & 42 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,61 @@
#!/usr/bin/env python
import logging, os
from settings import SettingsManager # type: ignore
import decky_plugin # type: ignore
import logging
import typing
from settings import SettingsManager # type: ignore
import decky # type: ignore

# Setup environment variables
deckyHomeDir = decky_plugin.DECKY_HOME
settingsDir = decky_plugin.DECKY_PLUGIN_SETTINGS_DIR
loggingDir = decky_plugin.DECKY_PLUGIN_LOG_DIR
logger = decky_plugin.logger
deckyHomeDir = decky.DECKY_HOME
settingsDir = decky.DECKY_PLUGIN_SETTINGS_DIR
loggingDir = decky.DECKY_PLUGIN_LOG_DIR
logger = decky.logger

# Setup backend logger
logger.setLevel(logging.DEBUG) # can be changed to logging.DEBUG for debugging issues
logger.setLevel(logging.DEBUG)
logger.info('[backend] Settings path: {}'.format(settingsDir))
settings = SettingsManager(name="settings", settings_directory=settingsDir)
settings.read()


class SetSettingOptions(typing.TypedDict):
key: str
value: typing.Any


class GetSettingOptions(typing.TypedDict):
key: str
defaults: typing.Any


class Plugin:
async def plugin_info(self):
# Call plugin_info only once preferably
logger.debug('[backend] PluginInfo:\n\tPluginName: {}\n\tPluginVersion: {}\n\tDeckyVersion: {}'.format(
decky_plugin.DECKY_PLUGIN_NAME,
decky_plugin.DECKY_PLUGIN_VERSION,
decky_plugin.DECKY_VERSION
))
pluginInfo = {
"name": decky_plugin.DECKY_PLUGIN_NAME,
"version": decky_plugin.DECKY_PLUGIN_VERSION
}
return pluginInfo

async def logger(self, logLevel:str, msg:str):
msg = '[frontend] {}'.format(msg)
match logLevel.lower():
case 'info': logger.info(msg)
case 'debug': logger.debug(msg)
case 'warning': logger.warning(msg)
case 'error': logger.error(msg)
case 'critical': logger.critical(msg)

async def settings_read(self):
logger.info('[backend] Reading settings')
return settings.read()
async def settings_commit(self):
logger.info('[backend] Saving settings')
return settings.commit()
async def settings_getSetting(self, key: str, defaults):
logger.info('[backend] Get {}'.format(key))
return settings.getSetting(key, defaults)
async def settings_setSetting(self, key: str, value):
logger.info('[backend] Set {}: {}'.format(key, value))
return settings.setSetting(key, value)
@classmethod
async def _main(cls):
logger.info("[backend] Loading CheatDeck!")

@classmethod
async def _unload(cls):
logger.info("[backend] Unloading CheatDeck!")

@classmethod
async def _uninstall(cls):
logger.info("[backend] Uninstalling CheatDeck!")

@classmethod
async def settings_read(cls):
logger.info('[backend] Reading settings')
return settings.read()

@classmethod
async def settings_commit(cls):
logger.info('[backend] Saving settings')
return settings.commit()

@classmethod
async def settings_getSetting(cls, data: GetSettingOptions):
logger.info('[backend] Get {}'.format(data['key']))
return settings.getSetting(data['key'], data['defaults'])

@classmethod
async def settings_setSetting(cls, data: SetSettingOptions):
logger.info('[backend] Set {}: {}'.format(data['key'], data['value']))
return settings.setSetting(data['key'], data['value'])
39 changes: 21 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"name": "cheatdeck",
"type": "module",
"version": "0.3.2",
"description": "Launch games with cheat or trainer and manage your launch options.",
"scripts": {
"build": "shx rm -rf dist && rollup -c",
"build": "rollup -c",
"watch": "rollup -c -w",
"lint:frontend": "eslint",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
Expand All @@ -24,25 +26,26 @@
},
"homepage": "https://github.com/SheffeyG/CheatDeck#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.3.3",
"@types/react": "16.14.0",
"@types/webpack": "^5.28.0",
"@types/uuid": "^9.0.8",
"rollup": "^2.77.1",
"rollup-plugin-import-assets": "^1.1.1",
"shx": "^0.3.4",
"tslib": "^2.4.0",
"typescript": "^4.7.4"
"@decky/rollup": "^1.0.1",
"@decky/ui": "^4.7.2",
"@eslint/js": "^9.11.1",
"@stylistic/eslint-plugin": "^2.8.0",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"@types/uuid": "^10.0.0",
"@types/webpack": "^5.28.5",
"eslint": "^9.11.1",
"eslint-plugin-react": "^7.37.0",
"rollup": "^4.22.5",
"typescript": "^5.6.2",
"typescript-eslint": "^8.7.0"
},
"dependencies": {
"uuid": "^9.0.0",
"decky-frontend-lib": "^3.24.5",
"qrcode.react": "^3.1.0",
"react-icons": "^4.4.0"
"@decky/api": "^1.1.2",
"qrcode.react": "^4.0.1",
"react-icons": "^5.3.0",
"tslib": "^2.7.0",
"uuid": "^10.0.0"
},
"pnpm": {
"peerDependencyRules": {
Expand Down
1 change: 1 addition & 0 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "CheatDeck",
"author": "Sheffey",
"flags": [],
"api_version": 1,
"publish": {
"tags": [ "cheat", "trainer" ],
"description": "Launch games with cheat or trainer and manage your launch options.",
Expand Down
Loading

0 comments on commit a11014c

Please sign in to comment.