From 27cdfd696d4dfc62e34528cfa87583ae50bed4ab Mon Sep 17 00:00:00 2001 From: Alexandr Stelnykovych Date: Mon, 28 Apr 2025 16:57:32 +0300 Subject: [PATCH] =?UTF-8?q?[desktop]=20fix:=20Bug=20in=20the=20asyncInvoke?= =?UTF-8?q?()=20function=20=E2=80=94=20sometimes=20it=20never=20receives?= =?UTF-8?q?=20a=20response.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes the ticket s26: "[bug] UI: Sometimes the UI remains stuck in the "Connecting to System Service" state indefinitely. " --- .../angular/src/app/integration/taur-app.ts | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/desktop/angular/src/app/integration/taur-app.ts b/desktop/angular/src/app/integration/taur-app.ts index ad663e6b..41ed37b5 100644 --- a/desktop/angular/src/app/integration/taur-app.ts +++ b/desktop/angular/src/app/integration/taur-app.ts @@ -24,7 +24,7 @@ function asyncInvoke(method: string, args: object): Promise { return new Promise((resolve, reject) => { const eventId = uuid(); - once(eventId, (event) => { + const listenerPromise = once(eventId, (event) => { if (typeof event.payload === 'object' && 'error' in event.payload) { reject(event.payload); return @@ -33,14 +33,17 @@ function asyncInvoke(method: string, args: object): Promise { resolve(event.payload); }) - invoke(method, { - ...args, - responseId: eventId, - }).catch((err: any) => { - console.error("tauri:invoke rejected: ", method, args, err); - reject(err) - }); - }) + // Only make the invoke call after the listener is registered + listenerPromise.then(() => { + invoke(method, { + ...args, + responseId: eventId, + }).catch((err: any) => { + console.error("tauri:invoke rejected: ", method, args, err); + reject(err) + }); + }) + }); } export type ServiceManagerStatus = 'Running' | 'Stopped' | 'NotFound' | 'unsupported service manager' | 'unsupported operating system';