Huakun Shen 656100cb76
refactor: remove platform-specific tauri conf
Merge windows back to main tauri config. The reason I separated them was
because I need decoration: true on mac and false on windows and linux.
Now I use tauri rust API to set decorations to false for win and linux.
2024-12-20 11:44:57 -05:00

72 lines
2.6 KiB
Rust

use tauri::{is_dev, App, AppHandle, LogicalSize, Manager, Runtime, Size, WebviewWindow, Window};
#[cfg(target_os = "macos")]
use cocoa::appkit::{NSWindow, NSWindowButton, NSWindowStyleMask, NSWindowTitleVisibility};
#[cfg(target_os = "macos")]
use objc::runtime::YES;
pub trait WindowExt {
#[cfg(target_os = "macos")]
fn set_transparent_titlebar(&self, title_transparent: bool, remove_toolbar: bool);
}
impl<R: Runtime> WindowExt for WebviewWindow<R> {
#[cfg(target_os = "macos")]
fn set_transparent_titlebar(&self, title_transparent: bool, remove_tool_bar: bool) {
use objc::{msg_send, sel, sel_impl};
unsafe {
let id = self.ns_window().unwrap() as cocoa::base::id;
NSWindow::setTitlebarAppearsTransparent_(id, cocoa::base::YES);
let mut style_mask = id.styleMask();
style_mask.set(
NSWindowStyleMask::NSFullSizeContentViewWindowMask,
title_transparent,
);
id.setStyleMask_(style_mask);
if remove_tool_bar {
let close_button = id.standardWindowButton_(NSWindowButton::NSWindowCloseButton);
let _: () = msg_send![close_button, setHidden: YES];
let min_button =
id.standardWindowButton_(NSWindowButton::NSWindowMiniaturizeButton);
let _: () = msg_send![min_button, setHidden: YES];
let zoom_button = id.standardWindowButton_(NSWindowButton::NSWindowZoomButton);
let _: () = msg_send![zoom_button, setHidden: YES];
}
id.setTitleVisibility_(if title_transparent {
NSWindowTitleVisibility::NSWindowTitleHidden
} else {
NSWindowTitleVisibility::NSWindowTitleVisible
});
id.setTitlebarAppearsTransparent_(if title_transparent {
cocoa::base::YES
} else {
cocoa::base::NO
});
}
}
}
pub fn setup_window<R: Runtime>(app: &AppHandle<R>) {
#[cfg(target_os = "macos")]
{
let main_win = app.get_webview_window("main").unwrap();
main_win.set_transparent_titlebar(true, true);
let splashscreen_win = app.get_webview_window("splashscreen").unwrap();
splashscreen_win.set_transparent_titlebar(true, true);
}
#[cfg(not(target_os = "macos"))]
{
// on linux or windows, set decorations to false
let main_win = app.get_webview_window("main").unwrap();
main_win
.set_decorations(false)
.expect("Failed to set decorations");
}
}