Skip to content

Commit 2766180

Browse files
committed
2.0 - Fixing auto updater
1 parent c4403a0 commit 2766180

File tree

7 files changed

+133
-63
lines changed

7 files changed

+133
-63
lines changed

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This player is compatible only with Chrome/webkit browsers because in future I w
1818

1919
## Usage
2020

21-
**For angular2/typescript development**
21+
**For Angular and Typescript Development**
2222
1. Install [NodeJS 6.11.0+](https://nodejs.org/en/download/ "Node JS Download")
2323
2. Install [angular-cli 1.1.3+](https://github.com/angular/angular-cli "Angular Cli")
2424

@@ -32,7 +32,6 @@ This player is compatible only with Chrome/webkit browsers because in future I w
3232

3333
`npm start` in root folder
3434

35-
------
3635

3736
**For SASS development**
3837

@@ -43,7 +42,21 @@ This player is compatible only with Chrome/webkit browsers because in future I w
4342

4443
4. Start compiling the SCSS files by
4544

46-
`gulp`
45+
`gulp sw` in root folder
46+
47+
------
48+
49+
**For building app**
50+
51+
1. Build the src folder with
52+
`ng build` in root folder (you need to have angular-cli installed on global)
53+
54+
2. Copy package.json from **/app** folder and paste it to **dist** folder
55+
3. Download [NWjs v0.25.0 +](https://nwjs.io/ "NWJS Download")
56+
4. Path your system enviroment to folder where you unarchived
57+
5. Run
58+
59+
`gulp build` in root folder
4760

4861
**For personal use**
4962

dist/index.html

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,49 @@
2020
</div>
2121
</app-yt>
2222
<script>
23-
const AutoUpdater = require( "nw-autoupdater" ),
23+
const AutoUpdater = require( "nw-autoupdater" ),
2424
updater = new AutoUpdater( require( "./package.json" ) ),
2525
output = document.querySelector( "#output" );
26-
async function main(){
27-
try {
28-
// Update copy is running to replace app with the update
29-
if ( updater.isSwapRequest() ) {
30-
output.innerHTML += `\nSwapping...`;
31-
await updater.swap();
32-
output.innerHTML += `\nDone...`;
33-
await updater.restart();
34-
return;
35-
}
36-
// Download/unpack update if any available
37-
const rManifest = await updater.readRemoteManifest();
38-
const needsUpdate = await updater.checkNewVersion( rManifest );
39-
if ( !needsUpdate ) {
40-
output.innerHTML += `\nApp is up to date...`;
41-
return;
42-
}
43-
if ( !confirm( "New release is available. Do you want to upgrade?" ) ) {
44-
return;
45-
}
46-
// Subscribe for progress events
47-
updater.on( "download", ( downloadSize, totalSize ) => {
48-
output.innerHTML = `Downloading...`;
49-
console.log( "download progress", Math.floor( downloadSize / totalSize * 100 ), "%" );
50-
});
51-
updater.on( "install", ( installFiles, totalFiles ) => {
52-
output.innerHTML = `Installing...\n`;
53-
console.log( "install progress", Math.floor( installFiles / totalFiles * 100 ), "%" );
54-
});
55-
const updateFile = await updater.download( rManifest );
56-
await updater.unpack( updateFile );
57-
alert( `The application will automatically restart to finish installing the update` );
58-
await updater.restartToSwap();
59-
} catch ( e ) {
60-
console.error( e );
26+
27+
async function main(){
28+
try {
29+
// Update copy is running to replace app with the update
30+
if ( updater.isSwapRequest() ) {
31+
output.innerHTML += `\nSwapping...`;
32+
await updater.swap();
33+
output.innerHTML += `\nDone...`;
34+
await updater.restart();
35+
return;
36+
}
37+
// Download/unpack update if any available
38+
const rManifest = await updater.readRemoteManifest();
39+
const needsUpdate = await updater.checkNewVersion( rManifest );
40+
if ( !needsUpdate ) {
41+
output.innerHTML += `\nIs up to date...`;
42+
return;
43+
}
44+
if ( !confirm( "New release is available. Do you want to upgrade?" ) ) {
45+
return;
46+
}
47+
// Subscribe for progress events
48+
updater.on( "download", ( downloadSize, totalSize ) => {
49+
output.innerHTML = `Downloading...`;
50+
console.log( "download progress", Math.floor( downloadSize / totalSize * 100 ), "%" );
51+
});
52+
updater.on( "install", ( installFiles, totalFiles ) => {
53+
output.innerHTML = `Installing...\n`;
54+
console.log( "install progress", Math.floor( installFiles / totalFiles * 100 ), "%" );
55+
});
56+
const updateFile = await updater.download( rManifest );
57+
await updater.unpack( updateFile );
58+
alert( `The application will automatically restart to finish installing the update` );
59+
await updater.restartToSwap();
60+
} catch ( e ) {
61+
console.error( e );
62+
}
6163
}
62-
}
63-
output.innerHTML = `${nw.App.manifest.version}\n`;
64-
main();
64+
output.innerHTML = `Application v${nw.App.manifest.version}\n`;
65+
main();
6566

6667
</script>
6768
<script type="text/javascript" src="inline.bundle.js"></script><script type="text/javascript" src="polyfills.bundle.js"></script><script type="text/javascript" src="styles.bundle.js"></script><script type="text/javascript" src="vendor.bundle.js"></script><script type="text/javascript" src="main.bundle.js"></script></body>

dist/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@
2222
"webkit": {
2323
"plugin": true
2424
},
25+
"scripts": {
26+
"postversion": "npm run package",
27+
"package": "nwb nwbuild -v 0.25.2-sdk . -o ../release --output-format=ZIP --output-name={name}-v{version}-{target}"
28+
},
2529
"dependencies": {
2630
"nw-autoupdater": "*"
31+
},
32+
"devDependencies": {
33+
"nwjs-builder": "^1.14.0"
2734
}
2835
}

gulpfile.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@
33
var gulp = require('gulp');
44
var sass = require('gulp-sass');
55
var exec = require('child_process').exec;
6-
var NwBuilder = require('nw-builder');
7-
8-
var nw = new NwBuilder({
9-
files: 'dist/**/**',
10-
platforms: ['win64'],
11-
version: '0.25.2'
12-
});
136

147
gulp.task('sass', function() {
158
return gulp.src('scss/main.scss')
@@ -26,25 +19,31 @@ gulp.task('sw', ['sass'], function() {
2619
});
2720

2821
gulp.task('build', function() {
29-
console.log('Not started');
22+
console.log('Installing packages...');
3023
exec('npm install', { cwd: 'dist', stdio: 'inherit' }, function (error, stdout, stderr) {
3124
if (stderr !== null) {
32-
console.log('stderr' + stderr);
25+
console.log(stderr);
3326
}
3427
if (stdout !== null) {
35-
console.log('stdout' + stdout);
28+
console.log(stdout);
3629
}
3730
if (error !== null) {
38-
console.log('error' + error);
31+
console.log(error);
3932
}
4033
}).on('close', done);
4134

4235
function done() {
43-
nw.build().then(function () {
44-
console.log('all done!');
45-
}).catch(function (error) {
46-
console.error(error);
47-
});
36+
exec('npm run package', { cwd: 'dist', stdio: 'inherit' }, function (error, stdout, stderr) {
37+
if (stderr !== null) {
38+
console.log(stderr);
39+
}
40+
if (stdout !== null) {
41+
console.log(stdout);
42+
}
43+
if (error !== null) {
44+
console.log(error);
45+
}
46+
});
4847
}
4948
});
5049

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular2-youtube-player",
3-
"version": "1.3.0",
3+
"version": "1.0.0",
44
"license": "MIT",
55
"scripts": {
66
"ng": "ng",

src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<header>
22
<div class="header-bar">
3-
<h1>YouTube Player v1.9.1</h1>
3+
<h1>YouTube Player v2.0</h1>
44
<div class="win-controls">
55
<button id="win-minimize" (click)="winMinimize();"></button>
66
<button id="win-maximize" (click)="winMaximize();"></button>

src/index.html

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,69 @@
22
<html>
33
<head>
44
<base href="/">
5-
<title>YouTube Player v1.9.2</title>
5+
<title>YouTube Player v2.0</title>
66
<link rel="icon" href="favicon.ico">
77
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
88
<link rel="stylesheet" href="assets/css/normalize.css">
99
<link rel="stylesheet" href="assets/css/main.css">
1010
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
1111
</head>
12-
<body>
12+
<body class="application app-win">
13+
<div class="updates" style="position: fixed; top: 0; z-index: 999; background-color: red; color: white">
14+
<div id="output"></div>
15+
</div>
1316
<app-yt>
1417
<div class="loading-app">
1518
<i class="fa fa-circle-o-notch fa-spin fa-2x fa-fw"></i>
1619
<span class="sr-only">Loading...</span>
1720
</div>
1821
</app-yt>
19-
</body>
22+
<script>
23+
const AutoUpdater = require( "nw-autoupdater" ),
24+
updater = new AutoUpdater( require( "./package.json" ) ),
25+
output = document.querySelector( "#output" );
26+
27+
async function main(){
28+
try {
29+
// Update copy is running to replace app with the update
30+
if ( updater.isSwapRequest() ) {
31+
output.innerHTML += `\nSwapping...`;
32+
await updater.swap();
33+
output.innerHTML += `\nDone...`;
34+
await updater.restart();
35+
return;
36+
}
37+
// Download/unpack update if any available
38+
const rManifest = await updater.readRemoteManifest();
39+
const needsUpdate = await updater.checkNewVersion( rManifest );
40+
if ( !needsUpdate ) {
41+
output.innerHTML += `\nApp is up to date...`;
42+
return;
43+
}
44+
if ( !confirm( "New release is available. Do you want to upgrade?" ) ) {
45+
return;
46+
}
47+
// Subscribe for progress events
48+
updater.on( "download", ( downloadSize, totalSize ) => {
49+
output.innerHTML = `Downloading...`;
50+
console.log( "download progress", Math.floor( downloadSize / totalSize * 100 ), "%" );
51+
});
52+
updater.on( "install", ( installFiles, totalFiles ) => {
53+
output.innerHTML = `Installing...\n`;
54+
console.log( "install progress", Math.floor( installFiles / totalFiles * 100 ), "%" );
55+
});
56+
const updateFile = await updater.download( rManifest );
57+
await updater.unpack( updateFile );
58+
alert( `The application will automatically restart to finish installing the update` );
59+
await updater.swap();
60+
await updater.restart();
61+
} catch ( e ) {
62+
console.error( e );
63+
}
64+
}
65+
output.innerHTML = `Application ver. ${nw.App.manifest.version}\n`;
66+
main();
67+
68+
</script>
69+
<script type="text/javascript" src="inline.bundle.js"></script><script type="text/javascript" src="polyfills.bundle.js"></script><script type="text/javascript" src="styles.bundle.js"></script><script type="text/javascript" src="vendor.bundle.js"></script><script type="text/javascript" src="main.bundle.js"></script></body>
2070
</html>

0 commit comments

Comments
 (0)