first commit
This commit is contained in:
32
src-tauri/src/commands/window.rs
Normal file
32
src-tauri/src/commands/window.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use tauri::{AppHandle, Manager, WebviewWindow};
|
||||
|
||||
fn main_window(app: &AppHandle) -> Result<WebviewWindow, String> {
|
||||
app.get_webview_window("main")
|
||||
.ok_or_else(|| "Can't find main window".to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn win_minimize(app: AppHandle) -> Result<(), String> {
|
||||
main_window(&app)?
|
||||
.minimize()
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn win_toggle_maximize(app: AppHandle) -> Result<(), String> {
|
||||
let window = main_window(&app)?;
|
||||
let is_maximized = window.is_maximized().map_err(|error| error.to_string())?;
|
||||
|
||||
if is_maximized {
|
||||
window.unmaximize().map_err(|error| error.to_string())
|
||||
} else {
|
||||
window.maximize().map_err(|error| error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn win_close(app: AppHandle) -> Result<(), String> {
|
||||
main_window(&app)?
|
||||
.close()
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
Reference in New Issue
Block a user