tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[bug] setLevel_ and setCollectionBehavior_ not work in fullscreen of release but work in fullscreen of dev

Open Sneaken opened this issue 3 years ago • 4 comments
trafficstars

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

  1. yarn create tauri-app
  2. cd [workspace]
  3. yarn
  4. modify Cargo.toml
[target.'cfg(target_os = "macos")'.dependencies]
cocoa = "0.24.1"
  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");
}
  1. yarn tarui dev // everything is ok
  2. 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

Sneaken avatar Nov 07 '22 15:11 Sneaken

Is this supported now?

CcSimple avatar Mar 13 '23 07:03 CcSimple

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

Jinghao1209 avatar Jun 01 '23 08:06 Jinghao1209