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 3, 2024
1 parent e81dff3 commit 5ee6f02
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Tizen.web/ImageClassificationOffloading/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
GetMaxIdx,
GetImgPath,
loadLabelInfo,
startHybridService
} from "./utils.js";

let fHandle = null;
Expand Down Expand Up @@ -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();
});
Expand Down
60 changes: 60 additions & 0 deletions Tizen.web/ImageClassificationOffloading/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @author Yelin Jeong <[email protected]>
*/

let gServiceAppId = "EQmf4iSfpX.imageclassificationoffloadingservice";

/**
* Get currently used network type
* @returns the network type
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 5ee6f02

Please sign in to comment.