filips123 / PWAsForFirefox

A tool to install, manage and use Progressive Web Apps (PWAs) in Mozilla Firefox
https://pwasforfirefox.filips.si
Mozilla Public License 2.0
2.31k stars 51 forks source link

Option to focus an existing instance of a web app #291

Closed filips123 closed 1 year ago

filips123 commented 1 year ago

Discussed in https://github.com/filips123/PWAsForFirefox/discussions/287

Originally posted by **ThijmenDam** February 6, 2023 Hi! I wonder if the current opening behavior of an app on macOS is intended. Right now, if I open a PWA that is already running (i.e. by double clicking the app icon or through Spotlight), a second instance of the app is opened. However, to me it would make more sense if the instance of the app that's already running would be brought to the front instead of opening a new instance. I think this is more in line with the usual behavior of macOS apps.
caph1993 commented 1 month ago

Hello. I'm in Linux and I have exactly this problem. When the app is open and I double click the app launcher a second time, a second window opens.

This is my environment:

➜  ~ 
➜  ~ firefoxpwa --version                                                                
firefoxpwa 2.12.5

➜  ~ firefox --version                                                                   
Mozilla Firefox 131.0.3

➜  ~ uname -a && lsb_release -a 2>/dev/null | grep 'Description'
Linux lat7310 6.11.5-1-default #1 SMP PREEMPT_DYNAMIC Wed Oct 23 04:27:11 UTC 2024 (b4e3aa9) x86_64 x86_64 x86_64 GNU/Linux
Description:    openSUSE Tumbleweed

As a workaround, install wmctrl, saved the following script as /usr/bin/firefoxwpa-single, give it permission to be executed and replace all the web app launchers in ~/.local/share/applications to point to /usr/bin/firefoxwpa-single instead of /usr/bin/firefoxwpa. A bit awful as a solution, but it does the job.

#!/usr/bin/python
import sys, subprocess

cmd = ["firefoxpwa"] + sys.argv[1:]

if sys.argv[1:3] == ["site", "launch"] and len(sys.argv) >= 4:
    code = sys.argv[3]
    # Check if there is an open window with the app code
    stdout = subprocess.check_output(["wmctrl", "-lx"]).decode("utf-8")
    for line in stdout.split("\n"):
        if code in line:
            cmd = ["wmctrl", "-x", "-a", code]
            break

subprocess.run(cmd)
filips123 commented 1 month ago

You can enable focusing the existing window in the app browser settings.

caph1993 commented 1 month ago

You can enable focusing the existing window in the app browser settings.

Oh, yes. I was searching everywhere in the settings of the extension, not in the browser settings inside the PWA.

Thank you, I just realized that this is also mentioned by you here.