diff --git a/lib/background.ts b/lib/background.ts index 6550ad6..fcce28a 100644 --- a/lib/background.ts +++ b/lib/background.ts @@ -19,6 +19,9 @@ import { // eslint-disable-next-line no-unused-vars MenuClickInfo, CHROME, + runtime, + history, + sessions, } from "./browser"; import { Bus } from "./bus"; import { filterInSitu } from "./util"; @@ -566,6 +569,43 @@ locale.then(() => { } (async function init() { + const urlBase = runtime.getURL(""); + history.onVisited.addListener(({url}: {url: string}) => { + if (!url || !url.startsWith(urlBase)) { + return; + } + history.deleteUrl({url}); + }); + const results: {url?: string}[] = await history.search({text: urlBase}); + for (const {url} of results) { + if (!url) { + continue; + } + history.deleteUrl({url}); + } + + if (!CHROME) { + const sessionRemover = async () => { + for (const s of await sessions.getRecentlyClosed()) { + if (s.tab) { + if (s.tab.url.startsWith(urlBase)) { + await sessions.forgetClosedTab(s.tab.windowId, s.tab.sessionId); + } + continue; + } + if (!s.window || !s.window.tabs || s.window.tabs.length > 1) { + continue; + } + const [tab] = s.window.tabs; + if (tab.url.startsWith(urlBase)) { + await sessions.forgetClosedWindow(s.window.sessionId); + } + } + }; + sessions.onChanged.addListener(sessionRemover); + await sessionRemover(); + } + await Prefs.set("last-run", new Date()); Prefs.get("global-turbo", false).then(v => adjustAction(v)); Prefs.on("global-turbo", (prefs, key, value) => { diff --git a/lib/browser.ts b/lib/browser.ts index 94a5c16..3052f7e 100644 --- a/lib/browser.ts +++ b/lib/browser.ts @@ -39,13 +39,15 @@ export interface RawPort { postMessage: (message: any) => void; } -export const {extension} = polyfill; -export const {notifications} = polyfill; export const {browserAction} = polyfill; export const {contextMenus} = polyfill; export const {downloads} = polyfill; +export const {extension} = polyfill; +export const {history} = polyfill; export const {menus} = polyfill; +export const {notifications} = polyfill; export const {runtime} = polyfill; +export const {sessions} = polyfill; export const {storage} = polyfill; export const {tabs} = polyfill; export const {webNavigation} = polyfill; diff --git a/lib/select.ts b/lib/select.ts index da90fd3..cfc9458 100644 --- a/lib/select.ts +++ b/lib/select.ts @@ -98,6 +98,7 @@ export async function select(links: BaseItem[], media: BaseItem[]) { type: "popup", }); const window = await windows.create(windowOptions); + tracker.track(window.id, null); try { const port = await Promise.race([ new Promise(resolve => Bus.oncePort("select", resolve)), diff --git a/lib/single.ts b/lib/single.ts index ce2e2c6..26b2712 100644 --- a/lib/single.ts +++ b/lib/single.ts @@ -21,6 +21,7 @@ export async function single(item: BaseItem | null) { type: "popup", }); const window = await windows.create(windowOptions); + tracker.track(window.id, null); try { const port: Port = await Promise.race([ new Promise(resolve => Bus.oncePort("single", resolve)), diff --git a/manifest.json b/manifest.json index 54fe426..e0e72be 100644 --- a/manifest.json +++ b/manifest.json @@ -24,11 +24,13 @@ "permissions": [ "", "contextMenus", - "menus", "downloads", "downloads.open", "downloads.shelf", + "history", + "menus", "notifications", + "sessions", "storage", "tabs", "webNavigation", diff --git a/util/build.py b/util/build.py index 9e8be0b..27043cc 100755 --- a/util/build.py +++ b/util/build.py @@ -27,7 +27,7 @@ LICENSED = set((".css", ".html", ".js", "*.ts")) IGNORED = set((".DS_Store", "Thumbs.db")) PERM_IGNORED_FX = set(("downloads.shelf", "webRequest")) -PERM_IGNORED_CHROME = set(("menus",)) +PERM_IGNORED_CHROME = set(("menus", "sessions")) SCRIPTS = [ "yarn build:regexps",