Skip to content

Commit

Permalink
Add command for closing tabs (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-tejada authored Jul 24, 2024
1 parent 603d1d7 commit abca9f8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/background/actions/closeTab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import browser from "webextension-polyfill";
import { getTabIdForMarker } from "../misc/tabMarkers";

export async function closeTab(markers: string[]) {
const tabsToClose = await Promise.all(
markers.map(async (marker) => getTabIdForMarker(marker))
);

await browser.tabs.remove(tabsToClose);
}
1 change: 1 addition & 0 deletions src/background/commands/dispatchCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const backgroundCommands = new Set<RangoAction["type"]>([
"openSettingsPage",
"openPageInNewTab",
"activateTab",
"closeTab",
"refreshTabMarkers",
"toggleTabMarkers",
"focusOrCreateTabByUrl",
Expand Down
6 changes: 6 additions & 0 deletions src/background/commands/runBackgroundCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { sendRequestToContent } from "../messaging/sendRequestToContent";
import { refreshTabMarkers } from "../misc/tabMarkers";
import { getCurrentTab } from "../utils/getCurrentTab";
import { notifySettingRemoved } from "../utils/notify";
import { closeTab } from "../actions/closeTab";

export async function runBackgroundCommand(
command: RangoAction
Expand All @@ -33,6 +34,11 @@ export async function runBackgroundCommand(
break;
}

case "closeTab": {
await closeTab(command.target);
break;
}

case "historyGoBack":
try {
await sendRequestToContent(command);
Expand Down
1 change: 1 addition & 0 deletions src/typings/RangoAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ interface RangoActionWithoutTargetWithOptionalNumberArg {
export interface RangoActionWithTargets {
type:
| "activateTab"
| "closeTab"
| "openInBackgroundTab"
| "clickElement"
| "tryToFocusElementAndCheckIsEditable"
Expand Down

0 comments on commit abca9f8

Please sign in to comment.