mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-12-30 05:28:15 +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,58 +12,37 @@ 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 = '';
|
if (output.includes('Name or service not known'))
|
||||||
|
{
|
||||||
|
resolveInfo({
|
||||||
|
uri: uri,
|
||||||
|
available: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const processOutput = () => {
|
else
|
||||||
if (output.includes('Name or service not known'))
|
{
|
||||||
|
const regex = /PING (.*) \(([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\) .* ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) : [\d]+\([\d]+\)/gm.exec(output);
|
||||||
|
|
||||||
|
if (regex !== null)
|
||||||
{
|
{
|
||||||
resolveInfo({
|
resolveInfo({
|
||||||
uri: uri,
|
uri: regex[1],
|
||||||
available: false
|
remoteIp: regex[2],
|
||||||
|
localIp: regex[3],
|
||||||
|
available: regex[2] !== regex[3]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
const regex = /PING (.*) \(([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\) .* ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) : [\d]+\([\d]+\)/gm.exec(output);
|
|
||||||
|
|
||||||
if (regex !== null)
|
|
||||||
{
|
|
||||||
resolveInfo({
|
|
||||||
uri: regex[1],
|
|
||||||
remoteIp: regex[2],
|
|
||||||
localIp: regex[3],
|
|
||||||
available: regex[2] !== regex[3]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
process.output((outputPart) => {
|
|
||||||
output += outputPart;
|
|
||||||
|
|
||||||
processOutput();
|
|
||||||
});
|
|
||||||
|
|
||||||
process.finish(() => processOutput());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue