Skip to content

Commit

Permalink
Check if we should auto open tabs (#530)
Browse files Browse the repository at this point in the history
  • Loading branch information
gauntface authored Aug 16, 2024
1 parent 529e1f0 commit a78f7f1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/background/sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "../libs/controllers/_open-tabs";
import { getUrlsToPin } from "../libs/models/_pinned-tabs-browser-storage";
import { sleep } from "../libs/utils/_sleep";
import { getAutoOpenTabs } from "../libs/models/_auto-open-tabs-browser-storage";

const RETRY_SLEEP_MS = 100;
// After 5 minutes, give up.
Expand All @@ -29,6 +30,11 @@ browser.action.onClicked.addListener(async (_tab) => {
});

browser.windows.onCreated.addListener(async (window) => {
const autoOpen = await getAutoOpenTabs();
if (!autoOpen.autoOpenTabsNewWindow) {
return;
}

if (window.type === "normal" && window.id) {
const windowID = window.id;
for (let i = 0; i <= MAX_RETRIES; i += RETRY_SLEEP_MS) {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/models/_auto-open-tabs-browser-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const AUTO_OPEN_STORAGE_KEY = "auto-open-tabs";
export async function getAutoOpenTabs(): Promise<AutoOpenTabs> {
const result = await browser.storage.sync.get(AUTO_OPEN_STORAGE_KEY);
if (result[AUTO_OPEN_STORAGE_KEY]) {
return result[AUTO_OPEN_STORAGE_KEY];
return result[AUTO_OPEN_STORAGE_KEY] as AutoOpenTabs;
}

return {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/models/_pinned-tabs-browser-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const URLS_TO_PIN_STORAGE_KEY = "pinned-tabs";
export async function getUrlsToPin(): Promise<string[]> {
const result = await storage.sync.get(URLS_TO_PIN_STORAGE_KEY);
if (result[URLS_TO_PIN_STORAGE_KEY]) {
return result[URLS_TO_PIN_STORAGE_KEY];
return result[URLS_TO_PIN_STORAGE_KEY] as string[];
}

return [];
Expand Down

0 comments on commit a78f7f1

Please sign in to comment.