Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app.setAsDefaultProtocolClient doesn’t work on Linux .AppImage #4035

Closed
brunolemos opened this issue Jul 9, 2019 · 28 comments · Fixed by #4909
Closed

app.setAsDefaultProtocolClient doesn’t work on Linux .AppImage #4035

brunolemos opened this issue Jul 9, 2019 · 28 comments · Fixed by #4909

Comments

@brunolemos
Copy link

  • electon-builder: 20.44.4 and tried 21.0.13
  • electon-updater: 4.0.14 and tried 4.1.2
  • Target: linux (.AppImage, Ubuntu)

app.setAsDefaultProtocolClient works for macOS and Windows, but not for Linux, at least when using .AppImage, which is the only one I use.

The custom protocol / schema is never registered and app.isDefaultProtocolClient will always return false.

@brunolemos
Copy link
Author

Based on what I read I believe it should add the custom schema to /usr/share/applications/defaults.list, but it’s not doing that.

@roaringUnicorn
Copy link

roaringUnicorn commented Jul 17, 2019

I ran into the same problem. I had to workaround using :
childProcess.exec('xdg-mime default myApp.desktop x-scheme-handler/myapp')

@brunolemos
Copy link
Author

brunolemos commented Jul 17, 2019

@roaringUnicorn Tried it using import childProcess from 'child_process' and executing the command, but didn’t seem to have any effect.

@brunolemos
Copy link
Author

brunolemos commented Jul 17, 2019

@roaringUnicorn do I need to do anything else? E.g. create a .desktop file? I haven’t created one but afaik electron-builder handles that.

When searching for all .desktop files in the computer it finds one with my app name:

/home/MYUSERNAME/.local/share/applications/appimagekit-MYAPPNAME.desktop

I tried alternative commands like xdg-mime default /home/MYUSERNAME/.local/share/applications/appimagekit-MYAPPNAME.desktop x-scheme-handler/MYAPPNAME but no success.

@roaringUnicorn
Copy link

You do need to add "x-scheme-handler/MyApp;" as a known mimetype in your .desktop file.

You don't need to specify the full path of your .desktop file, as ~/.local/share/applications/ is one of the default paths for them.

Desktop file are generated by electron-builder, and managed automaticaly by the OS.
You can customize it through your package.json:

"linux": {
  "desktop": {
    "MimeType": "x-scheme-handler/MyApp;" 
  }
}

The electron-builder doc might not be extremely explicit: https://www.electron.build/configuration/appimage

BTW, don't put a space in your appimage name ! There is an escaping probleme somewhere...
see: #3547

@stale
Copy link

stale bot commented Sep 16, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the backlog label Sep 16, 2019
@roaringUnicorn
Copy link

roaringUnicorn commented Sep 16, 2019

The bug is still present in [email protected] and [email protected]

@stale stale bot removed the backlog label Sep 16, 2019
@brunolemos
Copy link
Author

brunolemos commented Oct 10, 2019

@roaringUnicorn unfortunately that also didn't work for me. Probably because desktop integration was "removed in favor of AppImageLauncher". Do I need to tell the users to install this AppImageLauncher now?

I tried installing this AppImageLauncher myself (.deb) and it doesn't seem to have any effect. Linux UX is so bad, I give up for now again.

@stale
Copy link

stale bot commented Dec 9, 2019

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the backlog label Dec 9, 2019
@brunolemos
Copy link
Author

Still a problem.

@stale stale bot removed the backlog label Dec 9, 2019
@stale
Copy link

stale bot commented Feb 7, 2020

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the backlog label Feb 7, 2020
@brunolemos
Copy link
Author

🙄

@stale
Copy link

stale bot commented Apr 8, 2020

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the backlog label Apr 8, 2020
@brunolemos
Copy link
Author

.

@stale stale bot removed the backlog label Apr 8, 2020
Simon-Laux added a commit to Simon-Laux/electron-builder that referenced this issue Apr 28, 2020
@jgredecka
Copy link

@brunolemos Were you able to solve this eventually? I'm facing the same issue right now with .AppImage on Ubuntu. I was hoping the above workaround would work but it seems electron-builder is not even generating the .desktop file 😕

@brunolemos
Copy link
Author

no

@Simon-Laux
Copy link
Contributor

