From 33bd75eeee1a16c73999e2ddfc2179e29650027d Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Tue, 8 Jul 2025 08:45:28 +0200 Subject: [PATCH] test: overlay --- src-tauri/src/commands.rs | 40 ++++++++++++++++++++++++++++++++++++++- src-tauri/src/lib.rs | 6 ++++-- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 92c87d9..fd66080 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -6,6 +6,7 @@ use std::path::PathBuf; use sysinfo::System; use tauri::AppHandle; use tauri::Emitter; +use tauri::Manager; use tokio::fs; use tokio::io::AsyncWriteExt; use tokio::process::Command; @@ -638,4 +639,41 @@ pub fn exit(app: AppHandle) { #[tauri::command] pub fn get_platform() -> String { std::env::consts::OS.to_string() -} \ No newline at end of file +} + +#[tauri::command] +pub fn show_overlay(app: tauri::AppHandle) -> Result<(), String> { + if !app.webview_windows().contains_key("overlay") { + tauri::WebviewWindowBuilder::new( + &app, + "overlay", + tauri::WebviewUrl::App("/overlay".into()), + ) + .always_on_top(true) + .transparent(true) + .decorations(false) + .resizable(false) + .minimizable(false) + .fullscreen(true) + .skip_taskbar(true) + .visible(true) + .center() + .build() + .map_err(|e| e.to_string())?; + } else if let Some(overlay) = app.get_webview_window("overlay") { + overlay.show().map_err(|e| e.to_string())?; + } + + Ok(()) +} + +#[tauri::command] +pub fn hide_overlay(app: tauri::AppHandle) -> Result<(), String> { + if app.webview_windows().contains_key("overlay") + && let Some(overlay) = app.get_webview_window("overlay") + { + overlay.show().map_err(|e| e.to_string())?; + } + + Ok(()) +} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index d94b280..f1161f0 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -8,7 +8,7 @@ use crate::commands::{ get_ezpp_launcher_update_files, get_hwid, get_launcher_version, get_osu_release_stream, get_osu_skin, get_osu_version, get_skins_count, is_osu_running, open_url_in_browser, replace_ui_files, run_osu, run_osu_updater, set_osu_config_values, set_osu_user_config_values, - valid_osu_folder, get_platform + valid_osu_folder, get_platform, show_overlay, hide_overlay }; #[cfg_attr(mobile, tauri::mobile_entry_point)] @@ -46,7 +46,9 @@ pub fn run() { open_url_in_browser, get_launcher_version, exit, - get_platform + get_platform, + show_overlay, + hide_overlay ]) .plugin(tauri_plugin_fs::init()) .plugin(tauri_plugin_dialog::init())