show mute status correctly when tab mute and add to get single tab status
This commit is contained in:
+22
-8
@@ -134,6 +134,7 @@ async function dispatch(command, args) {
|
||||
case "tabs.move": return tabsMove(args);
|
||||
case "tabs.active": return tabsActive(args);
|
||||
case "tabs.active_in_window": return tabsActiveInWindow(args);
|
||||
case "tabs.status": return tabsStatus(args);
|
||||
case "tabs.filter": return tabsFilter(args);
|
||||
case "tabs.count": return tabsCount(args);
|
||||
case "tabs.query": return tabsQuery(args);
|
||||
@@ -275,15 +276,10 @@ async function tabsList() {
|
||||
for (const w of windows) {
|
||||
for (const t of w.tabs) {
|
||||
tabs.push({
|
||||
id: t.id,
|
||||
windowId: t.windowId,
|
||||
...tabInfo(t),
|
||||
windowAlias: aliases[t.windowId] || null,
|
||||
active: t.active,
|
||||
pinned: t.pinned,
|
||||
title: t.title,
|
||||
url: t.url,
|
||||
favIconUrl: t.favIconUrl,
|
||||
groupId: t.groupId >= 0 ? t.groupId : null,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -346,6 +342,11 @@ async function tabsActiveInWindow({ windowId }) {
|
||||
return tabInfo(tab);
|
||||
}
|
||||
|
||||
async function tabsStatus({ tabId }) {
|
||||
const tab = tabId ? await chrome.tabs.get(tabId) : await getActiveTab();
|
||||
return tabInfo(tab);
|
||||
}
|
||||
|
||||
async function tabsFilter({ pattern }) {
|
||||
const all = await chrome.tabs.query({});
|
||||
return all.filter(t => t.url && t.url.includes(pattern)).map(tabInfo);
|
||||
@@ -442,13 +443,13 @@ async function tabsMergeWindows() {
|
||||
}
|
||||
|
||||
async function tabsMute({ tabId }) {
|
||||
const tab = tabId ? await chrome.tabs.get(tabId) : await getActiveTab();
|
||||
const tab = await resolveTabForDirectAction(tabId, "mute");
|
||||
await chrome.tabs.update(tab.id, { muted: true });
|
||||
return { tabId: tab.id, muted: true };
|
||||
}
|
||||
|
||||
async function tabsUnmute({ tabId }) {
|
||||
const tab = tabId ? await chrome.tabs.get(tabId) : await getActiveTab();
|
||||
const tab = await resolveTabForDirectAction(tabId, "unmute");
|
||||
await chrome.tabs.update(tab.id, { muted: false });
|
||||
return { tabId: tab.id, muted: false };
|
||||
}
|
||||
@@ -1243,6 +1244,19 @@ async function getActiveTab() {
|
||||
|| activeTabs[0];
|
||||
}
|
||||
|
||||
async function resolveTabForDirectAction(tabId, actionName) {
|
||||
if (tabId != null) {
|
||||
return chrome.tabs.get(tabId);
|
||||
}
|
||||
const allTabs = await chrome.tabs.query({});
|
||||
if (allTabs.length !== 1) {
|
||||
throw new Error(
|
||||
`Refusing to ${actionName} without explicit tab ID when ${allTabs.length} tabs are open`
|
||||
);
|
||||
}
|
||||
return allTabs[0];
|
||||
}
|
||||
|
||||
async function resolveGroupId(nameOrId) {
|
||||
const asInt = parseInt(nameOrId);
|
||||
if (!isNaN(asInt)) return asInt;
|
||||
|
||||
Reference in New Issue
Block a user