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
|
## 0.19.1
|
||||||
|
|
||||||
- Fixed the update button enabling the package
|
- Fixed the update button enabling the package
|
||||||
|
@ -533,14 +533,14 @@ pub async fn clear_cache(state: State<'_, Mutex<AppData>>) -> Result<(), String>
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[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");
|
log::debug!("invoke: list_platform_capabilities");
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[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")]
|
#[cfg(target_os = "linux")]
|
||||||
return Ok(vec!["wine".to_owned()]);
|
return Ok(vec!["wine".to_owned(), "preload-sh".to_owned()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
|
@ -255,6 +255,7 @@ impl Profile {
|
|||||||
|
|
||||||
let mut game_builder;
|
let mut game_builder;
|
||||||
let mut amd_builder;
|
let mut amd_builder;
|
||||||
|
let mut prelaunch = None;
|
||||||
|
|
||||||
let target_path = PathBuf::from(&self.data.sgt.target);
|
let target_path = PathBuf::from(&self.data.sgt.target);
|
||||||
let exe_dir = target_path.parent().ok_or_else(|| anyhow!("Invalid target path"))?;
|
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()));
|
game_builder = Command::new(sgt_dir.join(self.meta.game.inject_exe()));
|
||||||
amd_builder = Command::new("cmd.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")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
@ -272,6 +284,14 @@ impl Profile {
|
|||||||
|
|
||||||
game_builder.arg(sgt_dir.join(self.meta.game.inject_exe()));
|
game_builder.arg(sgt_dir.join(self.meta.game.inject_exe()));
|
||||||
amd_builder.arg("cmd.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(
|
amd_builder.env(
|
||||||
@ -420,6 +440,18 @@ impl Profile {
|
|||||||
util::pkill("amdaemon.exe").await;
|
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");
|
set.join_next().await.expect("No spawn").expect("No result");
|
||||||
|
|
||||||
log::debug!("Fin");
|
log::debug!("Fin");
|
||||||
|
@ -105,6 +105,12 @@ pub async fn pkill(process_name: &str) {
|
|||||||
.creation_flags(CREATE_NO_WINDOW).output().await;
|
.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")]
|
#[cfg(target_os = "linux")]
|
||||||
pub async fn pkill(process_name: &str) {
|
pub async fn pkill(process_name: &str) {
|
||||||
_ = Command::new("pkill").arg(process_name)
|
_ = Command::new("pkill").arg(process_name)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"productName": "STARTLINER",
|
"productName": "STARTLINER",
|
||||||
"version": "0.19.1",
|
"version": "0.20.0",
|
||||||
"identifier": "zip.patafour.startliner",
|
"identifier": "zip.patafour.startliner",
|
||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": "bun run dev",
|
"beforeDevCommand": "bun run dev",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import Button from 'primevue/button';
|
import Button from 'primevue/button';
|
||||||
import * as path from '@tauri-apps/api/path';
|
import * as path from '@tauri-apps/api/path';
|
||||||
import { open } from '@tauri-apps/plugin-dialog';
|
import { open } from '@tauri-apps/plugin-dialog';
|
||||||
@ -12,6 +12,7 @@ const props = defineProps({
|
|||||||
filename: String,
|
filename: String,
|
||||||
promptname: String,
|
promptname: String,
|
||||||
extension: String,
|
extension: String,
|
||||||
|
defaultValue: String,
|
||||||
});
|
});
|
||||||
|
|
||||||
const exists = ref(false);
|
const exists = ref(false);
|
||||||
@ -35,6 +36,12 @@ const save = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const filePick = async () => {
|
const filePick = async () => {
|
||||||
|
if (props.defaultValue !== undefined) {
|
||||||
|
contents.value = props.defaultValue;
|
||||||
|
exists.value = true;
|
||||||
|
await save();
|
||||||
|
return;
|
||||||
|
}
|
||||||
const p = await open({
|
const p = await open({
|
||||||
multiple: false,
|
multiple: false,
|
||||||
directory: false,
|
directory: false,
|
||||||
@ -54,13 +61,13 @@ const filePick = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
(async () => {
|
onMounted(async () => {
|
||||||
if (props.filename === undefined) {
|
if (props.filename === undefined) {
|
||||||
throw new Error('FileEditor without a filename');
|
throw new Error('FileEditor without a filename');
|
||||||
}
|
}
|
||||||
target_path.value = await path.join(await prf.configDir, props.filename);
|
target_path.value = await path.join(await prf.configDir, props.filename);
|
||||||
await load(target_path.value);
|
await load(target_path.value);
|
||||||
})();
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -1,13 +1,27 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { ref } from 'vue';
|
||||||
import ToggleSwitch from 'primevue/toggleswitch';
|
import ToggleSwitch from 'primevue/toggleswitch';
|
||||||
import FileEditor from '../FileEditor.vue';
|
import FileEditor from '../FileEditor.vue';
|
||||||
import OptionCategory from '../OptionCategory.vue';
|
import OptionCategory from '../OptionCategory.vue';
|
||||||
import OptionRow from '../OptionRow.vue';
|
import OptionRow from '../OptionRow.vue';
|
||||||
|
import { invoke } from '../../invoke';
|
||||||
import { usePrfStore } from '../../stores';
|
import { usePrfStore } from '../../stores';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
const { t } = useI18n();
|
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();
|
const prf = usePrfStore();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -26,5 +40,20 @@ const prf = usePrfStore();
|
|||||||
<!-- <Button icon="pi pi-refresh" size="small" /> -->
|
<!-- <Button icon="pi pi-refresh" size="small" /> -->
|
||||||
<FileEditor filename="segatools-base.ini" />
|
<FileEditor filename="segatools-base.ini" />
|
||||||
</OptionRow>
|
</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>
|
</OptionCategory>
|
||||||
</template>
|
</template>
|
||||||
|
@ -166,6 +166,8 @@ export default {
|
|||||||
other: 'Other segatools options',
|
other: 'Other segatools options',
|
||||||
otherTooltip:
|
otherTooltip:
|
||||||
'Advanced or situational options not covered by STARTLINER',
|
'Advanced or situational options not covered by STARTLINER',
|
||||||
|
prelaunch: 'Prelaunch script',
|
||||||
|
prelaunchTooltip: 'Optional script that runs before the game.',
|
||||||
},
|
},
|
||||||
extensions: {
|
extensions: {
|
||||||
title: 'Extensions',
|
title: 'Extensions',
|
||||||
|
@ -206,6 +206,8 @@ export default {
|
|||||||
other: 'Inne opcje segatools',
|
other: 'Inne opcje segatools',
|
||||||
otherTooltip:
|
otherTooltip:
|
||||||
'Zaawansowane lub sytuacyjne opcje, które nie są objęte przez STARTLINERA',
|
'Zaawansowane lub sytuacyjne opcje, które nie są objęte przez STARTLINERA',
|
||||||
|
prelaunch: 'Skrypt przedstartowy',
|
||||||
|
prelaunchTooltip: 'Opcjonalny skrypt uruchamiany przed grą.',
|
||||||
},
|
},
|
||||||
extensions: {
|
extensions: {
|
||||||
title: 'Rozszerzenia',
|
title: 'Rozszerzenia',
|
||||||
|
Reference in New Issue
Block a user