chore: automatically start/stop otd on osu launch/close
This commit is contained in:
@@ -985,3 +985,69 @@ pub async fn install_ezpp_launcher_update(app: AppHandle) -> Result<(), String>
|
||||
pub async fn install_ezpp_launcher_update(_app: AppHandle) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn run_open_tablet_driver(path: String) -> Result<(), String> {
|
||||
let otd_path = PathBuf::from(&path);
|
||||
if !otd_path.exists() {
|
||||
return Err(format!("OpenTabletDriver not found at: {}", path));
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
const DETACHED_PROCESS: u32 = 0x00000008;
|
||||
#[cfg(windows)]
|
||||
const CREATE_NEW_PROCESS_GROUP: u32 = 0x00000200;
|
||||
|
||||
{
|
||||
#[cfg(windows)]
|
||||
Command::new(&otd_path)
|
||||
.creation_flags(DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP)
|
||||
.spawn()
|
||||
.map_err(|e| format!("Failed to start OpenTabletDriver: {}", e))?;
|
||||
|
||||
#[cfg(not(windows))]
|
||||
Command::new(&otd_path)
|
||||
.spawn()
|
||||
.map_err(|e| format!("Failed to start OpenTabletDriver: {}", e))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn stop_open_tablet_driver(path: String) -> Result<(), String> {
|
||||
let binary_name = PathBuf::from(&path)
|
||||
.file_name()
|
||||
.and_then(|n| n.to_str())
|
||||
.ok_or("Invalid OpenTabletDriver path")?
|
||||
.to_string();
|
||||
|
||||
let mut sys = System::new_all();
|
||||
sys.refresh_processes(sysinfo::ProcessesToUpdate::All, true);
|
||||
|
||||
let process = sys.processes().values().find(|p| {
|
||||
p.name().eq_ignore_ascii_case(&binary_name)
|
||||
}).ok_or("OpenTabletDriver is not running")?;
|
||||
|
||||
process.kill();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn is_open_tablet_driver_running() -> bool {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let mut sys = System::new_all();
|
||||
sys.refresh_processes(sysinfo::ProcessesToUpdate::All, true);
|
||||
|
||||
sys.processes().values().any(|p| {
|
||||
p.name().eq_ignore_ascii_case("OpenTabletDriver.Daemon.exe")
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
true
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,9 @@ custom_theme_volume.subscribe((val) => {
|
||||
}
|
||||
});
|
||||
|
||||
export const openTabletDriverEnabled = writable<boolean>(false);
|
||||
export const openTabletDriverPath = writable<string>('');
|
||||
|
||||
export const serverPing = writable<number | undefined>(undefined);
|
||||
export const serverConnectionFails = writable(0);
|
||||
|
||||
|
||||
@@ -146,3 +146,6 @@ export const getSkins = async (folder: string) =>
|
||||
'get_skins',
|
||||
{ folder }
|
||||
);
|
||||
export const startOpenTabletDriver = async (otdDaemonPath: string) =>
|
||||
await invoke('run_open_tablet_driver', { path: otdDaemonPath });
|
||||
export const stopOpenTabletDriver = async (otdDaemonPath: string) => await invoke('stop_open_tablet_driver', { path: otdDaemonPath });
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
discordPresence,
|
||||
firstStartup,
|
||||
launcherVersion,
|
||||
openTabletDriverEnabled,
|
||||
openTabletDriverPath,
|
||||
platform,
|
||||
presenceLoading,
|
||||
setupValues,
|
||||
@@ -113,6 +115,8 @@
|
||||
const config_osu_installation_path = $userSettings.value('osu_installation_path');
|
||||
const config_discord_presence = $userSettings.value('discord_presence');
|
||||
const config_tracking_enabled = $userSettings.value('tracking_consent');
|
||||
const config_otd_enabled = $userSettings.value('otd_enabled');
|
||||
const config_otd_path = $userSettings.value('otd_path');
|
||||
|
||||
const localThemes = await getThemes();
|
||||
const last_theme = localThemes.find((t) => t.name === config_theme.get('Default'));
|
||||
@@ -131,6 +135,8 @@
|
||||
reduceAnimations.set(config_reduce_animations.get(false));
|
||||
osuInstallationPath.set(config_osu_installation_path.get(''));
|
||||
discordPresence.set(config_discord_presence.get(true));
|
||||
openTabletDriverEnabled.set(config_otd_enabled.get(false));
|
||||
openTabletDriverPath.set(config_otd_path.get(''));
|
||||
if (config_tracking_enabled.exists()) {
|
||||
trackingEnabled.set(config_tracking_enabled.get(false));
|
||||
}
|
||||
@@ -139,6 +145,7 @@
|
||||
customCursor.subscribe((val) => config_custom_cursor.set(val));
|
||||
cursorSmoothening.subscribe((val) => config_cursor_smoothening.set(val));
|
||||
reduceAnimations.subscribe((val) => config_reduce_animations.set(val));
|
||||
openTabletDriverEnabled.subscribe((val) => config_otd_enabled.set(val));
|
||||
|
||||
discordPresence.subscribe(async (val) => {
|
||||
config_discord_presence.set(val);
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
launcherVersion,
|
||||
launching,
|
||||
newVersion,
|
||||
openTabletDriverEnabled,
|
||||
openTabletDriverPath,
|
||||
osuBuild,
|
||||
osuStream,
|
||||
platform,
|
||||
@@ -112,6 +114,8 @@
|
||||
runUpdater,
|
||||
setConfigValues,
|
||||
setUserConfigValues,
|
||||
startOpenTabletDriver,
|
||||
stopOpenTabletDriver,
|
||||
} from '@/osuUtil';
|
||||
import { getCurrentWindow } from '@tauri-apps/api/window';
|
||||
import { ezppfarm } from '@/api/ezpp';
|
||||
@@ -618,11 +622,24 @@
|
||||
}, 1000 * 2);
|
||||
}
|
||||
|
||||
let otd_run = false;
|
||||
|
||||
if ($openTabletDriverEnabled && $openTabletDriverPath.length > 0) {
|
||||
try {
|
||||
await startOpenTabletDriver($openTabletDriverPath);
|
||||
otd_run = true;
|
||||
} catch (err) {
|
||||
console.log('Failed to start OpenTabletDriver:', err);
|
||||
}
|
||||
}
|
||||
|
||||
await runOsu(osuPath, true);
|
||||
if ($trackingEnabled) umami.track('app_exit_osu');
|
||||
cleanup = true;
|
||||
launchInfo = 'Cleaning up...';
|
||||
|
||||
if (otd_run) await stopOpenTabletDriver($openTabletDriverPath);
|
||||
|
||||
setCurrentTimeGlobalMedia(0);
|
||||
resumeGlobalMedia();
|
||||
fadeGlobalVolume(0, $custom_theme_volume, 2000);
|
||||
@@ -854,6 +871,48 @@
|
||||
});
|
||||
};
|
||||
|
||||
const browse_otd = async () => {
|
||||
const selectedPath = await open({
|
||||
directory: false,
|
||||
multiple: false,
|
||||
title: 'Select OpenTabletDriver Executable',
|
||||
filters:
|
||||
$platform === 'windows'
|
||||
? [
|
||||
{
|
||||
name: 'OpenTabletDriver',
|
||||
extensions: ['exe'],
|
||||
},
|
||||
]
|
||||
: undefined,
|
||||
});
|
||||
|
||||
if (typeof selectedPath === 'string') {
|
||||
const fileName = selectedPath.split(/[\\/]/).pop();
|
||||
if ($platform === 'windows' && fileName?.toLowerCase() !== 'opentabletdriver.daemon.exe') {
|
||||
sileo.error({
|
||||
title: 'Wrong executable',
|
||||
description: 'Please select OpenTabletDriver.Daemon.exe',
|
||||
fill: '#181825',
|
||||
styles: { description: 'text-center!' },
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
openTabletDriverPath.set(selectedPath);
|
||||
$userSettings.value('otd_path').set(selectedPath);
|
||||
await $userSettings.save();
|
||||
sileo.success({
|
||||
title: 'Yay!',
|
||||
description: 'OpenTabletDriver set successfully.',
|
||||
fill: '#181825',
|
||||
styles: {
|
||||
description: 'text-center!',
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
onMount(() => {
|
||||
const config = $userSettings;
|
||||
const trackingConsent = config.value('tracking_consent');
|
||||
@@ -1711,6 +1770,33 @@
|
||||
>
|
||||
</div>
|
||||
{#if $platform === 'windows'}
|
||||
<div class="flex flex-col">
|
||||
<Label class="text-sm" for="setting-otd-path">OpenTabletDriver path</Label>
|
||||
<div class="text-muted-foreground text-xs">
|
||||
Automatically start OpenTabletDriver when launching osu!.
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-row w-full">
|
||||
<div
|
||||
class="mt-4 flex items-center bg-theme-950 border border-theme-800 border-r-0 rounded-l-md px-3"
|
||||
>
|
||||
<Checkbox id="setting-otd" bind:checked={$openTabletDriverEnabled} />
|
||||
</div>
|
||||
<Input
|
||||
class="mt-4 w-full bg-theme-950 border-theme-800 border-r-0 rounded-none"
|
||||
type="text"
|
||||
value={$openTabletDriverPath}
|
||||
placeholder="Path to OpenTabletDriver.Daemon.exe"
|
||||
readonly
|
||||
disabled={!$openTabletDriverEnabled}
|
||||
/>
|
||||
<Button
|
||||
class="mt-4 bg-theme-950 border-theme-800 rounded-l-none"
|
||||
variant="outline"
|
||||
disabled={!$openTabletDriverEnabled}
|
||||
onclick={browse_otd}>Browse</Button
|
||||
>
|
||||
</div>
|
||||
<div class="flex flex-col">
|
||||
<Label class="text-sm" for="setting-custom-cursor">patcher release stream</Label>
|
||||
<div class="text-muted-foreground text-xs">
|
||||
|
||||
Reference in New Issue
Block a user