Update download contentSet process

This commit is contained in:
Ryan Huffman 2016-01-15 08:52:30 -08:00
parent 57f2722c6b
commit 3a78fbaca5

View file

@ -65,8 +65,12 @@ function shutdown() {
}); });
if (idx == 0) { if (idx == 0) {
isShuttingDown = true; isShuttingDown = true;
logWindow.close(); if (logWindow) {
homeServer.stop(); logWindow.close();
}
if (homeServer) {
homeServer.stop();
}
var timeoutID = setTimeout(app.quit, 5000); var timeoutID = setTimeout(app.quit, 5000);
homeServer.on('state-update', function(processGroup) { homeServer.on('state-update', function(processGroup) {
@ -308,7 +312,7 @@ function updateTrayMenu(serverState) {
const httpStatusPort = 60332; const httpStatusPort = 60332;
function maybeInstallDefaultContentSet() { function maybeInstallDefaultContentSet(onComplete) {
var hasRun = userConfig.get('hasRun', false); var hasRun = userConfig.get('hasRun', false);
if (false && hasRun) { if (false && hasRun) {
@ -331,68 +335,77 @@ function maybeInstallDefaultContentSet() {
// Show popup // Show popup
var window = new BrowserWindow({ var window = new BrowserWindow({
icon: APP_ICON, icon: APP_ICON,
width: 400, width: 640,
height: 160, height: 480,
center: true, center: true,
frame: true, frame: true,
useContentSize: true, useContentSize: true,
resizable: false resizable: false
}); });
window.loadURL('file://' + __dirname + '/downloader.html'); window.loadURL('file://' + __dirname + '/downloader.html');
// window.setMenu(null); window.setMenu(null);
window.show(); window.show();
function sendStateUpdate(state, args) { window.on('closed', onComplete);
console.log(state, args);
window.webContents.send('update', { state: state, args: args });
}
var unzipper = unzip.Extract({ electron.ipcMain.on('ready', function() {
path: getAssignmentClientResourcesDirectory(), console.log("got ready");
verbose: true function sendStateUpdate(state, args) {
}); console.log(state, window, args);
unzipper.on('close', function() { window.webContents.send('update', { state: state, args: args });
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-3914.exe"
}, 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 var aborted = false;
console.log("progress", state);
sendStateUpdate('downloading', { progress: state.percentage }); // Start downloading content set
}).pipe(unzipper); var req = progress(request.get({
// url: "http://localhost:8000/contentSet.zip",
url: "http://builds.highfidelity.com/interface-win64-3914.exe"
}, function(error, responseMessage, responseData) {
if (aborted) {
return;
} else 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) {
if (!aborted) {
// Update progress popup
console.log("progress", state);
sendStateUpdate('downloading', { progress: state.percentage });
}
});
var unzipper = unzip.Extract({
path: getAssignmentClientResourcesDirectory(),
verbose: true
});
unzipper.on('close', function() {
console.log("Done", arguments);
sendStateUpdate('complete');
});
unzipper.on('error', function (err) {
console.log("aborting");
aborted = true;
req.abort();
console.log("ERROR");
sendStateUpdate('error', {
message: "Error installing resources."
});
});
req.pipe(unzipper);
userConfig.set('hasRun', true);
});
userConfig.set('hasRun', true);
} }
function maybeShowSplash() { function maybeShowSplash() {
@ -438,33 +451,34 @@ app.on('ready', function() {
updateTrayMenu(ProcessGroupStates.STOPPED); updateTrayMenu(ProcessGroupStates.STOPPED);
maybeInstallDefaultContentSet(); maybeInstallDefaultContentSet(function() {
maybeShowSplash(); maybeShowSplash();
if (interfacePath && dsPath && acPath) { if (interfacePath && dsPath && acPath) {
domainServer = new Process('domain-server', dsPath, [], logPath); domainServer = new Process('domain-server', dsPath, [], logPath);
acMonitor = new ACMonitorProcess('ac-monitor', acPath, ['-n4', acMonitor = new ACMonitorProcess('ac-monitor', acPath, ['-n4',
'--log-directory', logPath, '--log-directory', logPath,
'--http-status-port', httpStatusPort], httpStatusPort, logPath); '--http-status-port', httpStatusPort], httpStatusPort, logPath);
homeServer = new ProcessGroup('home', [domainServer, acMonitor]); homeServer = new ProcessGroup('home', [domainServer, acMonitor]);
logWindow = new LogWindow(acMonitor, domainServer); logWindow = new LogWindow(acMonitor, domainServer);
// make sure we stop child processes on app quit // make sure we stop child processes on app quit
app.on('quit', function(){ app.on('quit', function(){
console.log('App quitting'); console.log('App quitting');
userConfig.save(configPath); userConfig.save(configPath);
logWindow.close(); logWindow.close();
homeServer.stop(); homeServer.stop();
}); });
var processes = { var processes = {
home: homeServer home: homeServer
}; };
// handle process updates // handle process updates
homeServer.on('state-update', function(processGroup) { updateTrayMenu(processGroup.state); }); homeServer.on('state-update', function(processGroup) { updateTrayMenu(processGroup.state); });
// start the home server // start the home server
homeServer.start(); homeServer.start();
} }
});
}); });