Fix mount detection
This commit is contained in:
@@ -132,39 +132,56 @@ module.exports.createSignatureFiles = (signature, publicKey) => {
|
||||
|
||||
module.exports.detectRepertoryMounts = (version, providerList) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const processOptions = {
|
||||
detached: true,
|
||||
shell: false,
|
||||
windowsHide: true,
|
||||
};
|
||||
|
||||
const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
|
||||
const args = [];
|
||||
args.push('-status');
|
||||
|
||||
const process = new spawn(command, args, processOptions);
|
||||
let result = '';
|
||||
|
||||
process.on('error', (err) => {
|
||||
reject(err);
|
||||
});
|
||||
|
||||
process.stdout.on('data', (d)=> {
|
||||
result += d;
|
||||
});
|
||||
|
||||
process.on('exit', () => {
|
||||
let defaultData = {};
|
||||
for (const provider of providerList) {
|
||||
defaultData[provider] = {
|
||||
Active: false,
|
||||
Location: '',
|
||||
PID: -1,
|
||||
let mountState = {};
|
||||
const defaultData = {};
|
||||
for (const provider of providerList) {
|
||||
defaultData[provider] = {
|
||||
Active: false,
|
||||
Location: '',
|
||||
PID: -1,
|
||||
};
|
||||
}
|
||||
const grabStatus = index => {
|
||||
if (index >= providerList.length) {
|
||||
resolve(mountState);
|
||||
} else {
|
||||
const provider = providerList[index];
|
||||
const processOptions = {
|
||||
detached: true,
|
||||
shell: false,
|
||||
windowsHide: true,
|
||||
};
|
||||
|
||||
const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
|
||||
const args = [];
|
||||
args.push('-status');
|
||||
if (Constants.PROVIDER_LIST.includes(provider)) {
|
||||
if (provider !== 'Sia') {
|
||||
args.push('-sp');
|
||||
}
|
||||
} else {
|
||||
args.push('-rm');
|
||||
args.push(provider.substr(6));
|
||||
}
|
||||
const process = new spawn(command, args, processOptions);
|
||||
let result = '';
|
||||
|
||||
process.on('error', (err) => {
|
||||
reject(err);
|
||||
});
|
||||
|
||||
process.stdout.on('data', (d) => {
|
||||
result += d;
|
||||
});
|
||||
|
||||
process.on('exit', () => {
|
||||
mountState[provider] = tryParse(result, defaultData)[provider];
|
||||
grabStatus(++index);
|
||||
});
|
||||
process.unref();
|
||||
}
|
||||
resolve(tryParse(result, defaultData));
|
||||
});
|
||||
process.unref();
|
||||
};
|
||||
grabStatus(0);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user