feat: add prelaunch scripts

This commit is contained in:
2025-05-09 16:07:58 +00:00
parent 8f05a04350
commit 469ba5f574
9 changed files with 91 additions and 7 deletions

View File

@ -533,14 +533,14 @@ pub async fn clear_cache(state: State<'_, Mutex<AppData>>) -> Result<(), String>
}
#[tauri::command]
pub async fn list_platform_capabilities() -> Result<Vec<String>, ()> {
pub fn list_platform_capabilities() -> Result<Vec<String>, ()> {
log::debug!("invoke: list_platform_capabilities");
#[cfg(target_os = "windows")]
return Ok(vec!["display".to_owned(), "shortcut".to_owned(), "chunithm".to_owned()]);
return Ok(vec!["display".to_owned(), "shortcut".to_owned(), "chunithm".to_owned(), "preload-bat".to_owned()]);
#[cfg(target_os = "linux")]
return Ok(vec!["wine".to_owned()]);
return Ok(vec!["wine".to_owned(), "preload-sh".to_owned()]);
}
#[tauri::command]

View File

@ -255,6 +255,7 @@ impl Profile {
let mut game_builder;
let mut amd_builder;
let mut prelaunch = None;
let target_path = PathBuf::from(&self.data.sgt.target);
let exe_dir = target_path.parent().ok_or_else(|| anyhow!("Invalid target path"))?;
@ -264,6 +265,17 @@ impl Profile {
{
game_builder = Command::new(sgt_dir.join(self.meta.game.inject_exe()));
amd_builder = Command::new("cmd.exe");
let prelaunch_path = self.config_dir().join("prelaunch.bat");
if prelaunch_path.exists() {
let mut c = Command::new("cmd");
c.args(["/C", "start"]);
c.raw_arg("\"STARTLINER Prelaunch\"");
c.args(["cmd", "/C"]);
c.arg(prelaunch_path);
log::debug!("Prelaunch: {:?}", c);
prelaunch = Some(c.spawn()?);
}
}
#[cfg(target_os = "linux")]
{
@ -272,6 +284,14 @@ impl Profile {
game_builder.arg(sgt_dir.join(self.meta.game.inject_exe()));
amd_builder.arg("cmd.exe");
let prelaunch_path = self.config_dir().join("prelaunch.sh");
if prelaunch_path.exists() {
prelaunch_builder = Some(Command::new("sh"));
c.arg(prelaunch_path);
log::debug!("Prelaunch: {:?}", c);
prelaunch = Some(c.spawn()?);
}
}
amd_builder.env(
@ -420,6 +440,18 @@ impl Profile {
util::pkill("amdaemon.exe").await;
}
if let Some(mut _child) = prelaunch {
#[cfg(target_os = "windows")]
{
// child.kill() doesn't work
util::pkill_title("STARTLINER Prelaunch").await;
}
#[cfg(target_os = "linux")]
{
_child.start_kill()?;
}
}
set.join_next().await.expect("No spawn").expect("No result");
log::debug!("Fin");

View File

@ -105,6 +105,12 @@ pub async fn pkill(process_name: &str) {
.creation_flags(CREATE_NO_WINDOW).output().await;
}
#[cfg(target_os = "windows")]
pub async fn pkill_title(window_title: &str) {
_ = Command::new("taskkill.exe").arg("/fi").raw_arg(format!("\"WindowTitle eq {window_title}\""))
.creation_flags(CREATE_NO_WINDOW).output().await;
}
#[cfg(target_os = "linux")]
pub async fn pkill(process_name: &str) {
_ = Command::new("pkill").arg(process_name)

View File

@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "STARTLINER",
"version": "0.19.1",
"version": "0.20.0",
"identifier": "zip.patafour.startliner",
"build": {
"beforeDevCommand": "bun run dev",