Do old frame cleanup with polling
This commit is contained in:
parent
9019963597
commit
7d8758d1ee
@ -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});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user