I will make an pr to fix it until then you can do:

sed -i "s/\"AppRun\"/\"AppRun\ %U\"/" node_modules/app-builder-lib/out/targets/AppImageTarget.js

@Simon-Laux
Copy link
Contributor

First of all app.setAsDefaultProtocolClient works only on mac and windows, for linux you need an entry in your desktop file.
So I see the following steps:

1. Mimetype/Protocol in .desktop file

Have the mimetype inside of your build configuration and validate you did the right thing by extracting the appimage (./path/to/appimage --appimage-extract) and checking the .desktop file.
see deltachat/deltachat-desktop@2e722f4#diff-b9cfc7f2cdf78a7f4b91a753d10865a2 for an example for the build configuration.
[looks like you have already done this step in https://github.com/devhubapp/devhub/blob/master/packages/desktop/package.json]

2. Install the AppImage

Make sure you have the appimage "installed"/"Integrated" so that the .desktop file is found by your OS. (on Manjaro Linux, the already installed https://github.com/TheAssassin/AppImageLauncher works fine for this. Double click the appimage and click on Integrate and Run)
-> now it should open your app when doing: xdg-open "devhub:test", but your app won't know that it was opened by this url, thats where step 3 comes into play.

3. Patch electron-builder

In the .desktop file there is an Exec key that say what should happen when executing it.
You can use variables there to pass more information to the app (see documentation).
what we need here is %U for passing the filepaths/urls that should be processed by the app to the app, which is automatically added by electron-builder, except for app images, there the `Exec``key is just overwritten by "AppRun" and the %U was forgotten to be added.
We can fix it like that:

sed -i "s/\"AppRun\"/\"AppRun\ %U\"/" node_modules/app-builder-lib/out/targets/AppImageTarget.js

For me it looks like you are still on 2 while my PR is doing step 3.

@mahnunchik
Copy link
Contributor

x-scheme-handler is added by default for now

mimeTypes.push(`x-scheme-handler/${scheme}`)

@brunolemos
Copy link
Author

brunolemos commented May 28, 2020

x-scheme-handler is added by default for now

@mahnunchik this line change of from two years

image

@mahnunchik
Copy link
Contributor

Yep! So we are waiting for PR #4909 to be merged to have it works.

@stale
Copy link

stale bot commented Jul 27, 2020

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the backlog label Jul 27, 2020
@mahnunchik
Copy link
Contributor

Is is relevant!

1 similar comment
@mahnunchik
Copy link
Contributor

Is is relevant!

@stale stale bot removed the backlog label Jul 27, 2020
@mahnunchik
Copy link
Contributor

Is is relevant!

2 similar comments
@mahnunchik
Copy link
Contributor

Is is relevant!

@mahnunchik
Copy link
Contributor

Is is relevant!

develar pushed a commit that referenced this issue Sep 22, 2020
* fix missing %U in desktop file of appimages

this should fix #4035

* fix test
adityaruplaha added a commit to Heroic-Games-Launcher/HeroicGamesLauncher that referenced this issue Apr 17, 2021
Fixes #307.

Implementation based on what I read here:
electron-userland/electron-builder#4035
electron/electron#4857

Scheme is a lot like HTTP, except that there's no domain name.
Like `heroic://launch?appName=Hazelnut`.
@berkon
Copy link
Contributor

berkon commented Feb 16, 2022

I have this issue not only with .AppImage but also with .deb packages. My workaround is as follows:

Create a file called <yourapp>.desktop in ~/.local/share/applications/ if intended for current user only, or in /usr/share/applications/ if for all users. Make sure that <yourapp> is in the path, otherwise set the whole path for Exec and Icon (below).

[Desktop Entry]
Name=<Your App>
Exec=<yourapp> %u
Icon=<yourapp>
Type=Application

Set handler for a specific protocol

execSync ( 'xdg-settings set default-url-scheme-handler <your prot name> <yourapp>.desktop' )

This creates an entry like this:

x-scheme-handler/<your prot name>=<yourapp>.desktop

in:

~/.config/mimeapps.list

of course you can create that entry manually as well.

Get handler assigned to a specific protocol

execSync ( 'xdg-settings get default-url-scheme-handler <your prot name>' ).toString().trim()

The result will be:

<yourapp>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants