From: DongHyun Song Date: Wed, 12 Oct 2022 08:58:44 +0000 (+0900) Subject: [Service] Provide webapis.isRunningApp() API X-Git-Tag: submit/tizen/20221021.160028~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F55%2F282855%2F4;p=platform%2Fframework%2Fweb%2Fwrtjs.git [Service] Provide webapis.isRunningApp() API Conventionally, to know an app if it is alive with webapis, it should get all alive packages info and check if the subject app ID is included on them. This is very inefficient way. So, WRT did provide below API recently. - wrt.isRunningApp(appId: string): bool This patch will webapis.isRunningApp(appId: strig) also for the service apps. Change-Id: If20751d6b47913ebb9836463b307d5aa97f76e65 Signed-off-by: DongHyun Song --- diff --git a/wrt_app/service/device_api_router.ts b/wrt_app/service/device_api_router.ts index cde4134e..7754a63d 100644 --- a/wrt_app/service/device_api_router.ts +++ b/wrt_app/service/device_api_router.ts @@ -76,14 +76,43 @@ export class DeviceAPIRouter { global.webapis.getAppIdsByMetadata = (metadata: string) => { return wrt.getAppIdsByMetadata(metadata); } + global.webapis.isRunningApp = async (appId: string) => { + if (wrt.isRunningApp) { + return new Promise((resolve) => { + resolve(wrt.isRunningApp(appId)); + }); + } else { + const getAppsContext = async (appId: string): Promise => { + return new Promise((resolve) => { + try { + global.tizen.application.getAppsContext((contexts: any) => { + let isRunningApp = false; + for (let i = 0; i < contexts.length; i++) { + if (appId === contexts[i].appId) { + isRunningApp = true; + break; + } + } + resolve(isRunningApp); + }); + } catch (e) { + console.log(`tizen.application.getAppsContext() has failed with ${e}`); + resolve(false); + } + }); + } + return await getAppsContext(appId); + } + } Object.defineProperties(global.webapis, { getAppIdsByMetadata: { writable: false, enumerable: true }, getCallerAppId: { writable: false, enumerable: true }, getPackageId: { writable: false, enumerable: true }, - getServiceId: { writable: false, enumerable: true }, - postPlainNotification: { writable: false, enumerable: true }, getPreviewData: { writable: false, enumerable: true }, getProfile: { writable: false, enumerable: true }, + getServiceId: { writable: false, enumerable: true }, + isRunningApp: { writable: false, enumerable: true }, + postPlainNotification: { writable: false, enumerable: true }, }); this.initMDEWebapis(); this.initEdgeWebapis();