From ef1fa02dd22c931564d84b3884e3b3f40597a3fd Mon Sep 17 00:00:00 2001 From: Dervex Date: Sun, 5 May 2024 14:15:38 +0200 Subject: [PATCH] Fix `debug` and `exec` on Windows --- CHANGELOG.md | 5 +++++ src/cli/exec.rs | 13 +++++++++++-- src/server/exec.rs | 6 +++++- src/stats.rs | 8 ++++++-- src/studio.rs | 13 +++++++++++-- 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a2a80d..f7b73f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ## [Unreleased] +### Fixed + +- `debug` command no longer errors even when succeeding on Windows +- `exec` command now actually focuses Roblox Studio when enabled on Windows + ## [2.0.3] - 2024-05-04 ### Added diff --git a/src/cli/exec.rs b/src/cli/exec.rs index 12bda0b..68eb62f 100644 --- a/src/cli/exec.rs +++ b/src/cli/exec.rs @@ -4,7 +4,7 @@ use reqwest::{blocking::Client, header::CONTENT_TYPE}; use serde::Serialize; use std::{fs, path::MAIN_SEPARATOR}; -use crate::{argon_error, argon_info, sessions}; +use crate::{argon_error, argon_info, sessions, studio}; /// Execute Luau code in Roblox Studio (requires running session) #[derive(Parser)] @@ -51,7 +51,11 @@ impl Exec { let body = rmp_serde::to_vec(&Request { code: code.to_owned(), - focus: self.focus, + focus: if cfg!(not(target_os = "windows")) { + self.focus + } else { + false + }, })?; let response = Client::default() @@ -64,6 +68,11 @@ impl Exec { Ok(_) => argon_info!("Code executed successfully!"), Err(err) => argon_error!("Code execution failed: {}", err), } + + #[cfg(target_os = "windows")] + if self.focus { + studio::focus(None)?; + } } else { argon_error!("Code execution failed: running session does not have an address"); } diff --git a/src/server/exec.rs b/src/server/exec.rs index 75d0d99..d021eb7 100644 --- a/src/server/exec.rs +++ b/src/server/exec.rs @@ -1,5 +1,6 @@ use actix_msgpack::MsgPack; use actix_web::{post, web::Data, HttpResponse, Responder}; +use log::error; use serde::Deserialize; use std::sync::Arc; @@ -25,7 +26,10 @@ async fn main(request: MsgPack, core: Data>) -> impl Responde if request.focus { if let Some(name) = queue.get_first_non_internal_listener_name() { - studio::focus(Some(name)).ok(); + match studio::focus(Some(name)) { + Ok(()) => (), + Err(err) => error!("Failed to focus Roblox Studio: {}", err), + } } } diff --git a/src/stats.rs b/src/stats.rs index 3ba98a4..ab2269e 100644 --- a/src/stats.rs +++ b/src/stats.rs @@ -1,6 +1,6 @@ use anyhow::Result; use lazy_static::lazy_static; -use log::{debug, warn}; +use log::{debug, trace, warn}; use reqwest::blocking::Client; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -147,7 +147,11 @@ pub fn track() -> Result<()> { thread::spawn(|| loop { thread::sleep(Duration::from_secs(300)); minutes_used(5); - save().ok(); + + match save() { + Ok(_) => trace!("Stats saved successfully"), + Err(err) => warn!("Failed to save stats: {}", err), + } }); sessions_started(1); diff --git a/src/studio.rs b/src/studio.rs index 2602430..db21997 100644 --- a/src/studio.rs +++ b/src/studio.rs @@ -112,7 +112,7 @@ pub fn focus(title: Option) -> Result<()> { #[cfg(target_os = "windows")] { - EnumWindows(|hwnd| -> bool { + let result = EnumWindows(|hwnd| -> bool { if !hwnd.IsWindowVisible() { return true; } @@ -134,7 +134,16 @@ pub fn focus(title: Option) -> Result<()> { } true - })?; + }); + + match result { + Ok(()) => (), + Err(err) => { + if err.raw() != 0 { + anyhow::bail!("Failed to focus Roblox Studio: {}", err) + } + } + } Ok(()) }