nwjs / nw.js

Call all Node.js modules directly from DOM/WebWorker and enable a new way of writing applications with all Web technologies.
https://nwjs.io
MIT License
40.29k stars 3.88k forks source link

Feature request: API for registering node-webkit applications as protocol handlers [$50] #951

Open Mithgol opened 11 years ago

Mithgol commented 11 years ago

Something like navigator.registerProtocolHandler(), but for node-webkit's applications.

The expected result is that the application is registered as a system-wide handler for the given protocol, i.e. is launched from the command line by the following:

Bonus feature request: an API to check if an application is already registered as a handler for the given protocol.

There is a $50 open bounty on this issue. Add to the bounty at Bountysource.

morsdyce commented 11 years ago

+1 I would very much like that feature as well.

ajmas commented 11 years ago

For MacOS X you can already do this, statically, just modifying the info.plist in your customised node-webkit app:

http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html

The page describes the iPhone, but this works on the Mac as well. For an example, take a look at /Applications/Utilities/Terminal.app/Contents/Info.plist

Is this an acceptable solution on the Mac side? Do we need something more dynamic? Does anyone know if other operating system offer an equivalent approach?

Just did a bit more reading:

morsdyce commented 11 years ago

I think this way passing data to your application won't be possible without node-webkit changes to accept them and forward them to your application which is the true power of those urls

sindresorhus commented 11 years ago

:+1:

ajmas commented 11 years ago

For the moment a solution could be provided to people who want to take node-webkit and 'rebrand' for easier distribution of their solution. I am going to explain this from a Mac perspective, since that's what I have in front of me, in terms of documentation:

At the very least this would offer a prototype for future work? It may be worth starting this as a general node package module and then making a node-webkit specific version once the other issues have been worked out?

perqa commented 10 years ago

This sounds very interesting and useful, but as some of you already pointed out, you want to be able to pass in variables in those URLs. Has anything more happened since this thread was last active?

verysimplenick commented 10 years ago

protocol handlers very very useful in html5 apps. I want this feature

shokurov commented 10 years ago

This can be done with the following in /src/browser/app_controller_mac.mm


-(void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
    NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
    [appleEventManager setEventHandler:self
                           andSelector:@selector(handleGetURLEvent:withReplyEvent:)
                         forEventClass:kInternetEventClass andEventID:kAEGetURL];
}

- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
  NSString *url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];

  if (content::Shell::windows().size() == 0) {
    CommandLine::ForCurrentProcess()->AppendArg([url UTF8String]);
    CommandLine::ForCurrentProcess()->FixOrigArgv4Finder([url UTF8String]);
    return;
  }

  // Just pick a shell and get its package.
  nw::Package* package = content::Shell::windows()[0]->GetPackage();

  if (package->self_extract()) {
    // Let the app deal with the opening event if it's a standalone app.
    nwapi::App::EmitOpenEvent([url UTF8String]);
  } else {
    // Or open a new app in the runtime mode.
  }
}
jessep commented 10 years ago

:+1:

gpetrov commented 10 years ago

@shokurov why don't you make a pull request our of this?

fish520 commented 10 years ago

If only I can redirect a path request to a DB query that returns something, with a protocol handler that accept a function, which return the content directly, without a server, in that case I can store the most commonly used script files into a sqlite DB file, and share between diffrent applications... there's more goods than I can imagine, see we are developing something like a software distribution platform, etc.

shokurov commented 10 years ago

Sorry guys, have no time to make a pull request, please do whomever has a minute

flippyhead commented 9 years ago

:+1:

tartavull commented 9 years ago

+1 Great feature

asinverse commented 9 years ago

+1

monorigabor commented 9 years ago

+1 this would be very useful!

shokurov commented 9 years ago

Mac solution is posted as pull request #2429

monorigabor commented 9 years ago

@shokurov that's great news! Thanks a lot for it!

jwerle commented 9 years ago

+1 very much needed !

gyzerok commented 9 years ago

@rogerwang is there any information about release date for this feature?

gpetrov commented 9 years ago

@rogerwang there is already a pull request for it, you just need to accept it: https://github.com/rogerwang/node-webkit/pull/1769

we really need this

auchenberg commented 9 years ago

Any update on this one?

shainegordon commented 9 years ago

is this supposed to be in v0.12.0-alpha3?

I just tested on mac, and it still seems that gui.App.argv is not populated, unlike on windows, where this works correctly

ekhaled commented 9 years ago

