Test and fix steam event system

This commit is contained in:
NGnius (Graham) 2022-10-13 17:53:44 -04:00
parent 17c61907a9
commit 4724576f72
7 changed files with 16 additions and 9 deletions

View file

@ -24,4 +24,3 @@ For building on another Linux PC, Rust toolchain `x86_64-unknown-linux-musl` mus
### Distribution ### Distribution
IDK, maybe a bit of custom spins as well as a barebones offering from me IDK, maybe a bit of custom spins as well as a barebones offering from me

View file

@ -24,7 +24,7 @@ jmespath = { version = "0.3", features = [ "sync" ] }
regex = { version = "1" } regex = { version = "1" }
# logging # logging
log = { version = "0.4", features = ["max_level_debug", "release_max_level_warn"] } log = { version = "0.4" }
simplelog = { version = "0.12" } simplelog = { version = "0.12" }
[profile.release] [profile.release]

View file

@ -251,6 +251,6 @@ pub struct SteamAppLifetimeNotification {
#[derive(Serialize, Deserialize, Clone)] #[derive(Serialize, Deserialize, Clone)]
pub struct SteamGameAction { pub struct SteamGameAction {
pub param0: usize, // idk what this is supposed to indicate 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 pub action: String, // idk what possible values are
} }

View file

@ -13,7 +13,7 @@ fn main() -> Result<(), ()> {
let cli_args = cli::CliArgs::cli(); let cli_args = cli::CliArgs::cli();
let log_filepath = cli_args.log.unwrap_or_else(|| format!("/tmp/{}.log", consts::PACKAGE_NAME).into()); let log_filepath = cli_args.log.unwrap_or_else(|| format!("/tmp/{}.log", consts::PACKAGE_NAME).into());
WriteLogger::init( WriteLogger::init(
LevelFilter::Off, LevelFilter::Debug,
Default::default(), Default::default(),
std::fs::File::create(&log_filepath).expect(&format!("Failed create log file {}", log_filepath.display())) std::fs::File::create(&log_filepath).expect(&format!("Failed create log file {}", log_filepath.display()))
).unwrap(); ).unwrap();
@ -33,7 +33,7 @@ fn main() -> Result<(), ()> {
.register_blocking("get_items", api::get_items(sender.clone())) .register_blocking("get_items", api::get_items(sender.clone()))
.register("on_javascript_result", api::on_javascript_result(sender.clone())) .register("on_javascript_result", api::on_javascript_result(sender.clone()))
.register("on_update", api::on_update(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())); .register_blocking("reload", api::reload(sender.clone()));
let _exec_handle = executor.spawn(); let _exec_handle = executor.spawn();
instance.run_blocking() instance.run_blocking()

View file

@ -116,6 +116,15 @@
"element": "result-display", "element": "result-display",
"title": "JS Test says", "title": "JS Test says",
"result_of": 9 "result_of": 9
},
{
"element": "event-display",
"title": "Now Playing",
"event": "game-start",
"on_event": {
"action": "json",
"jmespath": "join(' ', [action, to_string(gameID)])"
}
} }
], ],
"about": { "about": {

View file

@ -127,5 +127,5 @@ export async function onJavascriptResult(id: number, value: any): Promise<boolea
} }
export async function onSteamEvent(data: CSteamEvent): Promise<boolean> { export async function onSteamEvent(data: CSteamEvent): Promise<boolean> {
return (await call_backend("on_javascript_result", [data]))[0]; return (await call_backend("on_steam_event", [data]))[0];
} }

View file

@ -73,11 +73,11 @@ const eval2 = eval;
function jsCallback() { function jsCallback() {
return (script: backend.CJavascriptResponse) => { return (script: backend.CJavascriptResponse) => {
// register next callback (before running JS, in case that crashes)
backend.resolve(backend.getJavascriptToRun(), jsCallback());
if (script != null) { if (script != null) {
switch (script.result) { switch (script.result) {
case "javascript": case "javascript":
// register next callback (before running JS, in case that crashes)
backend.resolve(backend.getJavascriptToRun(), jsCallback());
let toRun = script as backend.CJavascriptResult; let toRun = script as backend.CJavascriptResult;
console.log("CAYLON: Got javascript " + toRun.id.toString(), toRun); console.log("CAYLON: Got javascript " + toRun.id.toString(), toRun);
let result = eval2(toRun.raw); let result = eval2(toRun.raw);
@ -376,7 +376,6 @@ function buildAbout() {
} }
export default definePlugin((serverApi: ServerAPI) => { export default definePlugin((serverApi: ServerAPI) => {
register_for_steam_events()
return { return {
title: <div className={staticClasses.Title}>{about == null? "Caylon": about.name}</div>, title: <div className={staticClasses.Title}>{about == null? "Caylon": about.name}</div>,
content: <Content serverAPI={serverApi} />, content: <Content serverAPI={serverApi} />,