Skip to content

Commit

Permalink
Fix debug and exec on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
DervexDev committed May 5, 2024
1 parent 7de8d85 commit ef1fa02
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions src/cli/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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()
Expand All @@ -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");
}
Expand Down
6 changes: 5 additions & 1 deletion src/server/exec.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -25,7 +26,10 @@ async fn main(request: MsgPack<Request>, core: Data<Arc<Core>>) -> 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),
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/stats.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 11 additions & 2 deletions src/studio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn focus(title: Option<String>) -> Result<()> {

#[cfg(target_os = "windows")]
{
EnumWindows(|hwnd| -> bool {
let result = EnumWindows(|hwnd| -> bool {
if !hwnd.IsWindowVisible() {
return true;
}
Expand All @@ -134,7 +134,16 @@ pub fn focus(title: Option<String>) -> Result<()> {
}

true
})?;
});

match result {
Ok(()) => (),
Err(err) => {
if err.raw() != 0 {
anyhow::bail!("Failed to focus Roblox Studio: {}", err)
}
}
}

Ok(())
}
Expand Down

0 comments on commit ef1fa02

Please sign in to comment.