Get current site more reliably (hopefully)
This commit is contained in:
parent
d6201dc2ac
commit
d2c1b2de3e
@ -154,7 +154,7 @@ class CommsServer {
|
|||||||
if (message.cmd === 'get-current-site') {
|
if (message.cmd === 'get-current-site') {
|
||||||
port.postMessage({
|
port.postMessage({
|
||||||
cmd: 'set-current-site',
|
cmd: 'set-current-site',
|
||||||
site: this.server.getVideoTab(),
|
site: await this.server.getVideoTab(),
|
||||||
tabHostname: await this.getCurrentTabHostname()
|
tabHostname: await this.getCurrentTabHostname()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,8 @@ class UWServer {
|
|||||||
// logger is the first thing that goes up
|
// logger is the first thing that goes up
|
||||||
this.logger = new Logger({
|
this.logger = new Logger({
|
||||||
logToFile: false,
|
logToFile: false,
|
||||||
logToConsole: false
|
logToConsole: true,
|
||||||
|
logAll: true,
|
||||||
});
|
});
|
||||||
await this.logger.init();
|
await this.logger.init();
|
||||||
|
|
||||||
@ -236,12 +237,33 @@ class UWServer {
|
|||||||
this.selectedSubitem[menu] = subitem;
|
this.selectedSubitem[menu] = subitem;
|
||||||
}
|
}
|
||||||
|
|
||||||
getVideoTab() {
|
async getCurrentTab() {
|
||||||
|
if (BrowserDetect.firefox) {
|
||||||
|
return (await browser.tabs.query({active: true, currentWindow: true}))[0];
|
||||||
|
} else if (BrowserDetect.chrome) {
|
||||||
|
return new Promise((resolve, reject) => chrome.tabs.query({active: true, currentWindow: true}, (x) => resolve(x[0])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async getVideoTab() {
|
||||||
// friendly reminder: if current tab doesn't have a video,
|
// friendly reminder: if current tab doesn't have a video,
|
||||||
// there won't be anything in this.videoTabs[this.currentTabId]
|
// there won't be anything in this.videoTabs[this.currentTabId]
|
||||||
if (this.videoTabs[this.currentTabId]) {
|
|
||||||
|
const ctab = await this.getCurrentTab();
|
||||||
|
|
||||||
|
console.log('Current tab:', ctab);
|
||||||
|
|
||||||
|
if (!ctab || !ctab.id) {
|
||||||
return {
|
return {
|
||||||
...this.videoTabs[this.currentTabId],
|
host: 'INVALID SITE',
|
||||||
|
frames: [],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.videoTabs[ctab.id]) {
|
||||||
|
return {
|
||||||
|
...this.videoTabs[ctab.id],
|
||||||
|
host: this.extractHostname(ctab.url),
|
||||||
selected: this.selectedSubitem
|
selected: this.selectedSubitem
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -249,7 +271,7 @@ class UWServer {
|
|||||||
// return something more or less empty if this tab doesn't have
|
// return something more or less empty if this tab doesn't have
|
||||||
// a video registered for it
|
// a video registered for it
|
||||||
return {
|
return {
|
||||||
host: this.currentSite,
|
host: this.extractHostname(ctab.url),
|
||||||
frames: [],
|
frames: [],
|
||||||
selected: this.selectedSubitem
|
selected: this.selectedSubitem
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user