global.window = global.window ?? global;
class XWalkExtension {
+ extensions: NativeXWalkExtension[] =
+ process.wrtBinding('wrt_xwalk_extension').getExtensions();
+
constructor() {
- const binding: NativeWRTjs.XWalkExtensionBinding = process.wrtBinding('wrt_xwalk_extension')
- var extensions: NativeXWalkExtension[] = binding.getExtensions();
- for (var i = 0; i < extensions.length; i++) {
- extensions[i].loaded = false;
- console.debug("Load extension : " + extensions[i].name);
- extensions_[extensions[i].name] = extensions[i];
+ for (var i = 0; i < this.extensions.length; i++) {
+ this.extensions[i].loaded = false;
+ console.debug("Load extension : " + this.extensions[i].name);
+ extensions_[this.extensions[i].name] = this.extensions[i];
}
for (var name in extensions_) {
if (!extensions_[name].use_trampoline) {
delete global[parent_name][base_name];
}
}
+
+ destory() {
+ for (var i = 0; i < this.extensions.length; i++)
+ this.extensions[i].destroy();
+ }
}
export const initialize = () => {
}
export let cleanup = () => {
+ instance?.destory();
delete global.tizen;
instance = undefined;
}
import '../common/init';
import * as XWalkExtension from '../common/wrt_xwalk_extension';
-import { DeviceAPIRouter } from './device_api_router';
+import * as DeviceAPIRouter from './device_api_router';
import { isMainThread, parentPort, workerData } from 'worker_threads';
import { wrt } from '../browser/wrt';
-Object.defineProperty(global, 'serviceType', {
- value: wrt.getServiceModel(),
- writable: false
-});
-
function isServiceApplication() {
return global['serviceType'] !== 'UI';
}
}
}
-export function start(id: string, filename: string) {
+function start(id: string, filename: string) {
+ wrt.tv?.serviceMount(id);
let ids = id.split(':');
let serviceId = ids[0];
let packageId = wrt.getPackageId(id);
});
console.debug(`serviceType : ${global['serviceType']}`)
- new DeviceAPIRouter(id, isGlobalService());
+ DeviceAPIRouter.initialize(id, isGlobalService());
printAppControlData(id);
// This is for awaking up uv loop.
}
}
-export function stop(id: string) {
+function stop(id: string) {
if (dummyTimer)
clearInterval(dummyTimer);
try {
}
}
+function destroy(id: string) {
+ XWalkExtension.cleanup();
+ DeviceAPIRouter.cleanup();
+ wrt.tv?.serviceUmount(id);
+
+ wrt.edge?.destroy(); delete wrt.edge;
+ wrt.mde?.destroy(); delete wrt.mde;
+ wrt.security?.destroy(); delete wrt.security;
+ wrt.tv?.destroy(); delete wrt.tv;
+ wrt.destroy();
+}
+
function run() {
let id = workerData.id;
if (!id) {
console.debug('workerData.id is empty!');
process.exit();
}
-
- Object.defineProperty(global, 'internalId', {
- value: id,
- writable: false
+ Object.defineProperties(global, {
+ 'serviceType': {
+ value: wrt.getServiceModel(),
+ writable: false
+ },
+ 'internalId': {
+ value: id,
+ writable: false
+ }
});
- wrt.tv?.serviceMount(id);
let filename = workerData.filename;
start(id, filename);
} else if (message.type === 'stop') {
stop(id);
setTimeout(() => {
- XWalkExtension.cleanup();
+ destroy(id);
parentPort?.postMessage("will-terminate");
parentPort?.close();
- wrt.tv?.serviceUmount(id);
}, message.delay);
}
});