Skip to content

Commit

Permalink
⚗️ Attempt popup check for context connection
Browse files Browse the repository at this point in the history
  • Loading branch information
richardfrost committed Mar 20, 2024
1 parent 4c584e6 commit 4142b81
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/script/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default class Popup {
tab: chrome.tabs.Tab;
themeElements: Element[];
url: URL;
webFilterActive: boolean;

//#region Class reference helpers
// Can be overridden in children classes
Expand Down Expand Up @@ -88,6 +89,7 @@ export default class Popup {
}

constructor() {
this.webFilterActive = true;
this.initializeMessaging();
this.disabledTab = false;
this.prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)').matches;
Expand Down Expand Up @@ -137,6 +139,7 @@ export default class Popup {
if (this.disabledTab) return 'Popup disabled for tab';
if (this.cfg.enabledDomainsOnly && !this.domain.enabled) return 'Popup disabled by domain mode';
if (this.domain.disabled) return 'Popup disabled for domain';
if (this.isDisconnected) return 'Disconnected, please refresh page';
return '';
}

Expand Down Expand Up @@ -251,7 +254,7 @@ export default class Popup {
const message = { destination: this.Class.Constants.MESSAGING.CONTEXT, source: this.Class.Constants.MESSAGING.POPUP, summary: true };
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, message, () => {
chrome.runtime.lastError; // Suppress error if no listener);
if (chrome.runtime.lastError) this.webFilterActive = false;
});
});
}
Expand All @@ -262,13 +265,24 @@ export default class Popup {
this.populateOptions(true);
}

get isDisconnected() {
return (
!this.webFilterActive
&& !this.disabledTab
&& !this.isRestrictedPage
&& !this.domain.disabled
&& !(this.cfg.enabledDomainsOnly && !this.domain.enabled)
);
}

get isDisabled() {
return (
this.domain.disabled
|| this.disabledTab
|| (this.cfg.enabledDomainsOnly && !this.domain.enabled)
|| this.isRestrictedPage
|| this.isPasswordProtected
|| this.isDisconnected
);
}

Expand Down Expand Up @@ -312,7 +326,7 @@ export default class Popup {

this.handleDisabledMessage();

if (this.isRestrictedPage) {
if (this.isRestrictedPage || this.isDisconnected) {
this.handleRestrictedPage();
return false;
}
Expand Down

0 comments on commit 4142b81

Please sign in to comment.