[Updater > Module] Smooth install progress

This commit is contained in:
Ducko 2022-03-14 18:20:02 +00:00
parent bbaa567c75
commit 14d9aab003
2 changed files with 21 additions and 70 deletions

View file

@ -10,21 +10,26 @@ exports.open = async (zipPath, _opts, callback) => {
listeners.error(err);
};
const entryCount = await new Promise((res) => {
execFile('unzip', ['-l', zipPath]).stdout.on('data', (x) => {
const m = x.toString().match(/([0-9]+) files/);
if (m) res(parseInt(m[1]));
});
setTimeout(res, 500);
});
callback(null, {
on: (event, listener) => {
listeners[event] = listener;
},
readEntry: () => {}, // Stubs as not used
openReadStream: () => {},
close: () => {}
entryCount
});
mkdirp.sync(extractPath);
const proc = execFile('unzip', ['-q', '-o', zipPath, '-d', extractPath]);
proc.stderr.on('data', errorOut);
const proc = execFile('unzip', ['-o', zipPath, '-d', extractPath]);
proc.on('error', (err) => {
if (err.code === 'ENOENT') {
@ -35,5 +40,9 @@ exports.open = async (zipPath, _opts, callback) => {
errorOut(err);
});
proc.stderr.on('data', errorOut);
proc.stdout.on('data', (x) => x.toString().split('\n').forEach((x) => x.includes('inflating') && listeners.entry()));
proc.on('close', () => listeners.end());
};