Skip to content

Commit

Permalink
[Tizen/Web] Launch native service in web application
Browse files Browse the repository at this point in the history
This patch launchs image classification offloading service in web application.

Signed-off-by: Yelin Jeong <[email protected]>
  • Loading branch information
niley7464 committed Jul 1, 2024
1 parent e81dff3 commit fcb6066
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion Tizen.web/ImageClassificationOffloading/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,74 @@ function inference(isLocal) {
};
}

let gServiceAppId = "EQmf4iSfpX.imageclassificationoffloadingservice";

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.
*/
function startHybridService() {
try {
tizen.application.getAppsContext(
onGetAppsContextSuccess,
onGetAppsContextError,
);
} catch (e) {
console.log("Get AppContext failed, " + e);
}
}

let ip;
let labels;

window.onload = async function () {
const networkType = await getNetworkType();
ip = await getIpAddress(networkType);
labels = loadLabelInfo();

startHybridService();
document.getElementById("start_local").addEventListener("click", function () {
runLocal();
});
Expand Down

0 comments on commit fcb6066

Please sign in to comment.