forked from akanyan/STARTLINER
feat: add prelaunch scripts
This commit is contained in:
@ -1,3 +1,9 @@
|
||||
## 0.20.0
|
||||
|
||||
- Added user-customizable pre-launch scripts
|
||||
- Added japanese localization
|
||||
- Fixed the file editor not updating state properly
|
||||
|
||||
## 0.19.1
|
||||
|
||||
- Fixed the update button enabling the package
|
||||
|
@ -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]
|
||||
|
@ -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");
|
||||
|
@ -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)
|
||||
|
@ -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",
|
||||
|
@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
import { onMounted, ref } from 'vue';
|
||||
import Button from 'primevue/button';
|
||||
import * as path from '@tauri-apps/api/path';
|
||||
import { open } from '@tauri-apps/plugin-dialog';
|
||||
@ -12,6 +12,7 @@ const props = defineProps({
|
||||
filename: String,
|
||||
promptname: String,
|
||||
extension: String,
|
||||
defaultValue: String,
|
||||
});
|
||||
|
||||
const exists = ref(false);
|
||||
@ -35,6 +36,12 @@ const save = async () => {
|
||||
};
|
||||
|
||||
const filePick = async () => {
|
||||
if (props.defaultValue !== undefined) {
|
||||
contents.value = props.defaultValue;
|
||||
exists.value = true;
|
||||
await save();
|
||||
return;
|
||||
}
|
||||
const p = await open({
|
||||
multiple: false,
|
||||
directory: false,
|
||||
@ -54,13 +61,13 @@ const filePick = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
(async () => {
|
||||
onMounted(async () => {
|
||||
if (props.filename === undefined) {
|
||||
throw new Error('FileEditor without a filename');
|
||||
}
|
||||
target_path.value = await path.join(await prf.configDir, props.filename);
|
||||
await load(target_path.value);
|
||||
})();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@ -1,13 +1,27 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
import ToggleSwitch from 'primevue/toggleswitch';
|
||||
import FileEditor from '../FileEditor.vue';
|
||||
import OptionCategory from '../OptionCategory.vue';
|
||||
import OptionRow from '../OptionRow.vue';
|
||||
import { invoke } from '../../invoke';
|
||||
import { usePrfStore } from '../../stores';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const extension = ref('');
|
||||
|
||||
invoke('list_platform_capabilities').then(async (v: unknown) => {
|
||||
if (Array.isArray(v)) {
|
||||
if (v.includes('preload-sh')) {
|
||||
extension.value = 'sh';
|
||||
} else if (v.includes('preload-bat')) {
|
||||
extension.value = 'bat';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const prf = usePrfStore();
|
||||
</script>
|
||||
|
||||
@ -26,5 +40,20 @@ const prf = usePrfStore();
|
||||
<!-- <Button icon="pi pi-refresh" size="small" /> -->
|
||||
<FileEditor filename="segatools-base.ini" />
|
||||
</OptionRow>
|
||||
<OptionRow
|
||||
:title="t('cfg.misc.prelaunch')"
|
||||
:tooltip="t('cfg.misc.prelaunchTooltip')"
|
||||
>
|
||||
<FileEditor
|
||||
v-if="extension === 'bat'"
|
||||
filename="prelaunch.bat"
|
||||
:defaultValue="`@echo off\n\nREM This script will be launched alongside the game\n`"
|
||||
/>
|
||||
<FileEditor
|
||||
v-else-if="extension === 'sh'"
|
||||
filename="prelaunch.sh"
|
||||
:defaultValue="`#!/bin/sh\n\n# This script will be launched alongside the game\n`"
|
||||
/>
|
||||
</OptionRow>
|
||||
</OptionCategory>
|
||||
</template>
|
||||
|
@ -166,6 +166,8 @@ export default {
|
||||
other: 'Other segatools options',
|
||||
otherTooltip:
|
||||
'Advanced or situational options not covered by STARTLINER',
|
||||
prelaunch: 'Prelaunch script',
|
||||
prelaunchTooltip: 'Optional script that runs before the game.',
|
||||
},
|
||||
extensions: {
|
||||
title: 'Extensions',
|
||||
|
@ -206,6 +206,8 @@ export default {
|
||||
other: 'Inne opcje segatools',
|
||||
otherTooltip:
|
||||
'Zaawansowane lub sytuacyjne opcje, które nie są objęte przez STARTLINERA',
|
||||
prelaunch: 'Skrypt przedstartowy',
|
||||
prelaunchTooltip: 'Opcjonalny skrypt uruchamiany przed grą.',
|
||||
},
|
||||
extensions: {
|
||||
title: 'Rozszerzenia',
|
||||
|
Reference in New Issue
Block a user