[single-instance] Callback function does not run if the app is not visible (after calling window.hide())
Hi,
I've discovered that the single instance callback function after initialization doesn't work when the app is not visible (I call window.hide() function). What I want to do is to show the app again when another instance is opened by using window.show(). Running window.miniminize() makes the single instance work but I'm hoping to use the hide() function. I also tried the one from the v2 docs about focusing on the new instances and it also does not work. Please help, thank you! 🙏
Thank you for the report, which OS did you test this on?
I'm using MacOS
I have the same issue. Is there anything progress?
@FabianLars Is this issue going on? Or do you have any plans?
i assume you're also on macos? This issue is actually unrelated to the single-instance plugin.
macOS has a built-in single-instance mechanism so for 99% of (macOS) apps this plugin doesn't provide any value. So the title should be more like "Callback function does not run on macOS". See https://github.com/tauri-apps/plugins-workspace/issues/287 for an example use-case for the plugin on macOS and the reason why we added macOS support to the plugin even if almost nobody needs it.
In theory you're looking for a way to handle the OS' applicationShouldHandleReopen event via https://docs.rs/tauri/2.0.0/x86_64-apple-darwin/tauri/enum.RunEvent.html#variant.Reopen but you could also use app.hide() instead of window.hide() for now which will automatically show your window(s) again if needed.
@FabianLars Thanks for the clarification. I was running into the exact same issue. I am building a tray app, which should open up a window, once the app is started again.
Interestingly this worked when running in dev mode, but once I build a release, the callback .plugin(tauri_plugin_single_instance::init(|_app, _args, _cwd| {}) is not called anymore. Do you know, why it behaves differently and how I can accomplish to open up a window, once it is opened again?
As long as your (built) app is running macOS' single instance mechanism takes over, whether or not you have windows open. This means you'll also have to handle the Reopen event linked in my last message and the single-instance plugin will not trigger.
@FabianLars
Thanks - that makes sense. I am going to use tauri_plugin_single_instance::init for windows and .run(|app, event| match event { RunEvent::Reopen { .. } => for MacOS.
The only confusing part to me was, that the Reopen is not called in dev mode. Do you know why?
deep links and the single instance mechanism on macos only really work in actual app bundles, so they only fully work if you run the myapp.app (which tauri dev does not do)