feat: amek window resizable

This commit is contained in:
zhom
2026-06-14 19:25:21 +04:00
parent e5910ad5cf
commit 168b7ac6d4
68 changed files with 1257 additions and 857 deletions
+17 -1
View File
@@ -1853,6 +1853,7 @@ dependencies = [
"tauri-plugin-opener",
"tauri-plugin-shell",
"tauri-plugin-single-instance",
"tauri-plugin-window-state",
"tempfile",
"thiserror 2.0.18",
"tokio",
@@ -3089,7 +3090,7 @@ dependencies = [
"js-sys",
"log",
"wasm-bindgen",
"windows-core 0.61.2",
"windows-core 0.62.2",
]
[[package]]
@@ -6858,6 +6859,21 @@ dependencies = [
"zbus",
]
[[package]]
name = "tauri-plugin-window-state"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73736611e14142408d15353e21e3cca2f12a3cfb523ad0ce85999b6d2ef1a704"
dependencies = [
"bitflags 2.11.1",
"log",
"serde",
"serde_json",
"tauri",
"tauri-plugin",
"thiserror 2.0.18",
]
[[package]]
name = "tauri-runtime"
version = "2.11.2"
+1
View File
@@ -41,6 +41,7 @@ tauri-plugin-dialog = "2"
tauri-plugin-macos-permissions = "2"
tauri-plugin-log = "2"
tauri-plugin-clipboard-manager = "2"
tauri-plugin-window-state = "2"
log = "0.4"
env_logger = "0.11"
+52 -2
View File
@@ -150,6 +150,8 @@ use api_server::{get_api_server_status, start_api_server, stop_api_server};
pub trait WindowExt {
#[cfg(target_os = "macos")]
fn set_transparent_titlebar(&self, transparent: bool) -> Result<(), String>;
#[cfg(target_os = "macos")]
fn disable_native_fullscreen(&self) -> Result<(), String>;
}
impl<R: Runtime> WindowExt for WebviewWindow<R> {
@@ -164,7 +166,7 @@ impl<R: Runtime> WindowExt for WebviewWindow<R> {
if transparent {
// Hide the title text
ns_window.setTitleVisibility(NSWindowTitleVisibility(2)); // NSWindowTitleHidden
ns_window.setTitleVisibility(NSWindowTitleVisibility(1)); // NSWindowTitleHidden
// Make titlebar transparent
ns_window.setTitlebarAppearsTransparent(true);
@@ -189,6 +191,33 @@ impl<R: Runtime> WindowExt for WebviewWindow<R> {
Ok(())
}
#[cfg(target_os = "macos")]
fn disable_native_fullscreen(&self) -> Result<(), String> {
use objc2::rc::Retained;
use objc2_app_kit::{NSWindow, NSWindowCollectionBehavior};
unsafe {
let ns_window: Retained<NSWindow> =
Retained::retain(self.ns_window().unwrap().cast()).unwrap();
// Make the green title-bar button (and titlebar double-click) "zoom"
// the window to fill the screen as an ordinary window instead of
// entering immersive native fullscreen that hides the menu bar and
// moves to its own Space. Mirrors Electron's `fullscreenable: false`:
// clear FullScreenPrimary and set FullScreenNone. AppKit then maps the
// green button to the standard zoom, expanding to the visible screen
// frame while keeping the window chrome and the current Space.
const FULL_SCREEN_PRIMARY: usize = 1 << 7;
const FULL_SCREEN_NONE: usize = 1 << 9;
let current = ns_window.collectionBehavior();
let updated =
NSWindowCollectionBehavior((current.0 & !FULL_SCREEN_PRIMARY) | FULL_SCREEN_NONE);
ns_window.setCollectionBehavior(updated);
}
Ok(())
}
}
// Called internally for deep-link / startup URL handling — not invoked from the
@@ -1388,6 +1417,21 @@ pub fn run() {
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_macos_permissions::init())
.plugin(tauri_plugin_clipboard_manager::init())
// Persist window size/position across restarts. VISIBLE is excluded
// because the app hides to tray: restoring visibility would otherwise
// relaunch with an invisible window after quitting from the tray while
// hidden. FULLSCREEN is excluded because native fullscreen is disabled
// (the green button zooms instead) — the maximized flag captures the
// "filled screen" state, including green-button zoom on macOS.
.plugin(
tauri_plugin_window_state::Builder::default()
.with_state_flags(
tauri_plugin_window_state::StateFlags::all()
& !tauri_plugin_window_state::StateFlags::VISIBLE
& !tauri_plugin_window_state::StateFlags::FULLSCREEN,
)
.build(),
)
.setup(|app| {
// Recover ephemeral dir mappings from RAM-backed storage (tmpfs/ramdisk)
ephemeral_dirs::recover_ephemeral_dirs();
@@ -1403,7 +1447,8 @@ pub fn run() {
let win_builder = WebviewWindowBuilder::new(app, "main", WebviewUrl::default())
.title("Donut Browser")
.inner_size(880.0, 500.0)
.resizable(false)
.min_inner_size(640.0, 400.0)
.resizable(true)
.fullscreen(false)
.center()
.focused(true)
@@ -1447,6 +1492,11 @@ pub fn run() {
if let Err(e) = window.set_transparent_titlebar(true) {
log::warn!("Failed to set transparent titlebar: {e}");
}
// Green title-bar button maximizes (zoom) the window rather than
// entering immersive native fullscreen.
if let Err(e) = window.disable_native_fullscreen() {
log::warn!("Failed to disable native fullscreen: {e}");
}
}
// Set up deep link handler