Skip to content

Commit

Permalink
Added cancel button
Browse files Browse the repository at this point in the history
  • Loading branch information
dpwhittaker committed Aug 2, 2017
1 parent 506dd85 commit b789d2d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
5 changes: 3 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@
<div class="right" style="top: 12px;">RoC Folder</div>
<input id="folder" type="text" class="right shadow" style="top: 48px;color: black; border: 3px solid #7b1b1d; border-radius: 8px; box-sizing: border-box; background-color: #627d9f"/>
<button id="browse" class="right shadow" style="top: 96px; border-radius: 8px; border: 3px solid #7b1b1d; color: #cc9966">Browse</button>
<button id="install" class="right shadow" style="top: 144px; width:48%; border-radius: 8px; border: 3px solid #7b1b1d; color: #cc9966">Install From SWG</button>
<button id="fullscan" class="right shadow" style="top: 144px; right:0; width:48%; border-radius: 8px; border: 3px solid #7b1b1d; color: #cc9966">Full Scan</button>
<button id="install" class="right shadow" style="top: 144px; width:38%; border-radius: 8px; border: 3px solid #7b1b1d; color: #cc9966">Install From SWG</button>
<button id="fullscan" class="right shadow" style="top: 144px; left:40%; width:38%; border-radius: 8px; border: 3px solid #7b1b1d; color: #cc9966">Full Scan</button>
<button id="cancel" class="right shadow" style="top: 144px; left:80%; width:20%; border-radius: 8px; border: 3px solid #7b1b1d; color: #cc9966">Cancel</button>
<div class="right" style="top: 208px;">Mods</div>
<ul id="modlist" class="right shadow" style="top:240px;"></ul>
<button id="gamesettings" class="right shadow" style="bottom:70px; border-radius: 8px; border: 3px solid #7b1b1d; color: #cc9966">Game Settings</button>
Expand Down
14 changes: 12 additions & 2 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ function unionByName(a, b) {
return r;
}

var forks = [];
var canceling = true;
module.exports.install = function(swgPath, emuPath, mods, fullScan) {
const child_process = require('child_process');

canceling = false;
module.exports.getManifest(mods, fullScan, emuPath, checkFiles);

var fileIndex = 0;
Expand All @@ -57,13 +59,15 @@ module.exports.install = function(swgPath, emuPath, mods, fullScan) {
let fork = child_process.fork(__filename, {env});
fork.on('message', m => installedCallback(fork, m));
fork.send(files[fileIndex++]);
forks.push(fork);
}
}
function installedCallback(fork, message) {
if (message.complete !== undefined) {
completedBytes += message.complete;
progress(completedBytes, totalBytes);
if (fileIndex == files.length) {
forks.splice(forks.indexOf(fork), 1);
fork.kill();
console.log("killing fork");
}
Expand All @@ -76,10 +80,16 @@ module.exports.install = function(swgPath, emuPath, mods, fullScan) {
}
}
function progress(completed, total) {
if (module.exports.progress) module.exports.progress(completed, total);
if (module.exports.progress && !canceling) module.exports.progress(completed, total);
}
}

module.exports.cancel = function() {
canceling = true;
for (var fork of forks) fork.kill();
forks = [];
}

if (process.send) {
const AdmZip = require('adm-zip');

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "roc-launcher",
"version": "0.0.14",
"version": "0.0.15",
"description": "Relics of Corbantis Official SWGEMU Launcher",
"main": "main.js",
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const folderBox = document.getElementById('folder');
const browseBtn = document.getElementById('browse');
const installBtn = document.getElementById('install');
const fullscanBtn = document.getElementById('fullscan');
const cancelBtn = document.getElementById('cancel');
const modListBox = document.getElementById('modlist');
const progressBox = document.getElementById('progressbox');
const progressBar = document.getElementById('progress');
Expand Down Expand Up @@ -108,6 +109,12 @@ installBtn.addEventListener('click', function(event) {
ipc.send('open-directory-dialog', 'install-selected');
});

cancelBtn.addEventListener('click', function(event) {
install.cancel();
enableAll();
progressBox.style.display = 'none';
})

ipc.on('install-selected', function (event, path) {
disableAll();
install.install(path, config.folder, config.mods);
Expand Down

0 comments on commit b789d2d

Please sign in to comment.