felix-d1strict / AL-JobTracker

Euro Truck Simulator 2 and American Truck Simulator - Jobtracker for Ace Logistics.
https://ace-logistics.uk
GNU General Public License v3.0
3 stars 1 forks source link

Automatic updates (no discord) #15

Closed AdyStudios closed 3 years ago

AdyStudios commented 3 years ago

The way I imagine it that we just download a zip file from d1strict or directly from github, then we extract it and replace all the files.

AdyStudios commented 3 years ago

https://stackoverflow.com/questions/11944932/how-to-download-a-file-with-node-js-without-using-third-party-libraries for downloading files

AdyStudios commented 3 years ago

https://www.npmjs.com/package/extract-zip For extracting zip, I also dont want to directly google how to make auto updates, just for the chalange

doouz commented 3 years ago

Maybe this can help? https://www.npmjs.com/package/auto-git-update

As I understand it, that way, any commit that is made in the main repository, will be obtained automatically.

AdyStudios commented 3 years ago

Well I don't maybe that could work, but first I want to try it on my own, but thanks for your help 👍

felix-d1strict commented 3 years ago

Should work now.

AdyStudios commented 3 years ago

Looks good 😀, but I will try to add completely auto update, I think you can override app.js while its running bc its on the ram, but maybe not, if not we start the installer and just shut the tracker down.

felix-d1strict commented 3 years ago

Well, just overwriting the app.js might not be so optimal. What if we add new files to the tracker? The solution that we get the files from GitHub is also not the best. There, for example, the API key is not preserved. Getting a ZIP file is a solution but what do we do when we update or add dependencies? (not via npm packages)

So I think downloading the setup file is currently the best solution. Only you would have to find out if you have an event, so to speak, that is triggered when the download is complete. Currently the notification is sent after a timeout. This is not so optimal.

AdyStudios commented 3 years ago

Yeah your right. Sad me :(

felix-d1strict commented 3 years ago

No problem. ;-) That's what the comment function is for. As I said, we just need to find out if there is some kind of event that is triggered when the download is complete.

AdyStudios commented 3 years ago

This one is just happens to have one, it uses fs var http = require('http'); var fs = require('fs');

var download = function(url, dest, cb) { var file = fs.createWriteStream(dest); var request = http.get(url, function(response) { response.pipe(file); file.on('finish', function() { file.close(cb); // close() is async, call cb after close completes. }); }).on('error', function(err) { // Handle errors fs.unlink(dest); // Delete the file async. (But we don't check the result) if (cb) cb(err.message); }); };

Credit to: https://stackoverflow.com/questions/11944932/how-to-download-a-file-with-node-js-without-using-third-party-libraries

felix-d1strict commented 3 years ago

That should help already.

AdyStudios commented 3 years ago

Indeed, but I'm not home right now. I want to get home :((

felix-d1strict commented 3 years ago

Should be finalized with the last commit.