Add back-end placeholder
This commit is contained in:
parent
8b1b5821f9
commit
14ff848b0a
17 changed files with 2422 additions and 7 deletions
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -40,3 +40,11 @@ __pycache__/
|
||||||
yalc.lock
|
yalc.lock
|
||||||
|
|
||||||
.vscode/settings.json
|
.vscode/settings.json
|
||||||
|
|
||||||
|
# ignore Rust compiler files
|
||||||
|
/server/target
|
||||||
|
backend
|
||||||
|
/bin
|
||||||
|
|
||||||
|
# packaged teasers
|
||||||
|
*.zip
|
||||||
|
|
19
main.py
19
main.py
|
@ -1,9 +1,16 @@
|
||||||
|
import pathlib
|
||||||
|
import subprocess
|
||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
HOME_DIR = str(pathlib.Path(os.getcwd()).parent.parent.resolve())
|
||||||
|
PARENT_DIR = str(pathlib.Path(__file__).parent.resolve())
|
||||||
|
|
||||||
class Plugin:
|
class Plugin:
|
||||||
# A normal method. It can be called from JavaScript using call_plugin_function("method_1", argument1, argument2)
|
backend_proc = None
|
||||||
async def add(self, left, right):
|
|
||||||
return left + right
|
|
||||||
|
|
||||||
|
|
||||||
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
|
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
|
||||||
async def _main(self):
|
async def _main(self):
|
||||||
pass
|
# startup
|
||||||
|
self.backend_proc = subprocess.Popen([PARENT_DIR + "/bin/backend"])
|
||||||
|
while True:
|
||||||
|
asyncio.sleep(1)
|
||||||
|
|
|
@ -40,7 +40,8 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"decky-frontend-lib": "^1.0.1",
|
"decky-frontend-lib": "^1.0.1",
|
||||||
"react-icons": "^4.3.1"
|
"react-icons": "^4.3.1",
|
||||||
|
"usdpl-front": "file:./src/usdpl-front"
|
||||||
},
|
},
|
||||||
"pnpm": {
|
"pnpm": {
|
||||||
"peerDependencyRules": {
|
"peerDependencyRules": {
|
||||||
|
|
1095
server/Cargo.lock
generated
Normal file
1095
server/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
19
server/Cargo.toml
Normal file
19
server/Cargo.toml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
[package]
|
||||||
|
name = "backend" # TODO replace with plugin name (also in build.sh)
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
usdpl-back = { version = "0.5.3", features = ["decky"] }
|
||||||
|
|
||||||
|
# logging
|
||||||
|
log = "0.4"
|
||||||
|
simplelog = "0.12"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
debug = false
|
||||||
|
strip = true
|
||||||
|
lto = true
|
||||||
|
codegen-units = 4
|
2
server/Cross.toml
Normal file
2
server/Cross.toml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[build]
|
||||||
|
default-target = "x86_64-unknown-linux-gnu"
|
6
server/build.sh
Executable file
6
server/build.sh
Executable file
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cargo build --release
|
||||||
|
mkdir ../bin
|
||||||
|
# TODO replace "backend" \/ with binary name
|
||||||
|
cp ./target/release/backend ../bin/backend
|
25
server/src/main.rs
Normal file
25
server/src/main.rs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
use simplelog::{WriteLogger, LevelFilter};
|
||||||
|
|
||||||
|
use usdpl_back::Instance;
|
||||||
|
use usdpl_back::core::serdes::Primitive;
|
||||||
|
|
||||||
|
const PORT: u16 = 54321; // TODO replace with something unique
|
||||||
|
|
||||||
|
const PACKAGE_NAME: &'static str = env!("CARGO_PKG_NAME");
|
||||||
|
const PACKAGE_VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
|
fn main() -> Result<(), ()> {
|
||||||
|
let log_filepath = format!("/tmp/{}.log", PACKAGE_NAME);
|
||||||
|
WriteLogger::init(
|
||||||
|
#[cfg(debug_assertions)]{LevelFilter::Debug},
|
||||||
|
#[cfg(not(debug_assertions))]{LevelFilter::Info},
|
||||||
|
Default::default(),
|
||||||
|
std::fs::File::create(&log_filepath).unwrap()
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
log::info!("Starting back-end ({} v{})", PACKAGE_NAME, PACKAGE_VERSION);
|
||||||
|
println!("Starting back-end ({} v{})", PACKAGE_NAME, PACKAGE_VERSION);
|
||||||
|
Instance::new(PORT)
|
||||||
|
.register("hello", |_: Vec<Primitive>| vec![format!("Hello {}", PACKAGE_NAME).into()])
|
||||||
|
.run_blocking()
|
||||||
|
}
|
|
@ -16,6 +16,10 @@ import { FaShip } from "react-icons/fa";
|
||||||
|
|
||||||
import logo from "../assets/logo.png";
|
import logo from "../assets/logo.png";
|
||||||
|
|
||||||
|
import {init_usdpl, target, init_embedded, call_backend} from "usdpl-front";
|
||||||
|
|
||||||
|
const USDPL_PORT: number = 54321;
|
||||||
|
|
||||||
// interface AddMethodArgs {
|
// interface AddMethodArgs {
|
||||||
// left: number;
|
// left: number;
|
||||||
// right: number;
|
// right: number;
|
||||||
|
@ -37,6 +41,12 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => {
|
||||||
// }
|
// }
|
||||||
// };
|
// };
|
||||||
|
|
||||||
|
// call hello callback on backend
|
||||||
|
(async () => {
|
||||||
|
let response = await call_backend("hello", []);
|
||||||
|
console.log("Backend says:", response);
|
||||||
|
})();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PanelSection title="Panel Section">
|
<PanelSection title="Panel Section">
|
||||||
<PanelSectionRow>
|
<PanelSectionRow>
|
||||||
|
@ -94,6 +104,14 @@ export default definePlugin((serverApi: ServerAPI) => {
|
||||||
exact: true,
|
exact: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// init USDPL WASM frontend
|
||||||
|
// this is required to interface with the backend
|
||||||
|
(async () => {
|
||||||
|
await init_embedded();
|
||||||
|
init_usdpl(USDPL_PORT);
|
||||||
|
console.log("USDPL started for framework: " + target());
|
||||||
|
})();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: <div className={staticClasses.Title}>Example Plugin</div>,
|
title: <div className={staticClasses.Title}>Example Plugin</div>,
|
||||||
content: <Content serverAPI={serverApi} />,
|
content: <Content serverAPI={serverApi} />,
|
||||||
|
|
57
src/usdpl-front/usdpl.d.ts
vendored
Normal file
57
src/usdpl-front/usdpl.d.ts
vendored
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/* 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 class UsdplContext {
|
||||||
|
free(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
||||||
|
|
||||||
|
export interface InitOutput {
|
||||||
|
readonly memory: WebAssembly.Memory;
|
||||||
|
readonly __wbg_usdplcontext_free: (a: number) => void;
|
||||||
|
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_malloc: (a: number) => number;
|
||||||
|
readonly __wbindgen_realloc: (a: number, b: number, c: number) => number;
|
||||||
|
readonly __wbindgen_export_2: WebAssembly.Table;
|
||||||
|
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h16ac289f583b8044: (a: number, b: number, c: number) => void;
|
||||||
|
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
||||||
|
readonly __wbindgen_free: (a: number, b: number) => void;
|
||||||
|
readonly __wbindgen_exn_store: (a: number) => void;
|
||||||
|
readonly wasm_bindgen__convert__closures__invoke2_mut__ha1c5a356ae6a22de: (a: number, b: number, c: number, d: number) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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();
|
589
src/usdpl-front/usdpl.js
Normal file
589
src/usdpl-front/usdpl.js
Normal file
File diff suppressed because one or more lines are too long
BIN
src/usdpl-front/usdpl_bg.wasm
Normal file
BIN
src/usdpl-front/usdpl_bg.wasm
Normal file
Binary file not shown.
15
src/usdpl-front/usdpl_bg.wasm.d.ts
vendored
Normal file
15
src/usdpl-front/usdpl_bg.wasm.d.ts
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/* tslint:disable */
|
||||||
|
/* eslint-disable */
|
||||||
|
export const memory: WebAssembly.Memory;
|
||||||
|
export function __wbg_usdplcontext_free(a: number): void;
|
||||||
|
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_malloc(a: number): number;
|
||||||
|
export function __wbindgen_realloc(a: number, b: number, c: number): number;
|
||||||
|
export const __wbindgen_export_2: WebAssembly.Table;
|
||||||
|
export function _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h16ac289f583b8044(a: number, b: number, c: number): void;
|
||||||
|
export function __wbindgen_add_to_stack_pointer(a: number): number;
|
||||||
|
export function __wbindgen_free(a: number, b: number): void;
|
||||||
|
export function __wbindgen_exn_store(a: number): void;
|
||||||
|
export function wasm_bindgen__convert__closures__invoke2_mut__ha1c5a356ae6a22de(a: number, b: number, c: number, d: number): void;
|
60
src/usdpl-front/usdpl_front.d.ts
vendored
Normal file
60
src/usdpl-front/usdpl_front.d.ts
vendored
Normal 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();
|
499
src/usdpl-front/usdpl_front.js
Normal file
499
src/usdpl-front/usdpl_front.js
Normal file
File diff suppressed because one or more lines are too long
BIN
src/usdpl-front/usdpl_front_bg.wasm
Normal file
BIN
src/usdpl-front/usdpl_front_bg.wasm
Normal file
Binary file not shown.
14
src/usdpl-front/usdpl_front_bg.wasm.d.ts
vendored
Normal file
14
src/usdpl-front/usdpl_front_bg.wasm.d.ts
vendored
Normal 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;
|
Reference in a new issue