Remove disabled action state entirely

This commit is contained in:
hensm
2022-09-10 20:31:35 +01:00
parent 3a38190478
commit 56bd6f841f
3 changed files with 5 additions and 29 deletions

View File

@@ -9,13 +9,9 @@
}, },
"actionTitleDefault": { "actionTitleDefault": {
"message": "fx_cast: Ready to cast", "message": "fx_cast",
"description": "Title for toolbar button in default state." "description": "Title for toolbar button in default state."
}, },
"actionTitleDisabled": {
"message": "fx_cast: Unable to cast",
"description": "Title for toolbar button in disabled state."
},
"actionTitleConnecting": { "actionTitleConnecting": {
"message": "fx_cast: Connecting", "message": "fx_cast: Connecting",
"description": "Title for toolbar button whilst connecting." "description": "Title for toolbar button whilst connecting."

View File

@@ -14,8 +14,7 @@ const isDarkTheme = window.matchMedia("(prefers-color-scheme: dark)").matches;
export enum ActionState { export enum ActionState {
Default, Default,
Connecting, Connecting,
Connected, Connected
Disabled
} }
/** Updates action details depending on given state. */ /** Updates action details depending on given state. */
@@ -29,9 +28,6 @@ export function updateActionState(state: ActionState, tabId?: number) {
case ActionState.Default: case ActionState.Default:
title = _("actionTitleDefault"); title = _("actionTitleDefault");
break; break;
case ActionState.Disabled:
title = _("actionTitleDisabled");
break;
case ActionState.Connecting: case ActionState.Connecting:
title = _("actionTitleConnecting"); title = _("actionTitleConnecting");
path = isDarkTheme path = isDarkTheme
@@ -44,12 +40,6 @@ export function updateActionState(state: ActionState, tabId?: number) {
break; break;
} }
if (state === ActionState.Disabled) {
browser.browserAction.disable(tabId);
} else {
browser.browserAction.enable(tabId);
}
browser.browserAction.setTitle({ tabId, title }); browser.browserAction.setTitle({ tabId, title });
browser.browserAction.setIcon({ tabId, path }); browser.browserAction.setIcon({ tabId, path });
} }
@@ -57,6 +47,8 @@ export function updateActionState(state: ActionState, tabId?: number) {
export function initAction() { export function initAction() {
logger.info("init (action)"); logger.info("init (action)");
updateActionState(ActionState.Default);
browser.browserAction.onClicked.addListener(async tab => { browser.browserAction.onClicked.addListener(async tab => {
if (tab.id === undefined) { if (tab.id === undefined) {
logger.error("Tab ID not found in browser action handler."); logger.error("Tab ID not found in browser action handler.");

View File

@@ -47,7 +47,7 @@ export default new (class extends TypedEventTarget<EventMap> {
async refresh() { async refresh() {
this.bridgePort?.disconnect(); this.bridgePort?.disconnect();
updateActionState(ActionState.Disabled); updateActionState(ActionState.Default);
try { try {
this.bridgeInfo = await bridge.getInfo(); this.bridgeInfo = await bridge.getInfo();
@@ -69,14 +69,6 @@ export default new (class extends TypedEventTarget<EventMap> {
} }
} }
private updateAction() {
if (this.receiverDevices.size > 0) {
updateActionState(ActionState.Default);
} else {
updateActionState(ActionState.Disabled);
}
}
getBridgeInfo() { getBridgeInfo() {
return this.bridgeInfo; return this.bridgeInfo;
} }
@@ -154,8 +146,6 @@ export default new (class extends TypedEventTarget<EventMap> {
}) })
); );
this.updateAction();
break; break;
} }
@@ -171,8 +161,6 @@ export default new (class extends TypedEventTarget<EventMap> {
}) })
); );
this.updateAction();
break; break;
} }