Actually fixed Domain.getInfo() work in some specific cases

This commit is contained in:
Observer KRypt0n_ 2022-01-11 22:05:24 +02:00
parent 8497c9d13b
commit 4f300f48f8
No known key found for this signature in database
GPG key ID: DC5D4EC1303465DA

View file

@ -3,6 +3,8 @@ import type { DomainInfo } from '../types/Domain';
import Process from '../neutralino/Process';
import { DebugThread } from './Debug';
declare const Neutralino;
export default class Domain
{
public static getInfo(uri: string): Promise<DomainInfo>
@ -10,27 +12,15 @@ export default class Domain
const debugThread = new DebugThread('Domain.getInfo', `Getting info about uri: ${uri}`);
return new Promise(async (resolve) => {
const process = await Process.run(`ping -n -4 -w 1 -B "${Process.addSlashes(uri)}"`);
// If something will be wrong - at least we'll have
// to wait 1.5 seconds instread of 2
process.runningInterval = 500;
process.outputInterval = 500;
const process = await Neutralino.os.execCommand(`ping -n -4 -w 1 -B "${Process.addSlashes(uri)}"`);
const output = process.stdOut || process.stdErr;
const resolveInfo = (info: DomainInfo) => {
process.outputInterval = null;
process.runningInterval = null;
process.kill();
debugThread.log({ message: info });
resolve(info);
};
let output = '';
const processOutput = () => {
if (output.includes('Name or service not known'))
{
resolveInfo({
@ -53,15 +43,6 @@ export default class Domain
});
}
}
};
process.output((outputPart) => {
output += outputPart;
processOutput();
});
process.finish(() => processOutput());
});
}
};