Make "main" property optional for more control over window(s) #299

Closed
darsain opened this Issue Dec 29, 2012 · 8 comments

Comments

Projects
None yet
6 participants

darsain commented Dec 29, 2012

Updated 27th October 2013 to a more sensible proposal

The current package.json format is limiting us in a lot of ways. We have to have one window as main, this window has to be always the same, and its creation can't be controlled.

I'm therefore proposing the "main" property in manifest to become optional, and the new requirement would be to have either "main", OR "node-main" defined.

I've described some problems of the current situation in the posts below, but I can come up with more if needed.

I've been dealing with this problem and trying to work around it for a long time. The workarounds are just ugly and are slowing down the app loading. Please make that bastard optional :)

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

+1 this kind of refactoring makes sense

Contributor

Mithgol commented Dec 29, 2012

−1 that's what I greatly disliked in AppJS. That boilerplate code in app.js that you had to repeat in almost every application.

Why would we need to call gui.createWindow(…) ourselves (for the main window) if a node-webkit can do that automatically? (And it does already.)

Many applications (like, I guess, 80% or 95% of them) need a main window anyway, and that window is actually the same each time. Let's keep that behaviour as a reasonable default and request a new feature: a preference (in the manifest file) to prevent the creation of that main window, such as { "window": null } in package.json.

If you need a main JavaScript file to be automatically executed, rejoice! such a preference is already implemented in the manifest, named node-main.

If you need an API to open new windows with all the same options that are currently available in the window object inside the package.json manifest file, rejoice! you have such API already, it's require('nw.gui').Window.open(…).

With all that existing features, { "window": null } in package.json is the only missing feature you need. Currently { "window": null } in package.json crashes node-webkit v0.3.6 (I observed that on Windows XP). Instead of crashing, it should prevent the main window from being created.

darsain commented Dec 29, 2012

Disliked? It provides so much more control over everything.

  • You can store window positions and sizes from previous launch and than use them as variables while creating the main window.
  • You can have borderless mode (and any other reasonable window option) as a configurable option and let user to choose what he wants.
  • In resource heavy apps, you can display loading screen before the app loads everything it needs.
  • In apps that require authentication, you can display login window that will let user into app, or display login errors. (app I want to create)
  • You can have an app that runs in the background and doesn't have any main window, just a tray icon, and some windows for settings, shortcuts and stuff. (app I want to create)
  • You can have a window that functions as a control panel for other window that uses different window style, border mode, etc ... (app I want to create)
  • You can create an app that will be used as OS default app to open certain file types, and based on what file (or state/validity of that file) is passed to it display different windows, or error messages. (app I want to create)

In all these cases current node-webkit app structure/package.json is either insufficient (app is impossible to do), or it just doesn't make sense, and feels like a bad app design. The current structure is designed for simple apps consisting of one window, and even than the control over opening this window is limited to static variables in package.json. What if my app has config.json file, which - if invalid, or values are not correct - the main window should not even load?

Stripping power away from developer so he wouldn't have to write a few more lines of code is a really bad argument against this.

Having an option in package.json to always open one window for simple apps should probably be kept, but don't throw this request away because you are lazy :)

kevsmt commented Dec 30, 2012

@darsain You can always make a library or $.extend gui {object} and add a createWindow. It is what i did on making node-webkit application, currently i am creating a frameless window w/ basic titlebar controls, and using bootstrap + google-bootstrap theme. I'll release this soon for public domain. Node-webkit i think should just provide a layer on things doable and some fancy functions should be left to the developer to create/decide so it has a better control to its code.

kevsmt commented Dec 30, 2012

I have a request though, making a window modal. like: win.showModal(), this makes the window suitable for logins and splash etc.

https://forrst.com/posts/NodeWebkit_Frameless_Library-HNK

Contributor

Mithgol commented Jan 2, 2013

Stripping power away from developer so he wouldn't have to write a few more lines of code is a really bad argument against this.

No, no, not that. My argument was that giving more power to that developer should not affect the people that don't want to write a few more lines of code. So, instead of removing the window object from the package.json file altogether and for everyone (which was your original suggestion, as far as I understood), I suggested that the developer should be able to declare that object as null ({ "window": null }) if (and only if) that is necessary for his application.

Having an option in package.json to always open one window for simple apps should probably be kept, but don't throw this request away because you are lazy :)

Ok.

In apps that require authentication, you can display login window that will let user into app, or display login errors. (app I want to create)

That you already can do. Use require('nw.gui').Window.get().hide() to hide your main window for the time being, then require('nw.gui').Window.open() to open your login window.

But that's a workaround and I agree that we all should have an option to prevent the main window from being created.

szwacz commented Oct 27, 2013

+1 for this

I like the { "window": null } proposal.

Some of window properties actually doesn't belong to package.json because they are willing to change (width, height, position, etc.). Having to overwrite them after app launch adds redundant computation and rendering time. Constructing app window in the code makes sometimes much more sense.

This should be working with latest version now.

In 0.13 we changed to an optimized architecture so more features can be supported, see http://nwjs.io/blog/whats-new-in-0.13/ and it's good for keeping up with Chromium upstream -- we released with Node.js v6.0 and new Chromium versions within 1 day after upstream release.

The new version would fixed many issues reported here and we're scrubbing them. This issue is closed as we believe it should be fixed. Please leave a message if it isn't and we'll reopen it.

@nwjs-bot nwjs-bot closed this Aug 24, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment