refactor to again have windows 7 support

This commit is contained in:
Sebastian Hildebrandt 2025-12-28 18:04:53 +01:00
parent faa378db99
commit 153e1e6f91
2 changed files with 39 additions and 36 deletions

View File

@ -212,7 +212,7 @@
<div class="title">Downloads last month</div> <div class="title">Downloads last month</div>
</div> </div>
<div class="col-xl-4 col-lg-4 col-md-4 col-12"> <div class="col-xl-4 col-lg-4 col-md-4 col-12">
<div class="numbers">926</div> <div class="numbers">929</div>
<div class="title">Dependents</div> <div class="title">Dependents</div>
</div> </div>
</div> </div>

View File

@ -375,7 +375,7 @@ function getWmic() {
} else { } else {
wmicPath = 'wmic'; wmicPath = 'wmic';
} }
} catch (e) { } catch {
wmicPath = 'wmic'; wmicPath = 'wmic';
} }
} }
@ -471,7 +471,7 @@ function powerShellRelease() {
_psChild.stdin.end(); _psChild.stdin.end();
_psPersistent = false; _psPersistent = false;
} }
} catch (e) { } catch {
if (_psChild) { if (_psChild) {
_psChild.kill(); _psChild.kill();
} }
@ -480,11 +480,6 @@ function powerShellRelease() {
} }
function powerShell(cmd) { function powerShell(cmd) {
/// const pattern = [
/// '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
/// '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))'
/// ].join('|');
if (_psPersistent) { if (_psPersistent) {
const id = Math.random().toString(36).substring(2, 12); const id = Math.random().toString(36).substring(2, 12);
return new Promise((resolve) => { return new Promise((resolve) => {
@ -502,7 +497,7 @@ function powerShell(cmd) {
if (_psChild && _psChild.pid) { if (_psChild && _psChild.pid) {
_psChild.stdin.write(_psToUTF8 + 'echo ' + _psCmdStart + id + _psIdSeperator + '; ' + os.EOL + cmd + os.EOL + 'echo ' + _psCmdSeperator + os.EOL); _psChild.stdin.write(_psToUTF8 + 'echo ' + _psCmdStart + id + _psIdSeperator + '; ' + os.EOL + cmd + os.EOL + 'echo ' + _psCmdSeperator + os.EOL);
} }
} catch (e) { } catch {
resolve(''); resolve('');
} }
}); });
@ -513,7 +508,12 @@ function powerShell(cmd) {
return new Promise((resolve) => { return new Promise((resolve) => {
process.nextTick(() => { process.nextTick(() => {
try { try {
const child = spawn(_powerShell, ['-NoProfile', '-NoLogo', '-InputFormat', 'Text', '-ExecutionPolicy', 'Unrestricted', '-Command', cmd], { const osVersion = os.release().split('.').map(Number);
const spanOptions =
osVersion[0] < 10
? ['-NoProfile', '-NoLogo', '-InputFormat', 'Text', '-NoExit', '-ExecutionPolicy', 'Unrestricted', '-Command', '-']
: ['-NoProfile', '-NoLogo', '-InputFormat', 'Text', '-ExecutionPolicy', 'Unrestricted', '-Command', cmd];
const child = spawn(_powerShell, spanOptions, {
stdio: 'pipe', stdio: 'pipe',
windowsHide: true, windowsHide: true,
maxBuffer: 1024 * 102400, maxBuffer: 1024 * 102400,
@ -543,18 +543,20 @@ function powerShell(cmd) {
child.kill(); child.kill();
resolve(result); resolve(result);
}); });
// try { if (osVersion[0] < 10) {
// child.stdin.write(_psToUTF8 + cmd + os.EOL); try {
// child.stdin.write('exit' + os.EOL); child.stdin.write(_psToUTF8 + cmd + os.EOL);
// child.stdin.end(); child.stdin.write('exit' + os.EOL);
// } catch (e) { child.stdin.end();
// child.kill(); } catch {
// resolve(result); child.kill();
// } resolve(result);
}
}
} else { } else {
resolve(result); resolve(result);
} }
} catch (e) { } catch {
resolve(result); resolve(result);
} }
}); });
@ -1124,7 +1126,7 @@ function getRpiGpu(cpuinfo) {
try { try {
cpuinfo = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).toString().split('\n'); cpuinfo = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).toString().split('\n');
_rpi_cpuinfo = cpuinfo; _rpi_cpuinfo = cpuinfo;
} catch (e) { } catch {
return false; return false;
} }
} }
@ -1140,22 +1142,23 @@ function getRpiGpu(cpuinfo) {
} }
function promiseAll(promises) { function promiseAll(promises) {
const resolvingPromises = promises.map(function (promise) { const resolvingPromises = promises.map(
return new Promise(function (resolve) { (promise) =>
let payload = new Array(2); new Promise((resolve) => {
const payload = new Array(2);
promise promise
.then(function (result) { .then((result) => {
payload[0] = result; payload[0] = result;
}) })
.catch(function (error) { .catch((error) => {
payload[1] = error; payload[1] = error;
}) })
.then(function () { .then(() => {
// The wrapped Promise returns an array: 0 = result, 1 = error ... we resolve all // The wrapped Promise returns an array: 0 = result, 1 = error ... we resolve all
resolve(payload); resolve(payload);
}); });
}); })
}); );
const errors = []; const errors = [];
const results = []; const results = [];