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

Deeplink is not working on Linux/Ubuntu #20

Closed
vijaygodhasara opened this issue Oct 20, 2020 · 17 comments · Fixed by #34
Closed

Deeplink is not working on Linux/Ubuntu #20

vijaygodhasara opened this issue Oct 20, 2020 · 17 comments · Fixed by #34
Labels

Comments

@vijaygodhasara
Copy link

Deeplink is not working on Linux/Ubuntu.

Installed and integrated plugin into our electron project.
open on chrome with :
Open app

getting below error
linux_deeplink_issue

@glawson
Copy link
Owner

glawson commented Oct 20, 2020

@vijaygodhasara I'm not sure if electron is even supporting this on Linux - the doc is not very clear. Only mentions Windows and MacOS - https://www.electronjs.org/docs/api/app#appsetasdefaultprotocolclientprotocol-path-args

@glawson
Copy link
Owner

glawson commented Oct 24, 2020

@vijaygodhasara - it should work on Linux, I'll debug it in the next couple of days.

@vijaygodhasara
Copy link
Author

Thanks, Once done let me know so I can check also this stuff on Linux/ubuntu as well.

@glawson
Copy link
Owner

glawson commented Oct 31, 2020

@vijaygodhasara - sorry it's taken so long. I did find the error and will have a fix out soon (I expect tomorrow).

@cedriking
Copy link

@vijaygodhasara - sorry it's taken so long. I did find the error and will have a fix out soon (I expect tomorrow).

Is this now solved? The issue is still marked as open and no replies after this one. Thanks.

@glawson
Copy link
Owner

glawson commented Dec 23, 2020

@cedriking - unfortunately not. There are some mixed issues regarding app.setAsDefaultProtocolClient on Linux. I tested on Linux and was never able to get it working. I also posted to the electron slack group, never got a response. I'll dig deeper and respond back.

@yeefun
Copy link

yeefun commented Oct 17, 2021

I try this, and it works.
https://stackoverflow.com/a/66366790

The point is:

    desktop:                            # Define desktop elem
        exec: myapp %u                  # Define Exec

@glawson
Copy link
Owner

glawson commented Oct 17, 2021

Thanks @yeefun - I'll see if we can incorporate.

@yeefun
Copy link

yeefun commented Oct 19, 2021

Sorry, I found it doesn't work in every Linux platform.

@glawson
Copy link
Owner

glawson commented Oct 19, 2021

@yeefun - thanks for letting me know.

@Joelkang
Copy link
Contributor

Joelkang commented Oct 19, 2021

I think this is where the bug lies:

if (os.platform() === 'win32') {
this.emit('received', argv.slice(-1).join(''));
}
if (this.mainWindow) {
if (this.mainWindow.isMinimized()) {
this.mainWindow.restore();
}
this.mainWindow.focus();
}

Because open-url and open-file are MacOS only, linux is missing the emit('received') call that windows has. What I wound up having to do to get around this was essentially re-implementing some parts of this library:

if (!gotTheLock) {
  app.quit();
} else {
  const onDeepLink = (link) => {...};
  app.on('second-instance', (_event: Event, args: string[]) => {
    if (['darwin','win32'].includes(process.platform)) return; // This is properly handled by electron-deep-link
    const [_executable, link] = args;
    onDeepLink(link);
  });
  ...
  deepLink = new Deeplink({
    app,
    mainWindow,
    protocol: 'myApp',
  });
  deepLink.on('received', onDeepLink);
}

As a side note, it feels a bit like a leaky abstraction to pass in the MainWindow at all--in particular, I have several windows that I show and hide based on whether the user is logged in (and what deep link is called). So it's not always the case that that the mainWindow should be open on a 2nd instance, or when a deeplink is called. Since callers already receive the received event (this bug not withstanding), they can call within that listener this portion if they wish to focus their main window:

if (this.mainWindow.isMinimized()) { 
    this.mainWindow.restore(); 
} 
this.mainWindow.focus(); 

That said, this is a breaking change, and not really related to this issue, so feel free to ignore.

@glawson happy to throw up a PR to fix this if you'd like!

@glawson
Copy link
Owner

glawson commented Oct 19, 2021

@Joelkang - that would be awesome!

@yeefun
Copy link

yeefun commented Oct 20, 2021

#20 (comment)

@Joelkang - I wonder if you test it on Linux and it works?

@Joelkang
Copy link
Contributor

@yeefun yep, I did. In addition to the changes I made above, I had to make this additional change to my Electron Forge config:

 {
      name: '@electron-forge/maker-deb',
      config: {
        options: {
          // existing options ...
          mimeType: ['x-scheme-handler/myApp'], // I added this
        },
      },
    },

@yeefun
Copy link

yeefun commented Oct 20, 2021

@Joelkang - I also did this, but it didn't work in every Linux platform. (BTW, I use electron-builder.)

what your Desktop Entry looks like?

Joelkang added a commit to dala-ai/electron-deeplink that referenced this issue Oct 20, 2021
Joelkang added a commit to dala-ai/electron-deeplink that referenced this issue Oct 20, 2021
Because the `open-url` and `open-file` events are macOS only,
we still need to rely on the second-instance event handler for
linux (in addition to win32).

Fixes glawson#20
Joelkang added a commit to dala-ai/electron-deeplink that referenced this issue Oct 20, 2021
Because the `open-url` and `open-file` events are macOS only,
we still need to rely on the second-instance event handler for
linux (in addition to win32).

Fixes glawson#20
Joelkang added a commit to dala-ai/electron-deeplink that referenced this issue Oct 20, 2021
Because the `open-url` and `open-file` events are macOS only,
we still need to rely on the second-instance event handler for
linux (in addition to win32).

Fixes glawson#20
Joelkang added a commit to dala-ai/electron-deeplink that referenced this issue Oct 20, 2021
Because the `open-url` and `open-file` events are macOS only,
we still need to rely on the second-instance event handler for
linux (in addition to win32).

Fixes glawson#20
@Joelkang
Copy link
Contributor

Joelkang commented Oct 20, 2021

@glawson: Whenever you're ready! (Woops sorry should've checked first before forcepushing so many times.)

@yeefun unfortunately I'm not trying to fix this for all linuxes--as long as it works on ubuntu, i'm good (though it doesn't seem like it shouldn't work on any other flavour).

Here's the desktop file generated from electron-forge:

Name=Dala
Comment=Dala description
GenericName=Dala
Exec=dala %U
Icon=dala
Type=Application
StartupNotify=true
Categories=GNOME;GTK;Utility;
MimeType=x-scheme-handler/dala;

@glawson
Copy link
Owner

glawson commented Nov 11, 2021

🎉 This issue has been resolved in version 1.0.9 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

5 participants