mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-13 02:49:58 +00:00
Remove disabled action state entirely
This commit is contained in:
@@ -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."
|
||||||
|
|||||||
@@ -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.");
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user