tauri-apps / tray-icon

Tray icons for Desktop Applications.
Apache License 2.0
206 stars 29 forks source link

egui example doesn't work, crashes on start on macOS #28

Closed twop closed 1 year ago

twop commented 1 year ago
Assertion failed: (CGAtomicGet(&is_initialized)), function CGSConnectionByID, file CGSConnection.mm, line 422.

After looking what might have caused the error, it seems that the NSApp needs to be initialized first https://github.com/servo/core-foundation-rs/issues/176

Indeed, moving tray creation inside the run_native function fixes the crash

    eframe::run_native(
        "My egui App",
        options,
        Box::new(|_cc| {
            // moved inside the lambda
            let _tray_icon = TrayIconBuilder::new().with_icon(icon).build().unwrap();

            Box::<MyApp>::default()
        }),
    )

BUT there is no icon in sight! Note that other examples worked just fine (winit + tao)

twop commented 1 year ago

I was able to show the icon, it seems that it needs to be stored somewhere in a data structure so it won't be dropped? Will dig a little more and maybe send a PR to update the example

amrbashir commented 1 year ago

That would be appreciated, I am fine with just storing it in a Rc<RefCell<Option<TrayIcon>>>

oren0e commented 1 year ago

@amrbashir I am getting the same with the "tao" example. There are two changes that need to be made to that example: tao::event_loop::EventLoop is used instead of EventLoopBuilder and in this library TrayEvent instead of TrayIconEvent

The error:

Assertion failed: (CGAtomicGet(&is_initialized)), function CGSConnectionByID, file /System/Volumes/Data/SWE/macOS/BuildRoots/37599d3d49/Library/Caches/com.apple.xbs/Sources/SkyLight/SkyLight-588.10/SkyLight/Services/Connection/CGSConnection.mm, line 133.
[1]    19271 abort      cargo run

I run this on a Mac Big Sur (not M1)

amrbashir commented 1 year ago

@oren0e the examples have been updated with this changes days ago. If you are facing a specific issue, feel free to open another issue with more details and steps to reproduce.