Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ const startUpdate = () => {

require('./firstRun').do();
} else {
moduleUpdater.init(Constants.UPDATE_ENDPOINT, buildInfo);
try {
moduleUpdater.init(Constants.UPDATE_ENDPOINT, buildInfo);
} catch (e) {
log('Modules', 'Failed to init module updater', e);
}
}

splash.events.once('APP_SHOULD_LAUNCH', () => {
Expand Down
35 changes: 32 additions & 3 deletions src/updater/moduleUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ exports.init = (endpoint, { releaseChannel, version }) => {
Module.globalPaths.push(basePath);

// Purge pending
fs.rmSync(downloadPath, { recursive: true, force: true });
mkdir(downloadPath);
try {
fs.rmSync(downloadPath, { recursive: true, force: true });
mkdir(downloadPath);
} catch (e) {
log('Modules', 'Failed to init pending directory', e);
}

try {
installed = JSON.parse(fs.readFileSync(manifestPath));
Expand Down Expand Up @@ -134,6 +138,23 @@ const downloadModule = async (name, ver) => {
const path = join(downloadPath, name + '-' + ver + '.zip');
const file = fs.createWriteStream(path);

let writeFailed = false;
file.on('error', (e) => {
if (writeFailed) return;
writeFailed = true;

log('Modules', 'Failed to download', name, e);

downloading.fail++;
downloading.done++;

events.emit('downloaded-module', { name });

if (downloading.done === downloading.total) {
events.emit('downloaded', { failed: downloading.fail });
}
});

// log('Modules', 'Downloading', `${name}@${ver}`);

let success, total, cur = 0;
Expand All @@ -151,6 +172,8 @@ const downloadModule = async (name, ver) => {

await new Promise((res) => file.on('close', res));

if (writeFailed) return;

if (success) commitManifest();
else downloading.fail++;

Expand Down Expand Up @@ -268,7 +291,13 @@ exports.quitAndInstallUpdates = () => host.quitAndInstall();
exports.isInstalled = (n, v) => installed[n] && (skipModule || !(v && installed[n].installedVersion !== v));
exports.getInstalled = () => ({ ...installed });

const commitManifest = () => fs.writeFileSync(manifestPath, JSON.stringify(installed, null, 2));
const commitManifest = () => {
try {
fs.writeFileSync(manifestPath, JSON.stringify(installed, null, 2));
} catch (e) {
log('Modules', 'Failed to write manifest', e);
}
};

exports.install = (name, def, { version } = {}) => {
if (exports.isInstalled(name, version)) {
Expand Down