From: liwei Date: Thu, 26 Aug 2021 08:43:16 +0000 (+0800) Subject: [WRTjs][VD] Send 'tizenvisibilitychange' event in app load-finish X-Git-Tag: submit/tizen/20210831.001723~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f075951b9ac40e1913352b86ecdc9105d21b1715;p=platform%2Fframework%2Fweb%2Fwrtjs.git [WRTjs][VD] Send 'tizenvisibilitychange' event in app load-finish In RWI scenario, an empty page will be loaded firstly,and window is shown, at this time, WRT will send 'tizenvisibilitychange' event to app, but app is not loaded, so app cannot receive it, after RWI popup is closed, app will be loaded, but WRT will not send 'tizenvisibilitychange' event anymore. For this case, WRT will send 'tizenvisibilitychange' event in 'load-finish' event(app load), and just send once. Change-Id: I33a61f7cb1f45f7b00f5818bc5af788e2db686a2 Signed-off-by: liwei Signed-off-by: DongHyun Song --- diff --git a/wrt_app/src/tv/web_application_tv.ts b/wrt_app/src/tv/web_application_tv.ts index ade41477..a80f7bf9 100644 --- a/wrt_app/src/tv/web_application_tv.ts +++ b/wrt_app/src/tv/web_application_tv.ts @@ -27,6 +27,7 @@ export class WebApplicationDelegateTV extends WebApplicationDelegate { preloadStatus: string = 'none'; runningStatus: string = 'none'; launchMode: string = 'none'; + needDispatchTizenVisibilityChange: boolean = false; tv: any = (wrt.tv as NativeWRTjs.TVExtension); constructor(webApplication: WebApplication) { @@ -63,6 +64,7 @@ export class WebApplicationDelegateTV extends WebApplicationDelegate { console.log(`runningStatus is DialogClose, src is ${this.inspectorSrc}`); this.webApplication.mainWindow.loadURL(this.inspectorSrc); this.inspectorSrc = ''; + this.needDispatchTizenVisibilityChange = true; } else if (this.runningStatus == 'behind' && this.webApplication.loadFinished) { // TODO : Need to care this situation and decide to pass the addon event emitter to suspend() this.webApplication.suspend(); @@ -75,6 +77,23 @@ export class WebApplicationDelegateTV extends WebApplicationDelegate { this.showInspectorGuide(); else this.suspendByStatus(); + + if (this.needDispatchTizenVisibilityChange) + this.sendTizenVisibilityEvent(this.webApplication.mainWindow.isVisible()); + } + + private sendTizenVisibilityEvent = (visibility: boolean) => { + console.log(`sendTizenVisibilityEvent call`); + this.needDispatchTizenVisibilityChange = false; + const kTizenvisibilityEventScript = `(function(){ +var __event = document.createEvent("CustomEvent"); +__event.initCustomEvent('tizenvisibilitychange', true, true, {visible: ${visibility} | 0}); +document.dispatchEvent(__event); +for (var i=0; i < window.frames.length; i++) + window.frames[i].document.dispatchEvent(__event); +})()`; + let webContents = this.webApplication.mainWindow.webContents; + wrt.executeJS(webContents, kTizenvisibilityEventScript); } private showInspectorGuide() {