Add new backend interface to front-end (untested)

This commit is contained in:
NGnius 2022-08-23 17:50:46 -04:00
parent c225554f78
commit 0a4d84c22f
8 changed files with 710 additions and 2 deletions

View file

@ -40,6 +40,7 @@
},
"dependencies": {
"decky-frontend-lib": "*",
"react-icons": "^4.4.0"
"react-icons": "^4.4.0",
"usdpl-front": "file:./src/usdpl_front"
}
}

View file

@ -71,7 +71,7 @@ fn main() -> Result<(), ()> {
api::cpu::set_cpu_online(default_settings.cpus.clone(), save_sender.clone())
)
.register(
"CPU_get_online",
"CPU_get_onlines",
api::cpu::get_cpus_online(default_settings.cpus.clone())
)
.register(

113
src/backend.ts Normal file
View file

@ -0,0 +1,113 @@
import {init_usdpl, target, init_embedded, call_backend} from "usdpl-front";
const USDPL_PORT: number = 44443;
// Utility
export function resolve(promise: Promise<any>, setter: any) {
(async function () {
let data = await promise;
if (data != null) {
console.debug("Got resolved", data);
setter(data);
} else {
console.warn("Resolve failed:", data);
}
})();
}
export async function initBackend() {
// init usdpl
await init_embedded();
init_usdpl(USDPL_PORT);
console.log("USDPL started for framework: " + target());
//setReady(true);
}
// API
// Battery
export async function getBatteryCurrent(): Promise<number> {
return (await call_backend("BATTERY_current_now", []))[0];
}
export async function getBatteryChargeRate(): Promise<number> {
return (await call_backend("BATTERY_get_charge_rate", []))[0];
}
export async function setBatteryChargeRate(val: number): Promise<number> {
return (await call_backend("BATTERY_set_charge_rate", [val]))[0];
}
export async function unsetBatteryChargeRate(): Promise<any[]> {
return await call_backend("BATTERY_unset_charge_rate", []);
}
// CPU
export async function getCpuCount(): Promise<number> {
return (await call_backend("CPU_count", []))[0];
}
export async function setCpuOnline(index: number, online: boolean): Promise<boolean> {
return (await call_backend("CPU_set_online", [index, online]))[0];
}
export async function getCpusOnline(): Promise<boolean[]> {
return (await call_backend("CPU_get_onlines", [])); // -> online status for all CPUs
}
export async function setCpuClockLimits(index: number, min: number, max: number): Promise<number[]> {
return (await call_backend("CPU_set_clock_limits", [index, min, max])); // -> [min, max]
}
export async function getCpuClockLimits(index: number): Promise<number[]> {
return (await call_backend("CPU_get_clock_limits", [index])); // -> [min, max]
}
export async function unsetCpuClockLimits(index: number): Promise<any[]> {
return (await call_backend("CPU_unset_clock_limits", [index]));
}
export async function setCpuGovernor(index: number, val: string): Promise<string> {
return (await call_backend("CPU_set_governor", [index, val]))[0];
}
export async function getCpusGovernor(): Promise<string[]> {
return (await call_backend("CPU_get_governors", [])); // -> governors for all CPUs
}
// GPU
export async function setGpuPpt(fast: number, slow: number): Promise<number[]> {
return (await call_backend("GPU_set_ppt", [fast, slow])); // -> [fastPPT, slowPPT]
}
export async function getGpuPpt(): Promise<number[]> {
return (await call_backend("GPU_get_ppt", [])); // -> [fastPPT, slowPPT]
}
export async function unsetGpuPpt(): Promise<any[]> {
return (await call_backend("GPU_unset_ppt", []));
}
export async function setGpuClockLimits(min: number, max: number): Promise<number[]> {
return (await call_backend("GPU_set_clock_limits", [min, max])); // -> [min, max]
}
export async function getGpuClockLimits(): Promise<number[]> {
return (await call_backend("GPU_get_clock_limits", [])); // -> [min, max]
}
export async function unsetGpuClockLimits(): Promise<any[]> {
return (await call_backend("GPU_unset_clock_limits", []));
}
export async function setGpuSlowMemory(val: boolean): Promise<boolean> {
return (await call_backend("GPU_set_slow_memory", [min, max]))[0];
}
export async function getGpuSlowMemory(): Promise<boolean> {
return (await call_backend("GPU_get_slow_memory", []))[0];
}

View file

@ -0,0 +1,21 @@
{
"name": "usdpl-front",
"collaborators": [
"NGnius (Graham) <ngniusness@gmail.com>"
],
"description": "Universal Steam Deck Plugin Library front-end designed for WASM",
"version": "0.6.0",
"license": "GPL-3.0-only",
"repository": {
"type": "git",
"url": "https://github.com/NGnius/usdpl-rs"
},
"files": [
"usdpl_front_bg.wasm",
"usdpl_front.js",
"usdpl_front.d.ts"
],
"module": "usdpl_front.js",
"types": "usdpl_front.d.ts",
"sideEffects": false
}

60
src/usdpl_front/usdpl_front.d.ts vendored Normal file
View file

@ -0,0 +1,60 @@
/* tslint:disable */
/* eslint-disable */
/**
* Initialize the front-end library
* @param {number} port
*/
export function init_usdpl(port: number): void;
/**
* Get the targeted plugin framework, or "any" if unknown
* @returns {string}
*/
export function target(): string;
/**
* Call a function on the back-end.
* Returns null (None) if this fails for any reason.
* @param {string} name
* @param {any[]} parameters
* @returns {Promise<any>}
*/
export function call_backend(name: string, parameters: any[]): Promise<any>;
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly init_usdpl: (a: number) => void;
readonly target: (a: number) => void;
readonly call_backend: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_export_0: (a: number) => number;
readonly __wbindgen_export_1: (a: number, b: number, c: number) => number;
readonly __wbindgen_export_2: WebAssembly.Table;
readonly __wbindgen_export_3: (a: number, b: number, c: number) => void;
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
readonly __wbindgen_export_4: (a: number, b: number) => void;
readonly __wbindgen_export_5: (a: number) => void;
readonly __wbindgen_export_6: (a: number, b: number, c: number, d: number) => void;
}
/**
* Synchronously compiles the given `bytes` and instantiates the WebAssembly module.
*
* @param {BufferSource} bytes
*
* @returns {InitOutput}
*/
export function initSync(bytes: BufferSource): InitOutput;
/**
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
* for everything else, calls `WebAssembly.instantiate` directly.
*
* @param {InitInput | Promise<InitInput>} module_or_path
*
* @returns {Promise<InitOutput>}
*/
export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
// USDPL customization
export function init_embedded();

File diff suppressed because one or more lines are too long

Binary file not shown.

View file

@ -0,0 +1,14 @@
/* tslint:disable */
/* eslint-disable */
export const memory: WebAssembly.Memory;
export function init_usdpl(a: number): void;
export function target(a: number): void;
export function call_backend(a: number, b: number, c: number, d: number): number;
export function __wbindgen_export_0(a: number): number;
export function __wbindgen_export_1(a: number, b: number, c: number): number;
export const __wbindgen_export_2: WebAssembly.Table;
export function __wbindgen_export_3(a: number, b: number, c: number): void;
export function __wbindgen_add_to_stack_pointer(a: number): number;
export function __wbindgen_export_4(a: number, b: number): void;
export function __wbindgen_export_5(a: number): void;
export function __wbindgen_export_6(a: number, b: number, c: number, d: number): void;