From 4724576f72b5bd603b78f9bcf81cc1d94a9b4c9a Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Thu, 13 Oct 2022 17:53:44 -0400 Subject: [PATCH] Test and fix steam event system --- README.md | 1 - backend/Cargo.toml | 2 +- backend/src/api/steam_types.rs | 2 +- backend/src/main.rs | 4 ++-- caylon.json | 9 +++++++++ src/backend.ts | 2 +- src/index.tsx | 5 ++--- 7 files changed, 16 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index fd4e7a7..7dc3e1b 100644 --- a/README.md +++ b/README.md @@ -24,4 +24,3 @@ For building on another Linux PC, Rust toolchain `x86_64-unknown-linux-musl` mus ### Distribution IDK, maybe a bit of custom spins as well as a barebones offering from me - diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 2fe5aae..cb3b4f9 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -24,7 +24,7 @@ jmespath = { version = "0.3", features = [ "sync" ] } regex = { version = "1" } # logging -log = { version = "0.4", features = ["max_level_debug", "release_max_level_warn"] } +log = { version = "0.4" } simplelog = { version = "0.12" } [profile.release] diff --git a/backend/src/api/steam_types.rs b/backend/src/api/steam_types.rs index 1bb4c94..be50735 100644 --- a/backend/src/api/steam_types.rs +++ b/backend/src/api/steam_types.rs @@ -251,6 +251,6 @@ pub struct SteamAppLifetimeNotification { #[derive(Serialize, Deserialize, Clone)] pub struct SteamGameAction { pub param0: usize, // idk what this is supposed to indicate - pub gameID: usize, + pub gameID: String, // almost definitely a valid integer pub action: String, // idk what possible values are } diff --git a/backend/src/main.rs b/backend/src/main.rs index de4d755..a9cb1da 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -13,7 +13,7 @@ fn main() -> Result<(), ()> { let cli_args = cli::CliArgs::cli(); let log_filepath = cli_args.log.unwrap_or_else(|| format!("/tmp/{}.log", consts::PACKAGE_NAME).into()); WriteLogger::init( - LevelFilter::Off, + LevelFilter::Debug, Default::default(), std::fs::File::create(&log_filepath).expect(&format!("Failed create log file {}", log_filepath.display())) ).unwrap(); @@ -33,7 +33,7 @@ fn main() -> Result<(), ()> { .register_blocking("get_items", api::get_items(sender.clone())) .register("on_javascript_result", api::on_javascript_result(sender.clone())) .register("on_update", api::on_update(sender.clone())) - .register("on_event", api::on_event(sender.clone())) + .register("on_steam_event", api::on_event(sender.clone())) .register_blocking("reload", api::reload(sender.clone())); let _exec_handle = executor.spawn(); instance.run_blocking() diff --git a/caylon.json b/caylon.json index 8bb506f..705d2b7 100644 --- a/caylon.json +++ b/caylon.json @@ -116,6 +116,15 @@ "element": "result-display", "title": "JS Test says", "result_of": 9 + }, + { + "element": "event-display", + "title": "Now Playing", + "event": "game-start", + "on_event": { + "action": "json", + "jmespath": "join(' ', [action, to_string(gameID)])" + } } ], "about": { diff --git a/src/backend.ts b/src/backend.ts index 05c6a75..dc28a4d 100644 --- a/src/backend.ts +++ b/src/backend.ts @@ -127,5 +127,5 @@ export async function onJavascriptResult(id: number, value: any): Promise { - return (await call_backend("on_javascript_result", [data]))[0]; + return (await call_backend("on_steam_event", [data]))[0]; } diff --git a/src/index.tsx b/src/index.tsx index 287ea04..6887e0e 100755 --- a/src/index.tsx +++ b/src/index.tsx @@ -73,11 +73,11 @@ const eval2 = eval; function jsCallback() { return (script: backend.CJavascriptResponse) => { - // register next callback (before running JS, in case that crashes) - backend.resolve(backend.getJavascriptToRun(), jsCallback()); if (script != null) { switch (script.result) { case "javascript": + // register next callback (before running JS, in case that crashes) + backend.resolve(backend.getJavascriptToRun(), jsCallback()); let toRun = script as backend.CJavascriptResult; console.log("CAYLON: Got javascript " + toRun.id.toString(), toRun); let result = eval2(toRun.raw); @@ -376,7 +376,6 @@ function buildAbout() { } export default definePlugin((serverApi: ServerAPI) => { - register_for_steam_events() return { title:
{about == null? "Caylon": about.name}
, content: ,