From 7d8758d1ee8c323d2f356b5fd1e16e7a3938c05d Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Sat, 16 May 2020 22:50:29 +0200 Subject: [PATCH] Do old frame cleanup with polling --- src/ext/lib/video-data/PageInfo.js | 28 +++++++++++++++++++----- src/ext/uw-bg.js | 35 ++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/ext/lib/video-data/PageInfo.js b/src/ext/lib/video-data/PageInfo.js index 0f375c6..53bc08e 100644 --- a/src/ext/lib/video-data/PageInfo.js +++ b/src/ext/lib/video-data/PageInfo.js @@ -237,12 +237,28 @@ class PageInfo { // if we're left without videos on the current page, we unregister the page. // if we have videos, we call register. if (this.comms) { - if (this.videos.length != oldVideoCount) { // only if number of videos changed, tho - if (this.videos.length > 0) { - this.comms.registerVideo({host: window.location.host, location: window.location}); - } else { - this.comms.unregisterVideo({host: window.location.host, location: window.location}); - } + // We used to send "register video" requests only on the first load, or if the number of + // videos on the page has changed. However, since Chrome Web Store started to require every + // extension requiring "broad permissions" to undergo manual review + // ... and since Chrome Web Store is known for taking their sweet ass time reviewing extensions, + // with review times north of an entire fucking month + // ... and since the legacy way of checking whether our frames-with-videos cache in background + // script contains any frames that no longer exist required us to use webNavigation.getFrame()/ + // webNavigation.getAllFrames(), which requires a permission that triggers a review. + // + // While the extension uses some other permissions that trigger manual review, it's said that + // less is better / has a positive effect on your manual review times ... So I guess we'll do + // things in the less-than-optimal. more-than-retarded way. + // + // no but honestly fuck Chrome. + + // if (this.videos.length != oldVideoCount) { + // } + + if (this.videos.length > 0) { + this.comms.registerVideo({host: window.location.host, location: window.location}); + } else { + this.comms.unregisterVideo({host: window.location.host, location: window.location}); } } diff --git a/src/ext/uw-bg.js b/src/ext/uw-bg.js index d6e2e27..89c6351 100644 --- a/src/ext/uw-bg.js +++ b/src/ext/uw-bg.js @@ -173,14 +173,11 @@ class UWServer { } if (this.videoTabs[sender.tab.id]) { - if (this.videoTabs[sender.tab.id].frames[sender.frameId]) { - return; // existing value is fine, no need to act - } else { - this.videoTabs[sender.tab.id].frames[sender.frameId] = { - id: sender.frameId, - host: frameHostname, - url: sender.url - } + this.videoTabs[sender.tab.id].frames[sender.frameId] = { + id: sender.frameId, + host: frameHostname, + url: sender.url, + registerTime: Date.now(), } } else { this.videoTabs[sender.tab.id] = { @@ -192,7 +189,8 @@ class UWServer { this.videoTabs[sender.tab.id].frames[sender.frameId] = { id: sender.frameId, host: frameHostname, - url: sender.url + url: sender.url, + registerTime: Date.now(), } } @@ -290,6 +288,25 @@ class UWServer { } if (this.videoTabs[ctab.id]) { + // if video is older than PageInfo's video rescan period (+ 4000ms of grace), + // we clean it up from videoTabs[tabId].frames array. + const ageLimit = Date.now() - this.settings.active.pageInfo.timeouts.rescan - 4000; + console.log("videoTabs[tabId]:", this.videoTabs[ctab.id]) + try { + for (const key in this.videoTabs[ctab.id].frames) { + if (this.videoTabs[ctab.id].frames[key].registerTime < ageLimit) { + delete this.videoTabs[ctab.id].frames[key]; + } + } + } catch (e) { + // something went wrong. There's prolly no frames. + return { + host: this.extractHostname(ctab.url), + frames: [], + selected: this.selectedSubitem + } + } + return { ...this.videoTabs[ctab.id], host: this.extractHostname(ctab.url),