Skip to content

Commit

Permalink
Improve rbx_reflector Roblox Studio automation and logging on macOS (
Browse files Browse the repository at this point in the history
…rojo-rbx#407)

This PR brings automatic place saving to macOS, so it now works exactly the same
as on Windows. It also pipes the `stdout` and `stderr` streams to `null` to get
rid of extreme verbosity on macOS. Lastly, it adds a check to the injected
plugin so it won't run outside of the defaults place, which is useful when other
Roblox Studio instances are open and Roblox Studio's "Reload plugins on file
changed" setting is enabled.
  • Loading branch information
DervexDev authored Apr 23, 2024
1 parent acf3d74 commit 8ca9250
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions rbx_reflector/plugin.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if game.Name ~= "defaults-place.rbxlx" then
return
end

local HttpService = game:GetService("HttpService")

local SERVER_URL = "http://localhost:22073"
Expand Down
23 changes: 21 additions & 2 deletions rbx_reflector/src/cli/defaults_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{
fmt::{self, Write},
fs,
path::PathBuf,
process::Command,
process::{Command, Stdio},
sync::mpsc,
time::Duration,
};
Expand Down Expand Up @@ -63,6 +63,8 @@ fn save_place_in_studio(path: &PathBuf) -> anyhow::Result<StudioInfo> {
log::info!("Starting Roblox Studio...");

let mut studio_process = Command::new(studio_install.application_path())
.stdout(Stdio::null())
.stderr(Stdio::null())
.arg(path)
.spawn()?;

Expand All @@ -85,7 +87,24 @@ fn save_place_in_studio(path: &PathBuf) -> anyhow::Result<StudioInfo> {
}
}

#[cfg(not(target_os = "windows"))]
#[cfg(target_os = "macos")]
{
let process_id = studio_process.id();
let script = format!(
r#"
tell application "System Events"
set frontmost of the first process whose unix id is {process_id} to true
keystroke "s" using command down
end tell
"#
);

Command::new("osascript")
.args(["-e", script.as_str()])
.output()?;
}

#[cfg(not(any(target_os = "windows", target_os = "macos")))]
println!("Please save the opened place in Roblox Studio (ctrl+s).");

loop {
Expand Down
4 changes: 3 additions & 1 deletion rbx_reflector/src/cli/dump.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::path::PathBuf;
use std::process::Command;
use std::{path::PathBuf, process::Stdio};

use anyhow::{bail, Context};
use clap::Parser;
Expand All @@ -22,6 +22,8 @@ impl DumpSubcommand {
RobloxStudio::locate().context("Could not locate Roblox Studio install")?;

Command::new(studio_install.application_path())
.stdout(Stdio::null())
.stderr(Stdio::null())
.arg("-FullAPI")
.arg(&self.output)
.status()?;
Expand Down

0 comments on commit 8ca9250

Please sign in to comment.