diff --git a/Tizen.web/ImageClassificationOffloading/js/main.js b/Tizen.web/ImageClassificationOffloading/js/main.js index 9f36bec5..3b5930e4 100644 --- a/Tizen.web/ImageClassificationOffloading/js/main.js +++ b/Tizen.web/ImageClassificationOffloading/js/main.js @@ -13,6 +13,7 @@ import { GetMaxIdx, GetImgPath, loadLabelInfo, + startHybridService } from "./utils.js"; let fHandle = null; @@ -160,7 +161,7 @@ window.onload = async function () { const networkType = await getNetworkType(); ip = await getIpAddress(networkType); labels = loadLabelInfo(); - + startHybridService(); document.getElementById("start_local").addEventListener("click", function () { runLocal(); }); diff --git a/Tizen.web/ImageClassificationOffloading/js/utils.js b/Tizen.web/ImageClassificationOffloading/js/utils.js index 783a53ca..d7696263 100644 --- a/Tizen.web/ImageClassificationOffloading/js/utils.js +++ b/Tizen.web/ImageClassificationOffloading/js/utils.js @@ -7,6 +7,8 @@ * @author Yelin Jeong */ +let gServiceAppId = "EQmf4iSfpX.imageclassificationoffloadingservice"; + /** * Get currently used network type * @returns the network type @@ -72,3 +74,61 @@ export function loadLabelInfo() { const labelList = fHandle.readString(); return labelList.split("\n"); } + +function launchServiceApp() { + function onSuccess() { + console.log("Service App launched successfully"); + } + + function onError(err) { + console.error("Service App launch failed", err); + } + + try { + console.log("Launching [" + gServiceAppId + "] ..."); + tizen.application.launch(gServiceAppId, onSuccess, onError); + } catch (exc) { + console.error("Exception while launching HybridServiceApp: " + exc.message); + } +} + +function onGetAppsContextSuccess(contexts) { + let i = 0; + let appInfo = null; + + for (i = 0; i < contexts.length; i = i + 1) { + try { + appInfo = tizen.application.getAppInfo(contexts[i].appId); + } catch (exc) { + console.error("Exception while getting application info " + exc.message); + } + + if (appInfo.id === gServiceAppId) { + break; + } + } + + if (i >= contexts.length) { + console.log("Service App not found, Trying to launch service app"); + launchServiceApp(); + } +} + +function onGetAppsContextError(err) { + console.error("getAppsContext exc", err); +} + +/** + * Starts obtaining information about applications + * that are currently running on a device. + */ +export function startHybridService() { + try { + tizen.application.getAppsContext( + onGetAppsContextSuccess, + onGetAppsContextError, + ); + } catch (e) { + console.log("Get AppContext failed, " + e); + } +}