refactor: simplify stopOpenTabletDriver, cleanup code
This commit is contained in:
1 parent
5b1e32d4eb
commit
cc4697efbc
3 files changed
+27
-40
No files matched your search
+25
-38
@@ -73,15 +73,11 @@ pub fn valid_osu_folder(folder: String) -> bool {
|
|||||||
check_folder_completeness(path, &osu_folder_files) >= 70.0
|
check_folder_completeness(path, &osu_folder_files) >= 70.0
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
#[tauri::command]
|
|
||||||
pub fn find_osu_installation() -> Option<String> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn find_osu_installation() -> Option<String> {
|
pub fn find_osu_installation() -> Option<String> {
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
use winreg::RegKey;
|
use winreg::RegKey;
|
||||||
use winreg::enums::*;
|
use winreg::enums::*;
|
||||||
|
|
||||||
@@ -128,7 +124,8 @@ pub fn find_osu_installation() -> Option<String> {
|
|||||||
let stripped = trimmed.strip_suffix(",0").unwrap_or(trimmed);
|
let stripped = trimmed.strip_suffix(",0").unwrap_or(trimmed);
|
||||||
let path = PathBuf::from(stripped.trim());
|
let path = PathBuf::from(stripped.trim());
|
||||||
if let Some(parent) = path.parent() {
|
if let Some(parent) = path.parent() {
|
||||||
let match_percentage = check_folder_completeness(parent, &osu_folder_files);
|
let match_percentage =
|
||||||
|
check_folder_completeness(parent, &osu_folder_files);
|
||||||
|
|
||||||
if match_percentage >= 70.0 {
|
if match_percentage >= 70.0 {
|
||||||
return Some(parent.to_string_lossy().into());
|
return Some(parent.to_string_lossy().into());
|
||||||
@@ -150,7 +147,8 @@ pub fn find_osu_installation() -> Option<String> {
|
|||||||
let stripped = trimmed.strip_suffix(",1").unwrap_or(trimmed);
|
let stripped = trimmed.strip_suffix(",1").unwrap_or(trimmed);
|
||||||
let path = PathBuf::from(stripped.trim());
|
let path = PathBuf::from(stripped.trim());
|
||||||
if let Some(parent) = path.parent() {
|
if let Some(parent) = path.parent() {
|
||||||
let match_percentage = check_folder_completeness(parent, &osu_folder_files);
|
let match_percentage =
|
||||||
|
check_folder_completeness(parent, &osu_folder_files);
|
||||||
|
|
||||||
if match_percentage >= 70.0 {
|
if match_percentage >= 70.0 {
|
||||||
return Some(parent.to_string_lossy().into());
|
return Some(parent.to_string_lossy().into());
|
||||||
@@ -160,6 +158,7 @@ pub fn find_osu_installation() -> Option<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -881,7 +880,7 @@ pub struct PresenceButton {
|
|||||||
pub async fn presence_update_button(button: PresenceButton) {
|
pub async fn presence_update_button(button: PresenceButton) {
|
||||||
match (button.text.as_deref(), button.url.as_deref()) {
|
match (button.text.as_deref(), button.url.as_deref()) {
|
||||||
(Some(text), Some(url)) => presence::set_button(text, url),
|
(Some(text), Some(url)) => presence::set_button(text, url),
|
||||||
_ =>presence::clear_button()
|
_ => presence::clear_button(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -956,6 +955,8 @@ pub async fn download_ezpp_launcher_update(app: AppHandle, url: String) -> Resul
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn install_ezpp_launcher_update(app: AppHandle) -> Result<(), String> {
|
pub async fn install_ezpp_launcher_update(app: AppHandle) -> Result<(), String> {
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
let temp_dir = app.path().temp_dir().expect("Failed to get temp directory");
|
let temp_dir = app.path().temp_dir().expect("Failed to get temp directory");
|
||||||
let file_path = temp_dir.join("ezpplauncher_update.exe");
|
let file_path = temp_dir.join("ezpplauncher_update.exe");
|
||||||
if !file_path.exists() {
|
if !file_path.exists() {
|
||||||
@@ -976,16 +977,11 @@ pub async fn install_ezpp_launcher_update(app: AppHandle) -> Result<(), String>
|
|||||||
sleep(Duration::from_millis(250)).await;
|
sleep(Duration::from_millis(250)).await;
|
||||||
|
|
||||||
app.exit(0x0100);
|
app.exit(0x0100);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
#[tauri::command]
|
|
||||||
pub async fn install_ezpp_launcher_update(_app: AppHandle) -> Result<(), String> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn run_open_tablet_driver(path: String) -> Result<(), String> {
|
pub async fn run_open_tablet_driver(path: String) -> Result<(), String> {
|
||||||
let otd_path = PathBuf::from(&path);
|
let otd_path = PathBuf::from(&path);
|
||||||
@@ -994,42 +990,33 @@ pub async fn run_open_tablet_driver(path: String) -> Result<(), String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
const DETACHED_PROCESS: u32 = 0x00000008;
|
|
||||||
#[cfg(windows)]
|
|
||||||
const CREATE_NEW_PROCESS_GROUP: u32 = 0x00000200;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
#[cfg(windows)]
|
const DETACHED_PROCESS: u32 = 0x00000008;
|
||||||
|
const CREATE_NEW_PROCESS_GROUP: u32 = 0x00000200;
|
||||||
Command::new(&otd_path)
|
Command::new(&otd_path)
|
||||||
.creation_flags(DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP)
|
.creation_flags(DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP)
|
||||||
.spawn()
|
.spawn()
|
||||||
.map_err(|e| format!("Failed to start OpenTabletDriver: {}", e))?;
|
.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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn stop_open_tablet_driver(path: String) -> Result<(), String> {
|
pub async fn stop_open_tablet_driver() -> Result<(), String> {
|
||||||
let binary_name = PathBuf::from(&path)
|
#[cfg(windows)]
|
||||||
.file_name()
|
{
|
||||||
.and_then(|n| n.to_str())
|
|
||||||
.ok_or("Invalid OpenTabletDriver path")?
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let mut sys = System::new_all();
|
let mut sys = System::new_all();
|
||||||
sys.refresh_processes(sysinfo::ProcessesToUpdate::All, true);
|
sys.refresh_processes(sysinfo::ProcessesToUpdate::All, true);
|
||||||
|
|
||||||
let process = sys.processes().values().find(|p| {
|
let process = sys
|
||||||
p.name().eq_ignore_ascii_case(&binary_name)
|
.processes()
|
||||||
}).ok_or("OpenTabletDriver is not running")?;
|
.values()
|
||||||
|
.find(|p| p.name().eq_ignore_ascii_case("OpenTabletDriver.Daemon.exe"))
|
||||||
|
.ok_or("OpenTabletDriver is not running")?;
|
||||||
|
|
||||||
process.kill();
|
process.kill();
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -1041,9 +1028,9 @@ pub fn is_open_tablet_driver_running() -> bool {
|
|||||||
let mut sys = System::new_all();
|
let mut sys = System::new_all();
|
||||||
sys.refresh_processes(sysinfo::ProcessesToUpdate::All, true);
|
sys.refresh_processes(sysinfo::ProcessesToUpdate::All, true);
|
||||||
|
|
||||||
sys.processes().values().any(|p| {
|
sys.processes()
|
||||||
p.name().eq_ignore_ascii_case("OpenTabletDriver.Daemon.exe")
|
.values()
|
||||||
})
|
.any(|p| p.name().eq_ignore_ascii_case("OpenTabletDriver.Daemon.exe"))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
|
|||||||
+1
-1
@@ -148,4 +148,4 @@ export const getSkins = async (folder: string) =>
|
|||||||
);
|
);
|
||||||
export const startOpenTabletDriver = async (otdDaemonPath: string) =>
|
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 (otdDaemonPath: string) => await invoke('stop_open_tablet_driver', { path: otdDaemonPath });
|
export const stopOpenTabletDriver = async () => await invoke('stop_open_tablet_driver');
|
||||||
@@ -638,7 +638,7 @@
|
|||||||
cleanup = true;
|
cleanup = true;
|
||||||
launchInfo = 'Cleaning up...';
|
launchInfo = 'Cleaning up...';
|
||||||
|
|
||||||
if (otd_run) await stopOpenTabletDriver($openTabletDriverPath);
|
if (otd_run) await stopOpenTabletDriver();
|
||||||
|
|
||||||
setCurrentTimeGlobalMedia(0);
|
setCurrentTimeGlobalMedia(0);
|
||||||
resumeGlobalMedia();
|
resumeGlobalMedia();
|
||||||
|
|||||||
Reference in new issue
Block a user