Hi all,
Lately I got stuck on my project (the first one too!). So I am making this application which downloads background wallpaper from Unsplash once every hour, you can check out this fancy website I made if you are interested.
I have a frontend, which allows user configuration, and I use the web-view
crate to display a window and accept user input.
So here's when the problem rises: the only usable macOS library I found is tray-item-rs
, which only allows tray icon creation on main thread. But the main thread has already been taken away by the webview UI. I have tried reversing them, creating the tray in main thread and the webview in a separate one. This however segfaults when I close the webview window.
I can't create both of them in the main thread, because as far as I know both of them invoke NSApp::run()
function, which basically locks the whole thread.
Here is my source code without tray. Any help will be appreciated! I have tried various methods, including but not limited to:
- Webview in main thread and tray icon in another (results in
ILLEGAL_HARDWARE_INSTRUCTION
) - Tray icon in main thread and webview in another (results in segfault when the webview is closed)
- Keep webview building process in main thread and start it in tray button callback using
Arc<Mutex<..>>
(could not get pass compilation, since the builder did not implementSend
; also there is this one closure in webview which captures the backgroundworker
, so I can't make it into a independent function