tauri
tauri copied to clipboard
[bug] setLevel_ and setCollectionBehavior_ not work in fullscreen of release but work in fullscreen of dev
Describe the bug
The following code works fine in the development environment, but will not take effect after packaging.
fn main() {
tauri::Builder::default()
.setup(|app| {
let main_window = app.get_window("main").unwrap();
#[cfg(target_os = "macos")]
{
use cocoa::appkit::{NSMainMenuWindowLevel, NSWindow, NSWindowCollectionBehavior};
use cocoa::base::id;
let ns_win = main_window.ns_window().unwrap() as id;
unsafe {
ns_win.setLevel_(((NSMainMenuWindowLevel + 1) as u64).try_into().unwrap());
ns_win.setCollectionBehavior_(
NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces,
);
}
}
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
Reproduction
- yarn create tauri-app
- cd [workspace]
- yarn
- modify Cargo.toml
[target.'cfg(target_os = "macos")'.dependencies]
cocoa = "0.24.1"
- replace main fn
use tauri::Manager;
fn main() {
tauri::Builder::default()
.setup(|app| {
let main_window = app.get_window("main").unwrap();
#[cfg(target_os = "macos")]
{
use cocoa::appkit::{NSMainMenuWindowLevel, NSWindow, NSWindowCollectionBehavior};
use cocoa::base::id;
let ns_win = main_window.ns_window().unwrap() as id;
unsafe {
ns_win.setLevel_(((NSMainMenuWindowLevel + 1) as u64).try_into().unwrap());
ns_win.setCollectionBehavior_(
NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces,
);
}
}
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
- yarn tarui dev // everything is ok
- yarn tarui build // setLevel_ and setCollectionBehavior_ not work in fullscreen
Expected behavior
Apps can also be pinned to the top in full screen
Platform and versions
Environment › OS: Mac OS 13.0.0 X64 › Node.js: 16.15.1 › npm: 8.11.0 › pnpm: 7.8.0 › yarn: 1.22.19 › rustup: 1.25.1 › rustc: 1.63.0 › cargo: 1.63.0 › Rust toolchain: stable-aarch64-apple-darwin
Packages › @tauri-apps/cli [NPM]: 1.1.1 › @tauri-apps/api [NPM]: 1.1.0 › tauri [RUST]: 1.1.1, › tauri-build [RUST]: 1.1.1, › tao [RUST]: 0.14.0, › wry [RUST]: 0.21.1,
App › build-type: bundle › CSP: unset › distDir: ../dist › devPath: http://localhost:1420/ › framework: React
App directory structure ├─ dist ├─ node_modules ├─ public ├─ src-tauri ├─ .git ├─ .vscode ├─ .idea └─ src
Stack trace
No response
Additional context
No response
Is this supported now?
Maybe this can help you:
By BillGoldenWater: https://github.com/BillGoldenWater/ChaosDanmuTool/blob/dev/backend/src/utils/window_utils/macos.rs
Discord: https://discord.com/channels/616186924390023171/1113520012800577569