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

Implement URL scheme support for MAC in 0.13 #4240

Closed
gpetrov opened this issue Jan 14, 2016 · 17 comments
Closed

Implement URL scheme support for MAC in 0.13 #4240

gpetrov opened this issue Jan 14, 2016 · 17 comments
Assignees
Labels

Comments

@gpetrov
Copy link

gpetrov commented Jan 14, 2016

Please implement this in 0.13 - we are depending on this functionality, so that our app can be opened with custom url scheme - it was already on 0.12!

The code is just is just the 98b1ef8 + achwedyk/nw.js@6f3ba7c

This fix is only needed for the mac - on Windows it is all ok!

On 0.12 it was implemented with #1769

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@rogerwang rogerwang added the nw13 label Jan 14, 2016
@gpetrov
Copy link
Author

gpetrov commented Jan 15, 2016

Testing this it very easy on any nwjs app, just follow the following few steps.
Here I will register the protocol test333://

  • if you show the Contents of the app, under Contents, edit Info.plist
  • in the beginning just after the dict tag add:
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string>Test Extension</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>test333</string>
            </array>
        </dict>
    </array>    
  • in your index,html or main file under app.nw, add something like:
var Gui = require('nw.gui');
Gui.App.on('open', function(url) {
    console.log('APP OPEN EVENT! cmd: ', url);
});
  • open you app once and close it (protocol gets registered from the Info.plist)
  • open safari and enter a url with the registered protocol like this:
    test333://somecustom_string
  • if everything is OK you app should be opened and the open event should be triggered with the url parameter to it
  • if you app was already open it should be activated and only the open event fired again with the passed url

On Windows the registration process is different but it results on the same of the app being started/or activated if running and the open event fired with the url.
You can see the Windows registration process here: http://stackoverflow.com/questions/389204/how-do-i-create-my-own-url-protocol-e-g-so

@rogerwang rogerwang self-assigned this Feb 2, 2016
@rogerwang
Copy link
Member

Fixed in git and will be available in the next nightly build.

@k7k0
Copy link

k7k0 commented Feb 17, 2016

@rogerwang crash is fixed on beta6, but open event argument is undefined. Following @gpetrov example:

APP OPEN EVENT! cmd:  undefined

Am I missing something?

@gpetrov
Copy link
Author

gpetrov commented Feb 17, 2016

@rogerwang I also don't see where this new function OSXOpenURLsHook is called ...
Very excited about getting this to work!

@gpetrov
Copy link
Author

gpetrov commented Feb 17, 2016

@k7k0 Did you got the app open event on each invocation of the custom url? Even when the app is already active? So not only when started initially?

@k7k0
Copy link

k7k0 commented Feb 17, 2016

@gpetrov I'm receiving the open event only when the app is already active. On initial launch no event is called, I'm looking for nw.App.argv arguments (that works on windows) but on OSX is not coming either.

@rogerwang
Copy link
Member

sorry, actually beta6 doesn't contain the full fix. will fix it again asap.

@gpetrov the hook is called from here: https://github.com/nwjs/chromium.src/blob/nw13/chrome/browser/app_controller_mac.mm#L1384

@rogerwang rogerwang reopened this Feb 17, 2016
@rogerwang
Copy link
Member

Fixed again in git and will be available in the next nightly build.

@k7k0
Copy link

k7k0 commented Feb 18, 2016

@rogerwang great, now is working alright!

  • On launch url is available using nw.App.argv
  • While running the event nw.App.on('open') receives the url

Thanks!

@snehapshinde
Copy link

snehapshinde commented Jul 15, 2016

I am not getting the url on 'open' event.

This is my sample start.html:
start.txt

and package.json:
package.txt

info.plist:
Info.txt

The application gets registered with test333, but alert message never shows the url.

I tried with 0.13.0 as well as latest nwjs version.
Am I missing something?

@snehapshinde
Copy link

@gpetrov Please guide me on how to get the URL. Does it take anything extra to do other than what is mentioned in your test333 example?

@gpetrov
Copy link
Author

gpetrov commented Jul 15, 2016

@snehapshinde - all works fine from the example above, you just need to handle the open event, like this in the latest nwjs:

nw.App.on('open', function(url) {
    console.log('APP OPEN EVENT! cmd: ' + url);
        // do something with the passed url
});

This will handle the event when user triggers the user protocol and your app is already open.

If you want to handle the case when your app is not yet open, make sure you also check the command line arguments nw.App.argv for the same sort url as parameter when your app is fully initialized.

@snehapshinde
Copy link

Ok, thanks. I think I was doing something wrong. It is working fine!

I have couple of questions:

  1. can we also register protocols like 'mailto' with this approach. I tried doing it, but it was not registering for mailto, but worked for any other custom protocol. Maybe because mailto protocol is already registered with other app?
  2. Once the app is registered with that protocol, is there any provision to unregister it from nwjs?

Thanks for your reply.

@snehapshinde
Copy link

@gpetrov Kindly reply to my queries. Waiting for it.

@gpetrov
Copy link
Author

gpetrov commented Jul 19, 2016

@snehapshinde this is not a support forum, please check the apple docs on implementing custom protocols

@snehapshinde
Copy link

Ok. Thanks. I will check.

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

No branches or pull requests

4 participants