mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-12-21 01:11:46 +03:00
Actually fixed Domain.getInfo()
work in some specific cases
This commit is contained in:
parent
8497c9d13b
commit
4f300f48f8
1 changed files with 21 additions and 40 deletions
|
@ -3,6 +3,8 @@ import type { DomainInfo } from '../types/Domain';
|
||||||
import Process from '../neutralino/Process';
|
import Process from '../neutralino/Process';
|
||||||
import { DebugThread } from './Debug';
|
import { DebugThread } from './Debug';
|
||||||
|
|
||||||
|
declare const Neutralino;
|
||||||
|
|
||||||
export default class Domain
|
export default class Domain
|
||||||
{
|
{
|
||||||
public static getInfo(uri: string): Promise<DomainInfo>
|
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}`);
|
const debugThread = new DebugThread('Domain.getInfo', `Getting info about uri: ${uri}`);
|
||||||
|
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
const process = await Process.run(`ping -n -4 -w 1 -B "${Process.addSlashes(uri)}"`);
|
const process = await Neutralino.os.execCommand(`ping -n -4 -w 1 -B "${Process.addSlashes(uri)}"`);
|
||||||
|
const output = process.stdOut || process.stdErr;
|
||||||
// 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 resolveInfo = (info: DomainInfo) => {
|
const resolveInfo = (info: DomainInfo) => {
|
||||||
process.outputInterval = null;
|
|
||||||
process.runningInterval = null;
|
|
||||||
|
|
||||||
process.kill();
|
|
||||||
|
|
||||||
debugThread.log({ message: info });
|
debugThread.log({ message: info });
|
||||||
|
|
||||||
resolve(info);
|
resolve(info);
|
||||||
};
|
};
|
||||||
|
|
||||||
let output = '';
|
|
||||||
|
|
||||||
const processOutput = () => {
|
|
||||||
if (output.includes('Name or service not known'))
|
if (output.includes('Name or service not known'))
|
||||||
{
|
{
|
||||||
resolveInfo({
|
resolveInfo({
|
||||||
|
@ -53,15 +43,6 @@ export default class Domain
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
process.output((outputPart) => {
|
|
||||||
output += outputPart;
|
|
||||||
|
|
||||||
processOutput();
|
|
||||||
});
|
|
||||||
|
|
||||||
process.finish(() => processOutput());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue