refactor(desktop): consolidate app on docked client

This commit is contained in:
2026-07-25 19:51:12 +08:00
parent 8e15c06148
commit 1e1718caee
38 changed files with 2024 additions and 7513 deletions

View File

@@ -1,26 +1,66 @@
use tauri::Window;
#[cfg(windows)]
use tauri::Manager;
#[cfg(not(windows))]
use tauri::{PhysicalPosition, PhysicalSize};
#[cfg(windows)]
mod windows_appbar;
#[tauri::command]
fn dock_window(window: Window, side: String) -> Result<(), String> {
#[cfg(windows)]
{
let hwnd = window.hwnd().map_err(|error| error.to_string())?;
return windows_appbar::set_edge(hwnd, side == "left").map_err(|error| error.to_string());
}
#[cfg(not(windows))]
{
let monitor = window
.current_monitor()
.map_err(|error| error.to_string())?
.ok_or_else(|| "Unable to identify the current monitor".to_string())?;
let window_size = window.outer_size().map_err(|error| error.to_string())?;
let work_area = monitor.work_area();
let dock_size = PhysicalSize::new(window_size.width, work_area.size.height);
let x = if side == "left" {
work_area.position.x
} else {
work_area.position.x + work_area.size.width as i32 - dock_size.width as i32
};
window
.set_size(dock_size)
.map_err(|error| error.to_string())?;
window
.set_position(PhysicalPosition::new(x, work_area.position.y))
.map_err(|error| error.to_string())?;
window
.set_always_on_top(true)
.map_err(|error| error.to_string())?;
Ok(())
}
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.setup(|app| {
#[cfg(windows)]
{
let window = app
.get_webview_window("main")
.expect("main window must be configured");
windows_appbar::register_right_edge(window.hwnd()?)?;
windows_appbar::register(window.hwnd()?)?;
}
Ok(())
})
.invoke_handler(tauri::generate_handler![dock_window])
.build(tauri::generate_context!())
.expect("failed to build SenlinAI desktop app")
.expect("failed to build SenlinAI App")
.run(|_, event| {
#[cfg(windows)]
if matches!(event, tauri::RunEvent::ExitRequested { .. }) {