electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.61k stars 1.74k forks source link

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

Closed brunolemos closed 4 years ago

brunolemos commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

brunolemos commented 5 years ago

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

brunolemos commented 5 years ago

@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 commented 5 years ago

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: https://github.com/electron-userland/electron-builder/issues/3547

stale[bot] commented 5 years ago

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.

roaringUnicorn commented 5 years ago

The bug is still present in electron@6.0.9 and electron-builder@21.2.0

brunolemos commented 4 years ago

@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[bot] commented 4 years ago

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.

brunolemos commented 4 years ago

Still a problem.

stale[bot] commented 4 years ago

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.

brunolemos commented 4 years ago

🙄

stale[bot] commented 4 years ago

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.

brunolemos commented 4 years ago

.

jgredecka commented 4 years ago

@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 :confused:

brunolemos commented 4 years ago

no

Simon-Laux commented 4 years ago

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 commented 4 years ago

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 https://github.com/deltachat/deltachat-desktop/commit/2e722f4484193602a15b49c7ca1f5d8d10eff9ea#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 commented 4 years ago

x-scheme-handler is added by default for now https://github.com/electron-userland/electron-builder/blob/f938de5aae09cb832a6f7f742e64a0d6c025fb9f/packages/app-builder-lib/src/targets/LinuxTargetHelper.ts#L137

brunolemos commented 4 years ago

x-scheme-handler is added by default for now

@mahnunchik this line change of from two years

image

mahnunchik commented 4 years ago

Yep! So we are waiting for PR https://github.com/electron-userland/electron-builder/pull/4909 to be merged to have it works.

stale[bot] commented 4 years ago

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.

mahnunchik commented 4 years ago

Is is relevant!

mahnunchik commented 4 years ago

Is is relevant!

mahnunchik commented 4 years ago

Is is relevant!

mahnunchik commented 4 years ago

Is is relevant!

mahnunchik commented 4 years ago

Is is relevant!

berkon commented 2 years ago

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>