This feature seems to have been nuked :( See: https://github.com/nwjs/nw.js/pull/1769#issuecomment-78530514

sashahilton00 commented 9 years ago

bumping

baconbrad commented 9 years ago

Seeing how this is possible with an NPM it isn't too crazy to think someone can create a cross platform version of this NPM package. Of course I would drop edge.js and use a better method of accessing the registry to avoid needing the .NET framework.

Mithgol commented 9 years ago

Then, I guess, I'll close this issue when someone creates such a package.

baconbrad commented 9 years ago

It would be a nice feature to have. Doing a quick look on Linux and Mac instructions it seems it would only be a matter of creating or packaging some files with your app/protocol info and possibly doing some shell commands to put them in their proper places.

I don't have the time/need to make this so I am going to post the ingredients here: Windows: http://stackoverflow.com/questions/389204/how-do-i-create-my-own-url-protocol-e-g-so Mac: http://stackoverflow.com/questions/471581/how-to-map-a-custom-protocol-to-an-application-on-the-mac Linux: http://superuser.com/questions/162092/how-can-i-register-a-custom-protocol-with-xdg

alxlu commented 9 years ago

This feature seems to have been nuked :( See: #1769 (comment)

What is the latest version that still has support for this?

hesmer-ibm commented 9 years ago

I would love to have this as well. Any chance to get this in a future version ?

achwedyk commented 9 years ago

What is the latest version that still has support for this?

I've tested various versions from http://dl.nwjs.io/. These were: 0.11.6, 0.11.7-rc1, 0.11.7-rc2, 0.12.0-alpha3 and 0.12.0-rc1 - none of them had this functionality working.

renarsvilnis commented 9 years ago

I think it's more of a build tool / packager issue. Each build tool does these processes different.

Experiment Just took nw-boilerplate and added CFBundleURLTypes key to the nw-boilerplate/blob/master/resources/osx/Info.plist file as described in baconface #102505353 comment url for adding custom protocols for mac. Compiled the app for Mac and it worked. Safari redirected to my app.

Further As i use nw-builder for building my nw apps, thinking of making a pull request of integrating this as a passable option. For now only for Mac.

Windows Need to look into how to add registry keys within .nsi files. Something like this

Issues But if we are binding custom protocols, we should unbind them when uninstalling the app or update them when updating the app.

Just deleted my previously compiled and installed app. Still have the protocol bindings in OS, although the behaviour is the same as before adding the custom protocol. Should look into whether how to remove them.

Note: used this to check protocols /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -dump|egrep "(bindings.*\:$)"|sort

achwedyk commented 9 years ago

@renarsvilnis you say

Compiled the app for Mac and it worked. Safari redirected to my app.

But the real problem on Mac is that currently there is no way for nw.js app to differentiate between myprotocol://do-a and myprotocol://do-b. Arguments are not passed to the application which in my opinion makes using protocol handlers on Mac almost useless. That's why it would be good to have https://github.com/nwjs/nw.js/pull/1769 re-merged. I've tested recently that it works with nw12 branch with this small change: https://github.com/achwedyk/nw.js/commit/6f3ba7c5af6cce55c945268daf7ad2a1d1d84602

jaruba commented 9 years ago

@achwedyk

Could you please upload the binary with the fix on a new repo and give a link?

You would save me (at least) a headache..

achwedyk commented 9 years ago

@jaruba I've done exactly as you've suggested. Here is the repo: https://github.com/achwedyk/nw.js-release Note that I was building nw.js for the first time. But it compiled fine and initial tests went OK.

jaruba commented 9 years ago

@achwedyk Awesome! One question though, why did you build it for 32bit? It would of been safe (and recommended) to build it for 64bit architecture as all OSX are 64bit anyway. :)

imeetdevpgi commented 8 years ago

It's nice feature to open application from external source on Mac such as browser. Could you please provide us on which version of node-webkit, we can use this feature on windows?

shainegordon commented 8 years ago

this already works on windows with all versions of nw-js.

This requires windows registry entries, and has nothing to do with nw.js

here is an extract from my wix installer configuration

               <Component Id="RegistryEntries" Guid="206C911C-56EF-44B8-9257-5FD242127965">
                   <RegistryKey Root="HKCR"
                         Key="[protocol]"
                         Action="createAndRemoveOnUninstall">
                     <RegistryValue Type="string" Name="URL Protocol" Value=""/>
                     <RegistryValue Type="string" Value="URL:Project Name"/>
                     <RegistryValue Type="string" Name="Content Type" Value="application/x-[protocol]"/>
                     <RegistryKey Key="DefaultIcon">
                       <RegistryValue Type="string" Value="&quot;[INSTALLDIR]Executable.exe&quot;,1" />
                     </RegistryKey>
                     <RegistryKey Key="shell">
                        <RegistryValue Type="string" Value="open"/>
                     </RegistryKey>
                     <RegistryKey Key="shell\open\command">
                       <RegistryValue Type="string" Value="&quot;[INSTALLDIR]Executable.exe&quot; &quot;%1&quot;" />
                     </RegistryKey>
                   </RegistryKey>
                 </Component>
snehapshinde commented 8 years ago

Anybody still working on this issue(specially for Mac)?

Mithgol commented 7 years ago

These two months of silence are most likely to say “nope”.

gpetrov commented 7 years ago

actually this is already implemented some time ago, for usage see: https://github.com/nwjs/nw.js/issues/4240#issuecomment-172096705

maybe somebody should document it

IssueHuntBot commented 5 years ago

@rororofff has funded $2.00 to this issue.


thiago4455 commented 5 years ago

This feature already works on all platforms.

On Linux, just set up your .desktop file:


I'd like to write proper documentation in Users/Advanced/, what do you think?

TheJaredWilcurt commented 4 years ago

It would be nice if this could all be handled in an easy to use Node module with a simple API. I've created a repo with some documentation on the existing suggested solutions.

This can be a place to submit PR's against for each OS.

I need help from others though to get the library working. This is a very low priority for me, as I don't have a need for this functionality in my apps. But happy to maintain the library, merge PR's, test the functionality, and do releases.

Shubham-Kumar-2000 commented 3 years ago

Now There is a nm module to do this which supports macOS, windows and Linux as of now. It can be done by just a function call.

const path = require('path');

const ProtocolRegistry = require('protocol-registry');

console.log('Registering...');
// Registers the Protocol
ProtocolRegistry.register({
    protocol: 'testproto', // sets protocol for your command , testproto://**
    command: `node ${path.join(__dirname, './index.js')} $_URL_`, // this will be executed with a extra argument %url from which it was initiated
    override: true, // Use this with caution as it will destroy all previous Registrations on this protocol
    terminal: true, // Use this to run your command inside a terminal
    script: false
}).then(async () => {
    console.log('Successfully registered');
});

You can read more about it here : https://www.npmjs.com/package/protocol-registry

This module is not exactly related to nwjs but you can achieve similar results with this workaround.