feat: use native border in macos

This commit is contained in:
reya 2024-07-19 08:33:16 +07:00
parent 3b99926f3b
commit 2d987849d8
7 changed files with 103 additions and 73 deletions

23
src-tauri/Cargo.lock generated
View File

@ -606,6 +606,19 @@ dependencies = [
"piper",
]
[[package]]
name = "border"
version = "0.1.0"
source = "git+https://github.com/ahkohd/tauri-toolkit?branch=v2#8aac2f5659b036f9c269444a78e7bf15425b4bd8"
dependencies = [
"cocoa",
"color",
"objc",
"objc-foundation",
"objc_id",
"tauri",
]
[[package]]
name = "brotli"
version = "3.5.0"
@ -862,6 +875,15 @@ dependencies = [
"objc",
]
[[package]]
name = "color"
version = "0.1.0"
source = "git+https://github.com/ahkohd/tauri-toolkit?branch=v2#8aac2f5659b036f9c269444a78e7bf15425b4bd8"
dependencies = [
"cocoa",
"tauri",
]
[[package]]
name = "color_quant"
version = "1.1.0"
@ -2780,6 +2802,7 @@ dependencies = [
name = "lume"
version = "4.0.0"
dependencies = [
"border",
"cocoa",
"futures",
"keyring",

View File

@ -53,6 +53,7 @@ objc = "0.2.7"
rand = "0.8.5"
monitor = { git = "https://github.com/ahkohd/tauri-toolkit", branch = "v2" }
tauri-nspanel = { git = "https://github.com/ahkohd/tauri-nspanel", branch = "v2" }
border = { git = "https://github.com/ahkohd/tauri-toolkit", branch = "v2" }
[profile.release]
codegen-units = 1

View File

@ -1,6 +1,8 @@
use std::path::PathBuf;
use std::str::FromStr;
#[cfg(target_os = "macos")]
use border::WebviewWindowExt as BorderWebviewWindowExt;
#[cfg(target_os = "macos")]
use cocoa::{appkit::NSApp, base::nil, foundation::NSString};
use serde::{Deserialize, Serialize};
@ -180,6 +182,7 @@ pub fn open_window(window: Window, app_handle: tauri::AppHandle) -> Result<(), S
.title_bar_style(TitleBarStyle::Overlay)
.minimizable(window.minimizable)
.maximizable(window.maximizable)
.transparent(true)
.effects(WindowEffectsConfig {
state: None,
effects: vec![Effect::UnderWindowBackground],
@ -226,9 +229,9 @@ pub fn open_window(window: Window, app_handle: tauri::AppHandle) -> Result<(), S
// Set decoration
window.create_overlay_titlebar().unwrap();
// Make main window transparent
// Restore native border
#[cfg(target_os = "macos")]
window.make_transparent().unwrap();
window.add_border(None);
}
Ok(())
@ -250,9 +253,9 @@ pub fn open_main_window(app: tauri::AppHandle) {
.build()
.unwrap();
// Make main window transparent
// Restore native border
#[cfg(target_os = "macos")]
window.make_transparent().unwrap();
window.add_border(None);
}
}

View File

@ -9,6 +9,8 @@ extern crate cocoa;
#[macro_use]
extern crate objc;
#[cfg(target_os = "macos")]
use border::WebviewWindowExt as BorderWebviewWindowExt;
use nostr_sdk::prelude::*;
use serde::{Deserialize, Serialize};
use specta::Type;
@ -150,9 +152,9 @@ fn main() {
#[cfg(target_os = "windows")]
main_window.create_overlay_titlebar().unwrap();
// Make main window transparent
// Restore native border
#[cfg(target_os = "macos")]
main_window.make_transparent().unwrap();
main_window.add_border(None);
// Set a custom inset to the traffic lights
#[cfg(target_os = "macos")]

View File

@ -17,6 +17,7 @@
"minWidth": 480,
"minHeight": 760,
"hiddenTitle": true,
"transparent": true,
"windowEffects": {
"state": "followsWindowActiveState",
"effects": [