feat(macos): implement transparent titlebar with custom background color
- Add transparent titlebar configuration in tauri.conf.json - Implement macOS titlebar background color matching main UI banner (#3498db) - Replace deprecated cocoa crate with modern objc2-app-kit - Preserve native window functionality (drag, traffic lights) - Remove all deprecation warnings from build process The titlebar now seamlessly matches the application's blue theme while maintaining all native macOS window management features.
This commit is contained in:
2
src-tauri/Cargo.lock
generated
2
src-tauri/Cargo.lock
generated
@@ -96,6 +96,8 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"dirs 5.0.1",
|
||||
"log",
|
||||
"objc2 0.5.2",
|
||||
"objc2-app-kit 0.2.2",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tauri",
|
||||
|
||||
@@ -26,3 +26,7 @@ tauri-plugin-log = "2"
|
||||
tauri-plugin-shell = "2"
|
||||
tauri-plugin-opener = "2"
|
||||
dirs = "5.0"
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
objc2 = "0.5"
|
||||
objc2-app-kit = { version = "0.2", features = ["NSColor"] }
|
||||
|
||||
@@ -12,6 +12,37 @@ pub fn run() {
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.setup(|app| {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
// 设置 macOS 标题栏背景色为主界面蓝色
|
||||
if let Some(window) = app.get_webview_window("main") {
|
||||
use objc2::runtime::AnyObject;
|
||||
use objc2::rc::Retained;
|
||||
use objc2_app_kit::NSColor;
|
||||
|
||||
let ns_window_ptr = window.ns_window().unwrap();
|
||||
let ns_window: Retained<AnyObject> = unsafe {
|
||||
Retained::retain(ns_window_ptr as *mut AnyObject).unwrap()
|
||||
};
|
||||
|
||||
// 使用与主界面 banner 相同的蓝色 #3498db
|
||||
// #3498db = RGB(52, 152, 219)
|
||||
let bg_color = unsafe {
|
||||
NSColor::colorWithRed_green_blue_alpha(
|
||||
52.0/255.0, // R: 52
|
||||
152.0/255.0, // G: 152
|
||||
219.0/255.0, // B: 219
|
||||
1.0, // Alpha: 1.0
|
||||
)
|
||||
};
|
||||
|
||||
unsafe {
|
||||
use objc2::msg_send;
|
||||
let _: () = msg_send![&*ns_window, setBackgroundColor: &*bg_color];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化日志
|
||||
if cfg!(debug_assertions) {
|
||||
app.handle().plugin(
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
"minWidth": 800,
|
||||
"minHeight": 600,
|
||||
"resizable": true,
|
||||
"fullscreen": false
|
||||
"fullscreen": false,
|
||||
"titleBarStyle": "Transparent"
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
|
||||
Reference in New Issue
Block a user