Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
feat(nsis-compat-updater): initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
evshiron committed Apr 19, 2017
1 parent f615850 commit 8451f55
Show file tree
Hide file tree
Showing 14 changed files with 516 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -24,7 +24,7 @@ Although NW.js has much lesser popularity than Electron, and is really troubled
* Configurable executable fields and icons for Windows and macOS
* Integration for `nwjs-ffmpeg-prebuilt`
* Exclusion of useless files from `node_modules`
* TODO Auto Updater inspired by `electron-updater`
* [Auto Updater](./packages/nsis-compat-tester/) inspired by `electron-updater`
* TODO Rebuilding native modules
* Ideas appreciated :)

Expand Down
7 changes: 7 additions & 0 deletions lerna.json
@@ -0,0 +1,7 @@
{
"lerna": "2.0.0-rc.3",
"packages": [
"packages/*"
],
"version": "independent"
}
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -36,6 +36,7 @@
"@types/yargs": "^6.6.0",
"ava": "^0.18.2",
"cross-env": "^3.2.3",
"lerna": "^2.0.0-rc.3",
"nyc": "^10.1.2",
"standard-version": "^4.0.0",
"tslint": "^4.5.1",
Expand Down
22 changes: 22 additions & 0 deletions packages/nsis-compat-tester/app/index.html
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<style type="text/css">

body {
width: 100%;
height: 100%;
margin: 0;
}

</style>
</head>
<body>
<script type="text/javascript">

document.write(`Version: ${ nw.App.manifest.version }`);

</script>
</body>
</html>
65 changes: 65 additions & 0 deletions packages/nsis-compat-tester/main.html
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<style type="text/css">

body {
width: 100%;
height: 100%;
margin: 0;
}

</style>
</head>
<body>
<script type="text/javascript">

document.write(`<p>App launches.</p>`);

const { NsisCompatUpdater } = require('nsis-compat-updater');

const updater = new NsisCompatUpdater('http://127.0.0.1:8080/versions.nsis.json', nw.App.manifest.version, 'x86');

updater.checkForUpdates()
.then((version) => {

document.write(`<p>Version: ${ version }</p>`);

if(version && confirm(`New version of ${ version.version } is available, download now?`)) {

return updater.downloadUpdate(version.version)
.then((path) => {

document.write(`<p>Path: ${ path }</p>`);

if(confirm(`New version of ${ version.version } is downloaded, install now?`)) {
return updater.quitAndInstall(path);
}
else {
return updater.installWhenQuit(path);
}

});

}
else {

nw.Window.open('./app/index.html', {
width: 640,
height: 480,
new_instance: true,
});

nw.Window.get().close();

}

})
.catch((err) => {
document.write(`<p>[ERROR] ${ err.message }</p>`);
});

</script>
</body>
</html>
30 changes: 30 additions & 0 deletions packages/nsis-compat-tester/package.json
@@ -0,0 +1,30 @@
{
"name": "nsis-compat-tester",
"version": "1.0.0",
"description": "",
"main": "main.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "http-server ./dist/",
"start": "DEBUG=nsis-compat-updater run --mirror https://npm.taobao.org/mirrors/nwjs/ .",
"dist": "build --win --x86 --mirror https://npm.taobao.org/mirrors/nwjs/ ."
},
"author": "evshiron",
"license": "MIT",
"dependencies": {
"nsis-compat-updater": "^1.0.0"
},
"devDependencies": {
"http-server": "^0.9.0",
"nwjs-builder-phoenix": "^1.9.3"
},
"build": {
"nwFlavor": "sdk",
"targets": [
"nsis"
],
"nsis": {
"diffUpdaters": true
}
}
}
39 changes: 39 additions & 0 deletions packages/nsis-compat-updater/package.json
@@ -0,0 +1,39 @@
{
"name": "nsis-compat-updater",
"version": "1.0.0",
"description": "",
"main": "./dist/lib/index.js",
"scripts": {
"prepublish": "npm run build",
"test": "npm run build && ava --verbose",
"build": "tsc"
},
"repository": {
"type": "git",
"url": "git+https://github.com/evshiron/nwjs-builder-phoenix.git"
},
"author": "evshiron",
"license": "MIT",
"bugs": {
"url": "https://github.com/evshiron/nwjs-builder-phoenix/issues"
},
"homepage": "https://github.com/evshiron/nwjs-builder-phoenix#readme",
"devDependencies": {
"@types/bluebird-global": "^3.5.1",
"@types/node": "^7.0.12",
"@types/semver": "^5.3.31",
"@types/tmp": "0.0.32",
"ava": "^0.18.2",
"nwjs-builder-phoenix": "^1.9.3",
"tslint": "^5.0.0",
"typescript": "^2.2.2"
},
"dependencies": {
"bluebird": "^3.5.0",
"debug": "^2.6.3",
"got": "^6.7.1",
"progress-stream": "^1.2.0",
"semver": "^5.3.0",
"tmp": "0.0.31"
}
}
2 changes: 2 additions & 0 deletions packages/nsis-compat-updater/src/global.d.ts
@@ -0,0 +1,2 @@

declare const nw: any;
Empty file.
22 changes: 22 additions & 0 deletions packages/nsis-compat-updater/src/lib/Event.ts
@@ -0,0 +1,22 @@

export class Event<TArgs> {

public listeners: Array<(args: TArgs) => void> = [];

constructor(name: string) {

}

public subscribe(fn: ((args: TArgs) => void)) {
this.listeners.push(fn);
}

public trigger = (args: TArgs) => {
this.listeners.map(fn => fn(args));
}

public unsubscribe(fn: ((args: TArgs) => void)) {
this.listeners = this.listeners.filter(f => f != fn);
}

}

0 comments on commit 8451f55

Please sign in to comment.