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

Quitting app from node-main context #423

Closed
ubaltaci opened this issue Feb 6, 2013 · 4 comments
Closed

Quitting app from node-main context #423

ubaltaci opened this issue Feb 6, 2013 · 4 comments

Comments

@ubaltaci
Copy link

ubaltaci commented Feb 6, 2013

Hi;

I looked https://groups.google.com/forum/?fromgroups=#!topic/node-webkit/R8d4cpCC-6o then when I try to quit app from node context; it throws reference error. Am I missed something ?

index.js:
var gui = window.require('nw.gui');
^
ReferenceError: window is not defined

OS: OS X 10.8
NW version: 4.1
package-json: "node-main":"js/index",

@zhchbin
Copy link
Contributor

zhchbin commented Feb 6, 2013

Hi, @ubaltaci requiring the 'nw.gui' directly didn't supported in the node-main. If you really want this, here is a workaround.
In the index.html(Which is specified in the main field of package.json), require the nw.gui and store it with process.mainModule.exports

package.json

{
  "name": "nw-test",
  "main": "index.html",
  "node-main": "foo.js"
}

index.html

<html>
<head>
   <script >
     process.mainModule.exports.gui = require('nw.gui');
     process.mainModule.exports.test();
   </script>
</head>
<body>
</body>
</html>

foo.js

exports.test = function () {
  console.log(exports.gui);
}

Now you can use it in the foo.js... Just a little trick, hope this will help. Anything wrong, please let me know.

@ubaltaci
Copy link
Author

ubaltaci commented Feb 6, 2013

thanks @zhchbin , I understand now and works like a charm. Thanks again.

@ubaltaci ubaltaci closed this as completed Feb 6, 2013
@darsain
Copy link

darsain commented Feb 6, 2013

I'd like to reference issue #299 in here, as this is one of the reasons I've proposed it.

I just really don't like having anything.html file along with window property in package.json to be an app initiator. The current API is just not sufficient for a lot of complex apps and use cases.

@ubaltaci
Copy link
Author

ubaltaci commented Feb 6, 2013

I'm not an experienced javascript user ( or node.js ) but I have strong oop background especially in case of native mobile applications.

In my app; there are multiple windows and each one handles some data which initialized and processed in node-main file. Therefore; if nw.gui can reachable easily or without little tricks, manipulating life cycle of app become more easy. Also, again I'm noob on javascript, but my first impression on node-webkit's package.json , I've assumed there are two entry points for app ( index.html and main.js ) Even though it's kinda true if api structure changes as you proposed, I think node-webkit starters will feel more comfortable.

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

No branches or pull requests

3 participants