how to get packaged app version #554

Closed
feverzy2 opened this Issue Mar 20, 2013 · 7 comments

Projects

None yet

3 participants

@feverzy2

hi,i'm new here,
i just found node-webkit so amazing !
follow some steps,
i can easily package my html app into a native windows desktop app,

but when i try to achieve app auto update。
i can't find a way to get current app version to compare with the server。

any help will be thankful!

@feverzy2

i found there is a ‘version’ attribute in package.json

but how can't i get it?

@Mithgol
Collaborator
Mithgol commented Mar 20, 2013

If you have attached a zip-packed archive to the tail of the node-webkit's binary, then, knowing the initial size of that binary, you may:

  1. use node-fs-ext to seek past that position,
  2. read the rest (that zip archive),
  3. use JSZip to unpack package.json from that archive,
  4. then parse JSON to get the version.
@feverzy2

thanks!
i tried read package.json with out unpack the zip file.
it worked.

fs.readFile('package.json','utf8', function (err, data) {
      if (err) throw err;
      console.log(data);
    });

i just want to know if there is an api support 。

@rogerwang
Member

Not currently, but it's on our plan. You can watch #360 to track it. Thanks.

@feverzy2

thanks to notify.
here’s my way to download update and run it.
l'd like to share it.

    var gui = require('nw.gui')
    ,execPath= process.execPath
    ,filePath =execPath.substr(0,execPath.lastIndexOf("\\"));

    var http = require('http')
  , fs = require('fs')
  , options,fileName='some.exe'

    options = {
        host: 'www.some.com'
      , port: 80
      , path: '/'+fileName
    }

    var request = http.get(options, function(res){
        var data = ''
        res.setEncoding('binary')

        var rln=0,ln=res.headers['content-length'];     
        res.on('data', function(chunk){
                rln+=chunk.length;
                console.log(Math.round(rln/ln*100));
                //update UI

            data += chunk
        })  
        res.on('end', function(){               
                console.log('File saved.')
            fs.writeFile(filePath+'/'+fileName, data, 'binary', function(err){
                if (err) 
                  //tips
                else{
                    gui.Shell.openItem(fileName);
                    gui.App.quit();
               }
            })
        })  
    })
@rogerwang rogerwang referenced this issue Jul 25, 2013
Closed

App.Version #920

@Mithgol
Collaborator
Mithgol commented Jul 25, 2013

I have to add the following to my previous comment.

When your application is running, it's unpacked already.

That's why, to get your own application's version, you do not have to read the engine's tail and unzip.

Just require('./package.json').version, and you've got the version.

@rogerwang
Member

closing it since #360 is resolved.

@rogerwang rogerwang closed this Aug 3, 2013
@feverzy2 feverzy2 changed the title from how to get packaged app version to how to get packaged app version Apr 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment