[Service] call onRequest() when app launched again 13/257913/2
authorDongHyun Song <dh81.song@samsung.com>
Thu, 6 May 2021 08:32:45 +0000 (17:32 +0900)
committerDongHyun Song <dh81.song@samsung.com>
Fri, 7 May 2021 00:26:04 +0000 (09:26 +0900)
When the app launched again, onRequest() event will
be called to handle different appcontrol data.

Change-Id: Ia80a6cfd8489318f9b7f42720209d79d76f375ae
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
wrt_app/common/service_manager.ts
wrt_app/common/service_runner.ts

index 14f0a874ae85cae9885ac92ec2b26bf9ed60473a..2bed6a6e25290d72f2638c9b3f1c7054ca4639a5 100644 (file)
@@ -17,8 +17,10 @@ function isStandalone() {
 }
 
 function createWorker(id: string, startService: string, filename: string) {
-  if (workers[id])
+  if (workers[id]) {
+    workers[id].postMessage({ type: 'wake' });
     return;
+  }
 
   workers[id] = new Worker(startService, {
     workerData: {
@@ -51,7 +53,11 @@ export function startService(id: string, filename: string) {
   console.log(`startService - ${id}`);
   if (isStandalone()) {
     runner = require('../common/service_runner');
-    runner.start(id, filename);
+    if (runner.getAppInstance()) {
+      runner.getAppInstance().onRequest();
+    } else {
+      runner.start(id, filename);
+    }
   } else {
     let startService = `${__dirname}/service_runner.js`;
     createWorker(id, startService, filename);
index 5f5410945ffc5cefa44372c32ee19d4e3d251482..f1ce5bcc96d339bc3c0c985fc670aa2df75ad9a8 100644 (file)
@@ -107,6 +107,10 @@ export function stop(id: string) {
   }
 }
 
+export function getAppInstance() {
+  return app;
+}
+
 function run() {
   let id = workerData.id;
   let filename = workerData.filename;
@@ -116,7 +120,9 @@ function run() {
     return;
   parentPort.on('message', (message) => {
     console.log(`Received message type : ${message.type}`);
-    if (message.type === 'stop') {
+    if (message.type === 'wake') {
+      app?.onRequest();
+    } else if (message.type === 'stop') {
       stop(id);
       setTimeout(() => {
         XWalkExtension.cleanup();