From c1e114c576337287a4ebff928d7e8a8bcb656ad6 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 13 Jan 2016 16:06:44 -0800 Subject: [PATCH] Add start of default content installation --- console/src/downloader.css | 19 +++++++++ console/src/downloader.html | 25 ++++++++++++ console/src/downloader.js | 37 +++++++++++++++++ console/src/main.js | 81 +++++++++++++++++++++++++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 console/src/downloader.css create mode 100644 console/src/downloader.html create mode 100644 console/src/downloader.js diff --git a/console/src/downloader.css b/console/src/downloader.css new file mode 100644 index 0000000000..f0316f349f --- /dev/null +++ b/console/src/downloader.css @@ -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; +} \ No newline at end of file diff --git a/console/src/downloader.html b/console/src/downloader.html new file mode 100644 index 0000000000..5db3b64385 --- /dev/null +++ b/console/src/downloader.html @@ -0,0 +1,25 @@ + + + + High Fidelity + + + + +
+ +
+
+ Installing! +
+
+ Error :( +
+ +
+
+ Complete + +
+ + diff --git a/console/src/downloader.js b/console/src/downloader.js new file mode 100644 index 0000000000..14f8482415 --- /dev/null +++ b/console/src/downloader.js @@ -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 }); +} diff --git a/console/src/main.js b/console/src/main.js index c45f6e91c0..bf054e4e2e 100644 --- a/console/src/main.js +++ b/console/src/main.js @@ -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) {