Node-webkit app- how to update it?

若如初见. 提交于 2019-12-03 01:53:45

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.

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!