WLBF / single-instance

A rust library for single instance application.
MIT License
34 stars 8 forks source link

[Feature Request] Activate Instance #10

Open SonnyX opened 3 years ago

SonnyX commented 3 years ago

Since both Linux and Windows now use something akin of domains, it makes me believe it should be somewhat possible to implement a function that brings the window to the foreground.

WLBF commented 3 years ago

I dont fully understand what you said brings the window to the foreground, Can you explain more detail about what you are proposing?

SonnyX commented 3 years ago

A function that if another instance exists, and if that Instance has a GUI, to bring the GUI to the foreground (in case it is minimized or hidden)

WLBF commented 3 years ago

Very interesting idea. I will do some research on this, although I probably would not add this kind of complex feature to this simple crate.

WLBF commented 3 years ago

One solution I can imagine is use unix domain socket inform another instance.

SonnyX commented 3 years ago

The same potentially with Windows named pipes, unless there is another way to get the window handle.

ottosson commented 2 years ago

I would very much love to see this feature as well. Why was it closed?

Thanks!

betamos commented 2 years ago

+1! I'm looking for single-instance in my Tauri app. When a user tries to open a new instance, it should bring focus to the existing application.

However, seeing this is a low-level utility (you wouldn't even need a GUI app at all) it wouldn't make sense to try to foreground an application from this crate. However, what would work is if the existing instance got a notification that another instance has been requested, perhaps as a receiving channel + canceler API. This would be sufficient to pipe through the request and do the appropriate thing.

Note that this would have tremendous value even if it wasn't supported on all platforms. For instance, MacOS already has deduplication so it's never a problem in practice (afaik). Windows is certainly the most useful one, probably followed by Linux.

Please consider reopening this.

nu11ptr commented 1 year ago

A potential workaround until this feature is added: what is really needed is a "platform independent IPC". It looks like there is a crate that does this: interprocess. My plan is to use this crate plus that one (haven't tried yet, but seems like it should work). At that point, the first process could take any action needed in a GUI independent manner once notified including restoring a GUI window, etc.

Hellager commented 1 year ago

+1! I'm looking for single-instance in my Tauri app. When a user tries to open a new instance, it should bring focus to the existing application.

However, seeing this is a low-level utility (you wouldn't even need a GUI app at all) it wouldn't make sense to try to foreground an application from this crate. However, what would work is if the existing instance got a notification that another instance has been requested, perhaps as a receiving channel + canceler API. This would be sufficient to pipe through the request and do the appropriate thing.

Note that this would have tremendous value even if it wasn't supported on all platforms. For instance, MacOS already has deduplication so it's never a problem in practice (afaik). Windows is certainly the most useful one, probably followed by Linux.

Please consider reopening this.

Hi there, i wonder have you already tried using this crate in your app? I'm trying add this to my tauri app, it works well in pure rust, but seems to be not working in tauri. I tried like this

#[tauri::command]
fn check_instance() -> bool {
    let instance = SingleInstance::new("tauri-app").unwrap();
    println!("check instance whether single {}", instance.is_single());

    instance.is_single()
}