Skip to content

Commit

Permalink
✨ Popup can enable for a disabled tab
Browse files Browse the repository at this point in the history
  • Loading branch information
richardfrost committed Mar 20, 2024
1 parent bef5955 commit 57911cf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/script/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ export default class Background {
} else if (request.backgroundData) {
this.handleBackgroundDataRequest(request, sender, sendResponse);
return true; // return true when waiting on an async call
} else if (request.enableTab) {
this.toggleTabDisable(request.tabId, false, sendResponse);
return true; // return true when waiting on an async call
} else {
this.LOGGER.error('Received unhandled message.', JSON.stringify(request));
}
Expand Down Expand Up @@ -393,12 +396,13 @@ export default class Background {
}
}

static async toggleTabDisable(tabId: number) {
static async toggleTabDisable(tabId: number, reload = true, sendResponse = null) {
const storage = await this.loadBackgroundStorage();
const tabOptions = this.getTabOptions(storage, tabId);
tabOptions.disabled = !tabOptions.disabled;
await this.saveBackgroundStorage(storage);
chrome.tabs.reload(tabId);
if (reload) chrome.tabs.reload(tabId);
if (sendResponse) sendResponse(tabOptions.disabled);
}

static async updatePopupStatus(tabId: number, status?: number, sendResponse?) {
Expand Down
1 change: 1 addition & 0 deletions src/script/lib/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface Message {
deep?: boolean;
destination: string;
disabled?: boolean;
enableTab?: boolean;
forceUpdate?: boolean;
getStatus?: boolean;
globalVariable?: string;
Expand Down
15 changes: 12 additions & 3 deletions src/script/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ export default class Popup {

handleDisabled() {
this.setDomainSwitch(false);
if (this.disabledTab) this.disableDomainSwitch();
this.disableOptions();
}

Expand Down Expand Up @@ -382,9 +381,19 @@ export default class Popup {

async toggle(prop: string) {
if (!this.protected) {
this.domain[prop] = !this.domain[prop];
try {
await this.domain.save(this.cfg);
if (this.disabledTab) {
const message = {
source: this.Class.Constants.MESSAGING.POPUP,
destination: this.Class.Constants.MESSAGING.BACKGROUND,
enableTab: true,
tabId: this.tab.id,
};
this.disabledTab = await chrome.runtime.sendMessage(message);
} else {
this.domain[prop] = !this.domain[prop];
await this.domain.save(this.cfg);
}
chrome.tabs.reload();
this.populateOptions();
} catch (err) {
Expand Down

0 comments on commit 57911cf

Please sign in to comment.