chore: add validation for OpenTabletDriver path and improve process handling
This commit is contained in:
4 files changed
+66
-23
No files matched your search
@@ -993,10 +993,14 @@ pub async fn run_open_tablet_driver(path: String) -> Result<(), String> {
|
|||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
const DETACHED_PROCESS: u32 = 0x00000008;
|
use std::process::Stdio;
|
||||||
const CREATE_NEW_PROCESS_GROUP: u32 = 0x00000200;
|
const CREATE_NO_WINDOW: u32 = 0x08000000;
|
||||||
|
|
||||||
Command::new(&otd_path)
|
Command::new(&otd_path)
|
||||||
.creation_flags(DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP)
|
.creation_flags(CREATE_NO_WINDOW)
|
||||||
|
.stdin(Stdio::null())
|
||||||
|
.stdout(Stdio::null())
|
||||||
|
.stderr(Stdio::null())
|
||||||
.spawn()
|
.spawn()
|
||||||
.map_err(|e| format!("Failed to start OpenTabletDriver: {}", e))?;
|
.map_err(|e| format!("Failed to start OpenTabletDriver: {}", e))?;
|
||||||
}
|
}
|
||||||
@@ -1041,6 +1045,21 @@ pub fn is_open_tablet_driver_running() -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn is_open_tablet_driver_path_valid(app: AppHandle, path: String) -> bool {
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
app.fs_scope().allow_file(&path).ok();
|
||||||
|
let otd_path = PathBuf::from(&path);
|
||||||
|
otd_path.exists()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
{
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Clone)]
|
#[derive(Serialize, Clone)]
|
||||||
pub struct ExtractProgress {
|
pub struct ExtractProgress {
|
||||||
pub theme_name: String,
|
pub theme_name: String,
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ use crate::commands::{
|
|||||||
find_osu_installation, get_beatmapsets_count, get_ezpp_launcher_update_files, get_hwid,
|
find_osu_installation, get_beatmapsets_count, get_ezpp_launcher_update_files, get_hwid,
|
||||||
get_launcher_version, get_osu_release_stream, get_osu_skin, get_osu_version, get_platform,
|
get_launcher_version, get_osu_release_stream, get_osu_skin, get_osu_version, get_platform,
|
||||||
get_skins, get_skins_count, has_net8, has_osuwinello, has_wmctrl, install_ezpp_launcher_update,
|
get_skins, get_skins_count, has_net8, has_osuwinello, has_wmctrl, install_ezpp_launcher_update,
|
||||||
is_open_tablet_driver_running, is_osu_running, open_url_in_browser, opened_urls,
|
is_open_tablet_driver_path_valid, is_open_tablet_driver_running, is_osu_running,
|
||||||
presence_connect, presence_disconnect, presence_is_connected, presence_update_button,
|
open_url_in_browser, opened_urls, presence_connect, presence_disconnect, presence_is_connected,
|
||||||
presence_update_status, presence_update_user, read_theme_info, replace_ui_files,
|
presence_update_button, presence_update_status, presence_update_user, read_theme_info,
|
||||||
run_open_tablet_driver, run_osu, run_osu_updater, set_osu_config_values,
|
replace_ui_files, run_open_tablet_driver, run_osu, run_osu_updater, set_osu_config_values,
|
||||||
set_osu_user_config_values, stop_open_tablet_driver, valid_osu_folder,
|
set_osu_user_config_values, stop_open_tablet_driver, valid_osu_folder,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -123,7 +123,8 @@ pub fn run() {
|
|||||||
download_and_extract_theme,
|
download_and_extract_theme,
|
||||||
run_open_tablet_driver,
|
run_open_tablet_driver,
|
||||||
stop_open_tablet_driver,
|
stop_open_tablet_driver,
|
||||||
is_open_tablet_driver_running
|
is_open_tablet_driver_running,
|
||||||
|
is_open_tablet_driver_path_valid
|
||||||
])
|
])
|
||||||
.plugin(tauri_plugin_fs::init())
|
.plugin(tauri_plugin_fs::init())
|
||||||
.plugin(tauri_plugin_dialog::init())
|
.plugin(tauri_plugin_dialog::init())
|
||||||
|
|||||||
@@ -150,3 +150,5 @@ export const startOpenTabletDriver = async (otdDaemonPath: string) =>
|
|||||||
await invoke('run_open_tablet_driver', { path: otdDaemonPath });
|
await invoke('run_open_tablet_driver', { path: otdDaemonPath });
|
||||||
export const stopOpenTabletDriver = async () => await invoke('stop_open_tablet_driver');
|
export const stopOpenTabletDriver = async () => await invoke('stop_open_tablet_driver');
|
||||||
export const isOpenTabletDriverRunning = async () => await invoke('is_open_tablet_driver_running');
|
export const isOpenTabletDriverRunning = async () => await invoke('is_open_tablet_driver_running');
|
||||||
|
export const isOpenTabletDriverPathValid = async (path: string) =>
|
||||||
|
await invoke('is_open_tablet_driver_path_valid', { path });
|
||||||
+36
-15
@@ -65,6 +65,7 @@
|
|||||||
hasOsuWinello,
|
hasOsuWinello,
|
||||||
hasWMCTRL,
|
hasWMCTRL,
|
||||||
installUpdate,
|
installUpdate,
|
||||||
|
isOpenTabletDriverPathValid,
|
||||||
isOpenTabletDriverRunning,
|
isOpenTabletDriverRunning,
|
||||||
isOsuCorrupted,
|
isOsuCorrupted,
|
||||||
isOsuRunning,
|
isOsuRunning,
|
||||||
@@ -201,6 +202,8 @@
|
|||||||
directory: true,
|
directory: true,
|
||||||
multiple: false,
|
multiple: false,
|
||||||
title: 'Select osu! Installation Folder',
|
title: 'Select osu! Installation Folder',
|
||||||
|
canCreateDirectories: false,
|
||||||
|
defaultPath: $osuInstallationPath ?? undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof selectedPath === 'string') {
|
if (typeof selectedPath === 'string') {
|
||||||
@@ -454,6 +457,35 @@
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let otd_run = false;
|
||||||
|
if ($openTabletDriverEnabled && $openTabletDriverPath.length > 0) {
|
||||||
|
const otdRunning = await isOpenTabletDriverRunning();
|
||||||
|
if (!otdRunning) {
|
||||||
|
launchInfo = 'Starting OpenTabletDriver...';
|
||||||
|
const validDaemon = await isOpenTabletDriverPathValid($openTabletDriverPath);
|
||||||
|
if (!validDaemon) {
|
||||||
|
sileo.error({
|
||||||
|
title: 'Hmmm...',
|
||||||
|
description: 'Failed to start OpenTabletDriver, executable not found.',
|
||||||
|
});
|
||||||
|
launching.set(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await startOpenTabletDriver($openTabletDriverPath);
|
||||||
|
otd_run = true;
|
||||||
|
} catch (err) {
|
||||||
|
console.log('Failed to start OpenTabletDriver:', err);
|
||||||
|
sileo.error({
|
||||||
|
title: 'Hmmm...',
|
||||||
|
description: 'Failed to start OpenTabletDriver.',
|
||||||
|
});
|
||||||
|
launching.set(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
await new Promise((res) => setTimeout(res, 1500));
|
await new Promise((res) => setTimeout(res, 1500));
|
||||||
launchInfo = 'Launching osu!...';
|
launchInfo = 'Launching osu!...';
|
||||||
|
|
||||||
@@ -575,19 +607,6 @@
|
|||||||
}, 1000 * 2);
|
}, 1000 * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
let otd_run = false;
|
|
||||||
if ($openTabletDriverEnabled && $openTabletDriverPath.length > 0) {
|
|
||||||
const otdRunning = await isOpenTabletDriverRunning();
|
|
||||||
if (!otdRunning) {
|
|
||||||
try {
|
|
||||||
await startOpenTabletDriver($openTabletDriverPath);
|
|
||||||
otd_run = true;
|
|
||||||
} catch (err) {
|
|
||||||
console.log('Failed to start OpenTabletDriver:', err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await runOsu(osuPath, true);
|
await runOsu(osuPath, true);
|
||||||
if ($trackingEnabled) umami.track('app_exit_osu');
|
if ($trackingEnabled) umami.track('app_exit_osu');
|
||||||
cleanup = true;
|
cleanup = true;
|
||||||
@@ -795,12 +814,14 @@
|
|||||||
const selectedPath = await open({
|
const selectedPath = await open({
|
||||||
directory: false,
|
directory: false,
|
||||||
multiple: false,
|
multiple: false,
|
||||||
title: 'Select OpenTabletDriver Executable',
|
title: 'Select OpenTabletDriver.Daemon Executable',
|
||||||
|
defaultPath: $openTabletDriverPath ?? undefined,
|
||||||
|
canCreateDirectories: false,
|
||||||
filters:
|
filters:
|
||||||
$platform === 'windows'
|
$platform === 'windows'
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
name: 'OpenTabletDriver',
|
name: 'OpenTabletDriver.Daemon.exe',
|
||||||
extensions: ['exe'],
|
extensions: ['exe'],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in new issue
Block a user