remember tab item selection in popup

This commit is contained in:
Tamius Han 2018-11-22 22:55:22 +01:00
parent 0526b43aae
commit 6eaeb717e2
4 changed files with 42 additions and 5 deletions

View File

@ -309,6 +309,9 @@ class CommsServer {
if (message.cmd === 'get-current-site') {
port.postMessage({cmd: 'set-current-site', site: this.server.getVideoTab(), tabHostname: await this.getCurrentTabHostname()});
}
if (message.cmd === 'set-selected-tab') {
this.server.setSelectedTab(cmd.selectedMenu, cmd.selectedSubitem);
}
if (message.cmd === 'get-config') {
if(Debug.debug) {

View File

@ -33,6 +33,16 @@ class MenuItem extends BaseElement {
}
}
}
existsSubitem(subitemName) {
for(let item of this.subitemList) {
if (item.name === subitemName) {
return true;
}
}
return false;
}
selectFirstSubitem() {
for(let item of this.subitemList) {
item.unselect();

View File

@ -16,6 +16,11 @@ class UWServer {
this.videoTabs = {};
this.currentTabId = 0;
this._gctimeout = undefined;
this.selectedSubitem = {
'siteSettings': undefined,
'videoSettings': undefined,
}
}
async setup() {
@ -101,6 +106,11 @@ class UWServer {
if(Debug.debug) {
console.log("TAB SWITCHED!", this.currentSite)
}
this.selectedSubitem = {
'siteSettings': undefined,
'videoSettings': undefined,
}
//TODO: change extension icon based on whether there's any videos on current page
}
@ -192,6 +202,10 @@ class UWServer {
}
}
setSelectedTab(menu, subitem) {
this.selectedSubitem[menu] = subitem;
}
getVideoTab() {
// friendly reminder: if current tab doesn't have a video,
// there won't be anything in this.videoTabs[this.currentTabId]
@ -203,7 +217,8 @@ class UWServer {
// a video registered for it
return {
host: this.currentSite,
frames: []
frames: [],
selected: this.selectedSubitem
}
}
}

View File

@ -32,6 +32,7 @@ port.onMessage.addListener( (m,p) => processReceivedMessage(m,p));
var _video_settings_tab_items = [];
var selectedSubitemLoaded = false;
//#region build ui
var tablist = {
@ -46,16 +47,22 @@ for (let t in tablist) {
}
function loadFrames(videoTab) {
tablist['siteSettings'].removeSubitems();
tablist['videoSettings'].removeSubitems();
console.log("VIDEO TAB", videoTab)
if (!selectedSubitemLoaded) {
if (videoTab.selected) {
selectedSubitem = videoTab.selected;
selectedSubitemLoaded = true;
}
}
function onTabitemClick(item) {
tablist[selectedMenu].selectSubitem(item);
selectedSubitem[selectedMenu] = item;
port.postMessage({cmd: 'select-tab', selectedMenu: selectedMenu, selectedSubitem: item});
}
for (var option of [{id: '__playing', label: 'Currently playing'}, {id: '__all', label: 'All'}]) {
@ -87,12 +94,14 @@ function loadFrames(videoTab) {
tablist['videoSettings'].insertSubitem(newItem);
}
if (! selectedSubitem.siteSettings) {
console.log("TIME TO SELECT SUBITEM", selectedSubitem, "\nexists subitem in site settings/video settings?", selectedSubitem && tablist['siteSettings'].existsSubitem(selectedSubitem.siteSettings), selectedSubitem && tablist['videoSettings'].existsSubitem(selectedSubitem.videoSettings))
if (! selectedSubitem.siteSettings || !tablist['siteSettings'].existsSubitem(selectedSubitem.siteSettings)) {
selectedSubitem['siteSettings'] = tablist['siteSettings'].selectFirstSubitem();
} else {
tablist['siteSettings'].selectSubitem(selectedSubitem.siteSettings)
}
if (! selectedSubitem.videoSettings) {
if (! selectedSubitem.videoSettings || !tablist['videoSettings'].existsSubitem(selectedSubitem.videoSettings)) {
selectedSubitem['videoSettings'] = tablist['videoSettings'].selectFirstSubitem();
} else {
tablist['videoSettings'].selectSubitem(selectedSubitem.videoSettings);