3

I am using node-webkit to develop apps for my students, and to provide one stop solution I would need to update node-webkit archive once in a month. Is there a way I can accomplish that? Basically I need to replace just one html file every month, say "page1.html". I googled but have no idea where to start.

swapna
  • 145
  • 1
  • 17
  • Tell us more about your setup - will the students have internet access? Does the app have to work offline? I've done something similar, I just need to understand your scenario, perhaps my solution can work for you. – Ewald Nov 22 '13 at 20:31
  • Yes they will have internet access. It will mostly work offline apart from that update feature in case it could be implemented. There will be a file called "lecturenotes.html" and I am looking to update it once in a month or week. My idea is to replace the packaged lecturenotes.html with a new one. I am not sure if it could be done as I am quite new to node-webkit. – swapna Nov 23 '13 at 09:27
  • Ah, my solution is a desktop app, but the data is pulled from the server, so it won't fit your scenario. You could download the data as a zip from the server and unpack it locally, then read and display it. – Ewald Nov 26 '13 at 08:19
  • Any updates on this requirement? Would love to know what happened finally. – asyncwait Aug 05 '14 at 16:52

2 Answers2

2

On Mac, you can access the filesystem of the own app e.g.

$ ls -lh /Applications/Shock.app/Contents/Resources/app.nw/
[...]
-rw-r--r--  1 jordi  staff   2,3K 29 gen 01:47 index.html
-rw-r--r--  1 jordi  staff   467B 29 gen 01:47 lecturenotes.html
[...]

So if you put a new version on a specific URL, you could fetch it and rewrite the HTML file inside the app:

var request = require('request');
request('http://www.your-own-server.com/app/lecturenotes.html', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    var fs = require('fs');
    fs.writeFileSync('/Applications/Shock.app/Contents/Resources/app.nw/lecturenotes.html', body);
  }
});

I think something similar happens on Linux. Unfortunately, the Windows version works with a binary package into the exe, so this trick won't work for the last case.

brickpop
  • 2,754
  • 1
  • 13
  • 12
1

I have used App.dataPath as described in https://github.com/nwjs/nw.js/wiki/App

You can download the html files into that path. App.dataPath works platform independent , though the location is different based on the platforms , your app will have a generic path to refer the html files.

excerpt :

Get the application's data path in user's directory. Windows: %LOCALAPPDATA%/; Linux: ~/.config/; OSX: ~/Library/Application Support/ where is the field in the manifest.

Tito
  • 8,894
  • 12
  • 52
  • 86