@samitouri / QOSami-HFS / commits / 6fe92d62

avoid blocking at start

Massimo Melina committed Mar 1, 2024 at 14:39 UTC 6fe92d62b69681e83489e480f90c73e114e3b954
3 files changed +8 -7
src/adminApis.ts
+1 -1
@@ -116,7 +116,7 @@ export const adminApis: ApiHandlers = {
116 ips: await getIps(false),
117 baseUrl: getBaseUrlOrDefault(),
118 roots: roots.get(),
119 - updatePossible: !updateSupported() ? false : await localUpdateAvailable() ? 'local' : true,
119 + updatePossible: !await updateSupported() ? false : (await localUpdateAvailable()) ? 'local' : true,
120 proxyDetected: getProxyDetected(),
121 frpDetected: localhostAdmin.get() && !getProxyDetected()
122 && getConnections().every(isLocalHost)
src/update.ts
+3 -3
@@ -65,12 +65,12 @@ export function localUpdateAvailable() {
65 return access(LOCAL_UPDATE).then(() => true, () => false)
66 }
67
68 -export function updateSupported() {
69 - return IS_BINARY && !currentServiceName
68 +export async function updateSupported() {
69 + return IS_BINARY && !await currentServiceName
70 }
71
72 export async function update(tagOrUrl: string='') {
73 - if (!updateSupported()) throw "only binary versions supports automatic update for now"
73 + if (!await updateSupported()) throw "only binary versions supports automatic update for now"
74 let updateSource: Readable | false = tagOrUrl.includes('://') ? await httpStream(tagOrUrl)
75 : await localUpdateAvailable() && createReadStream(LOCAL_UPDATE)
76 if (!updateSource) {
src/util-os.ts
+4 -3
@@ -64,12 +64,13 @@ export async function runCmd(cmd: string, args: string[] = []) {
64 return (stderr || stdout).replace(/\r/g, '')
65 }
66
67 -function getWindowsServices() {
67 +async function getWindowsServices() {
68 const fields = ['PathName', 'DisplayName', 'ProcessId'] as const
69 - return parseKeyValueObjects<typeof fields[number]>(execSync(`wmic service get ${fields.join()} /value`).toString().replace(/\r/g, ''))
69 + return parseKeyValueObjects<typeof fields[number]>(await runCmd(`wmic service get ${fields.join()} /value`))
70 }
71
72 -export const currentServiceName = IS_WINDOWS && _.find(getWindowsServices(), { ProcessId: String(pid) })?.DisplayName
72 +export const currentServiceName = IS_WINDOWS && new Promise(async resolve =>
73 + resolve(_.find(await getWindowsServices(), { ProcessId: String(pid) })?.DisplayName))
74
75 function parseKeyValueObjects<T extends string>(all: string, keySep='=', lineSep='\n', objectSep=/\n\n+/) {
76 return all.split(objectSep).map(obj =>