[WRTjs][VD] Send 'tizenvisibilitychange' event in app load-finish 32/263132/7
authorliwei <wei90727.li@samsung.com>
Thu, 26 Aug 2021 08:43:16 +0000 (16:43 +0800)
committerliwei <wei90727.li@samsung.com>
Mon, 30 Aug 2021 10:07:29 +0000 (18:07 +0800)
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 <wei90727.li@samsung.com>
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
wrt_app/src/tv/web_application_tv.ts

index ade41477dc43e966d64c27989dac924e024a6202..a80f7bf9499fedf01e638b7a06ad5d88daae6883 100644 (file)
@@ -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() {