schlagmichdoch / PairDrop

PairDrop: Transfer Files Cross-Platform. No Setup, No Signup.
https://pairdrop.net
GNU General Public License v3.0
4.66k stars 258 forks source link

[feature request] Using PairDrop from commandline uses existing tab instead of opening a new one everytime #42

Closed schlagmichdoch closed 1 year ago

schlagmichdoch commented 1 year ago

The only thing, what happens... every time using pairdrop from commandline, opens a new tab in firefox.

I run pairdrop from debian bullseye with firefox 102.8.0esr (64-Bit)

I don't know, if there is a possibility to reuse existing tab/window with this url, and only create a new one, if no pairdrop-tab/window exists.

Originally posted by @xundeenergie in https://github.com/schlagmichdoch/PairDrop/issues/39#issuecomment-1439890973

This is a more general problem so I moved it to this issue to be discussed.

I like the idea of being able to reuse open tabs instead of opening another one, it should however still be possible to open PairDrop in multiple tabs. There is a draft for focusing existing instances for PWAs using manifest.json:

    "launch_handler": {
        "client_mode": "focus-existing"
    }

This is not implemented in many browsers and only works if the PWA is installed on the device with the default browser: https://developer.mozilla.org/en-US/docs/Web/Manifest/launch_handler#browser_compatibility Opening urls in existing tabs is not per se possible

So I think about letting the tabs communicate to each other to find out whether another tab is already open and if yes, load the url there and close the new tab.

Tabs are indeed able to communicate with each other using a modern API: https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API

Possible Workflow:

  1. (pairdrop-cli is used with a additional flag like --use-existing-tab / -u)
  2. A new PairDrop tab tab_A is opened with a specific argument like ?focus_existing=true
  3. tab_A broadcasts its url (without the fucus_existing argument"). The broadcast is received by all tabs of the same domain.
  4. If another tab tab_B is open and not busy it:
    1. broadcasts that it overtakes the url
    2. loads the specified url
    3. changes the favicon and creates a notification that opens the tab if clicked
  5. To prevent multiple tabs from overtaking the url, if a third tab tab_C receives the overtake message, it will stop overtaking the url itself
  6. If tab_A receives the overtake message it will close itself using window.close()

@xundenergie Do you think this would be sensible?

xundeenergie commented 1 year ago

I've played around a bit with the snapdrop browserplugin... which i configured to use my pairdrop-server. I can receive files and text, send text, but not send files... in popup-mode.

So i found out, that it could open in sidebar. This looks like this: grafik

So i think, this could also be a good idea. But i've no idea, how to manage this. It's Firefox esr from debian 102.8

schlagmichdoch commented 1 year ago

Awesome that the extension works with PaiDrop. I will add it to the FAQ. However, there is no setting to open new tabs with the extension yet, is it?

xundeenergie commented 1 year ago

Awesome that the extension works with PaiDrop. I will add it to the FAQ. However, there is no setting to open new tabs with the extension yet, is it?

For sure. I can choose, to open in popup, new tab or sidebar. 😊

Popup does not work correctly. When i choose a file from filechooser, the connection closes. But sidebar works perfectly. And it's enough for me.

xundeenergie commented 1 year ago

You use xdg-open. Sorry, i don't know, how to parametrize the call, to open a website in Sidebar from there...

schlagmichdoch commented 1 year ago

After some consideration I think this overcomplicates things and is unintuitive for new users. I'll therefore close this issue.

xundeenergie commented 1 year ago

It's ok :)

schlagmichdoch commented 6 months ago

The following comments were deleted by GitHub (via hubot) as part of mistakenly marking this account as spam on 17th February 2024. The correct thread order and the creation date is unclear. I decided to manually restore them anyway in order to complete the information this issue holds even though the restored information might be outdated:

Comment by @schlagmichdoch:

I got that, but do new instances also open in the sidebar if launched via pairdrop-cli?