115 lines
3.6 KiB
Rust
115 lines
3.6 KiB
Rust
use tauri::{AppHandle, Manager, Window, WindowBuilder, WindowUrl, Position, PhysicalPosition};
|
|
use tracing::info;
|
|
|
|
pub fn create_main_window(app: &AppHandle) -> Window {
|
|
WindowBuilder::new(
|
|
app,
|
|
"main",
|
|
WindowUrl::App("/".into())
|
|
)
|
|
.title("EU-Utility")
|
|
.inner_size(1200.0, 800.0)
|
|
.min_inner_size(900.0, 600.0)
|
|
.center()
|
|
.build()
|
|
.expect("Failed to create main window")
|
|
}
|
|
|
|
pub fn setup_main_window(window: &Window) {
|
|
info!("Main window setup complete");
|
|
}
|
|
|
|
pub fn create_overlay_window(app: &AppHandle) {
|
|
// Get primary monitor size
|
|
let monitor = app.primary_monitor().unwrap();
|
|
let monitor_size = monitor.as_ref().map(|m| m.size()).unwrap_or_else(|| tauri::PhysicalSize::new(1920, 1080));
|
|
|
|
// Position overlay at bottom center like Windows Start Menu
|
|
let window_width = 720.0;
|
|
let window_height = 600.0; // Expanded height
|
|
let x = (monitor_size.width as f64 - window_width) / 2.0;
|
|
let y = monitor_size.height as f64 - window_height - 20.0; // 20px from bottom
|
|
|
|
let window = WindowBuilder::new(
|
|
app,
|
|
"overlay",
|
|
WindowUrl::App("/#/overlay".into())
|
|
)
|
|
.title("EU-Utility Overlay")
|
|
.inner_size(window_width, window_height)
|
|
.position(x, y)
|
|
.transparent(true)
|
|
.decorations(false)
|
|
.always_on_top(true)
|
|
.skip_taskbar(true)
|
|
.visible(false)
|
|
// Enable click-through when not focused
|
|
.focus()
|
|
.build()
|
|
.expect("Failed to create overlay window");
|
|
|
|
info!("Overlay window created at bottom center (Windows-style)");
|
|
}
|
|
|
|
pub fn toggle_overlay_window(app: &AppHandle) {
|
|
if let Some(window) = app.get_window("overlay") {
|
|
let is_visible = window.is_visible().unwrap_or(false);
|
|
|
|
if is_visible {
|
|
window.hide().ok();
|
|
// Re-enable click-through
|
|
enable_click_through(&window, true);
|
|
} else {
|
|
window.show().ok();
|
|
window.set_always_on_top(true).ok();
|
|
window.set_focus().ok();
|
|
// Disable click-through when active
|
|
enable_click_through(&window, false);
|
|
}
|
|
} else {
|
|
create_overlay_window(app);
|
|
if let Some(window) = app.get_window("overlay") {
|
|
window.show().ok();
|
|
enable_click_through(&window, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
fn enable_click_through(window: &Window, enable: bool) {
|
|
#[cfg(target_os = "windows")]
|
|
unsafe {
|
|
use windows::Win32::Foundation::HWND;
|
|
use windows::Win32::UI::WindowsAndMessaging::{SetWindowLongW, GetWindowLongW, GWL_EXSTYLE};
|
|
use windows::Win32::UI::WindowsAndMessaging::{WS_EX_LAYERED, WS_EX_TRANSPARENT, WS_EX_NOACTIVATE};
|
|
|
|
let hwnd = HWND(window.hwnd().unwrap().0 as *mut _);
|
|
let ex_style = GetWindowLongW(hwnd, GWL_EXSTYLE);
|
|
|
|
if enable {
|
|
// Enable click-through
|
|
SetWindowLongW(hwnd, GWL_EXSTYLE,
|
|
ex_style | WS_EX_LAYERED.0 as i32 | WS_EX_TRANSPARENT.0 as i32);
|
|
} else {
|
|
// Disable click-through
|
|
SetWindowLongW(hwnd, GWL_EXSTYLE,
|
|
ex_style & !(WS_EX_TRANSPARENT.0 as i32));
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn show_overlay_window(app: &AppHandle) {
|
|
if let Some(window) = app.get_window("overlay") {
|
|
window.show().ok();
|
|
window.set_always_on_top(true).ok();
|
|
window.set_focus().ok();
|
|
enable_click_through(&window, false);
|
|
}
|
|
}
|
|
|
|
pub fn hide_overlay_window(app: &AppHandle) {
|
|
if let Some(window) = app.get_window("overlay") {
|
|
window.hide().ok();
|
|
enable_click_through(&window, true);
|
|
}
|
|
}
|