Add start of default content installation

This commit is contained in:
Ryan Huffman 2016-01-13 16:06:44 -08:00
parent a6dc3f9b41
commit c1e114c576
4 changed files with 162 additions and 0 deletions

View file

@ -0,0 +1,19 @@
@font-face {
font-family: 'Proxima Nova';
src: url('vendor/ProximaNova/ProximaNova-Regular.otf');
}
* {
font-family: "Proxima Nova", "Open Sans", Arial, Helvetica, sans-serif;
font-size: 1.022em;
line-height: 130%;
}
body {
margin: 0;
padding: 0;
}
progress {
margin: 0 auto;
}

View file

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>High Fidelity</title>
<script src="downloader.js"></script>
<link rel="stylesheet" type="text/css" href="downloader.css"></link>
</head>
<body onload="ready()">
<div id="state-downloading" class="state">
<progress max="100" value="80" id="download-progress"></progress>
</div>
<div id="state-installing" class="state">
Installing!
</div>
<div id="state-error" class="state">
Error :(
<div id='error-message'></div>
<button>OK</button>
</div>
<div id="state-complete" class="state">
Complete
<button>OK</button>
</div>
</body>
</html>

37
console/src/downloader.js Normal file
View file

@ -0,0 +1,37 @@
function ready() {
console.log("Ready");
const electron = require('electron');
window.$ = require('./vendor/jquery/jquery-2.1.4.min.js');
$(".state").hide();
var currentState = null;
function updateState(state, args) {
console.log(state, args);
if (state == 'downloading') {
console.log("Updating progress bar");
$('#download-progress').attr('value', args.progress * 100);
} else if (state == 'installing') {
} else if (state == 'complete') {
} else if (state == 'error') {
$('#error-message').innerHTML = args.message;
}
if (currentState != state) {
if (currentState) {
$('#state-' + currentState).hide();
}
$('#state-' + state).show();
currentState = state;
}
}
electron.ipcRenderer.on('update', function(event, message) {
updateState(message.state, message.args);
});
updateState('downloading', { progress: 0 });
}

View file

@ -15,6 +15,10 @@ var fs = require('fs');
var Tail = require('always-tail');
var http = require('http');
var path = require('path');
var unzip = require('unzip');
var request = require('request');
var progress = require('request-progress');
var Config = require('./modules/config').Config;
@ -289,6 +293,77 @@ function updateTrayMenu(serverState) {
const httpStatusPort = 60332;
function maybeInstallDefaultContentSet() {
var hasRun = userConfig.get('hasRun', false);
if (false && hasRun) {
return;
}
// Show popup
var window = new BrowserWindow({
icon: APP_ICON,
width: 400,
height: 160,
center: true,
frame: true,
useContentSize: true,
resizable: false
});
window.loadURL('file://' + __dirname + '/downloader.html');
// window.setMenu(null);
window.show();
function sendStateUpdate(state, args) {
console.log(state, args);
window.webContents.send('update', { state: state, args: args });
}
var unzipper = unzip.Extract({ path: 'download2', verbose: true });
unzipper.on('close', function() {
console.log("Done", arguments);
sendStateUpdate('complete');
})
unzipper.on('error', function (err) {
console.log("ERROR");
sendStateUpdate('error', {
message: "Error installing resources."
});
});
// responseMessage.pipe(unzipper);
// responseData.pipe(process.stdout);
// console.log("UNZIPPING");
// Start downloading content set
progress(request.get({
url: "http://localhost:8000/contentSet.zip",
// url: "http://builds.highfidelity.com/interface-win64-3908.xe"
}, function(error, responseMessage, responseData) {
if (error || responseMessage.statusCode != 200) {
var message = '';
if (error) {
message = "Error contacting resource server.";
} else {
message = "Error downloading resources from server.";
}
sendStateUpdate('error', {
message: message
});
} else {
sendStateUpdate('installing');
}
}), { throttle: 250 }).on('progress', function(state) {
// Update progress popup
console.log("progress", state);
sendStateUpdate('downloading', { progress: state.percentage });
}).pipe(unzipper);
userConfig.set('hasRun', true);
}
function maybeShowSplash() {
var suppressSplash = userConfig.get('doNotShowSplash', false);
@ -313,6 +388,10 @@ function maybeShowSplash() {
}
}
function detectExistingStackManagerResources() {
return false;
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', function() {
@ -327,6 +406,8 @@ app.on('ready', function() {
tray.setToolTip('High Fidelity');
updateTrayMenu(ProcessGroupStates.STOPPED);
maybeInstallDefaultContentSet();
maybeShowSplash();
if (interfacePath && dsPath && acPath) {