diff --git a/options/options.html b/options/options.html
index 606f214..65a0b6c 100644
--- a/options/options.html
+++ b/options/options.html
@@ -97,7 +97,6 @@
-
diff --git a/src/background.ts b/src/background.ts
index b083f52..fea32c4 100644
--- a/src/background.ts
+++ b/src/background.ts
@@ -1,14 +1,19 @@
import type { Message, SearchRequest, ActionRequest, SearchItem } from "./types";
+function sortByRecent(items: SearchItem[]): SearchItem[] {
+ return items.sort((a, b) => (b.lastAccessed ?? 0) - (a.lastAccessed ?? 0));
+}
+
async function getOpenTabs(): Promise {
const tabs = await chrome.tabs.query({});
- return tabs.map((tab) => ({
+ return sortByRecent(tabs.map((tab) => ({
id: `tab-${tab.id}`,
title: tab.title ?? "",
url: tab.url ?? "",
type: "tabs" as const,
favIconUrl: tab.favIconUrl,
- }));
+ lastAccessed: tab.lastAccessed,
+ })));
}
async function getHistory(query: string): Promise {
@@ -17,12 +22,13 @@ async function getHistory(query: string): Promise {
maxResults: 50,
startTime: 0,
});
- return results.map((item) => ({
+ return sortByRecent(results.map((item) => ({
id: `history-${item.id}`,
title: item.title ?? "",
url: item.url ?? "",
type: "history" as const,
- }));
+ lastAccessed: item.lastVisitTime,
+ })));
}
async function getBookmarks(query: string): Promise {
@@ -39,7 +45,7 @@ async function getBookmarks(query: string): Promise {
async function getRecentlyClosed(): Promise {
const sessions = await chrome.sessions.getRecentlyClosed({ maxResults: 25 });
- return sessions
+ return sortByRecent(sessions
.filter((s) => s.tab)
.map((session) => ({
id: `closed-${session.tab!.sessionId}`,
@@ -47,7 +53,8 @@ async function getRecentlyClosed(): Promise {
url: session.tab!.url ?? "",
type: "closed" as const,
favIconUrl: session.tab!.favIconUrl,
- }));
+ lastAccessed: session.lastModified ? session.lastModified * 1000 : undefined,
+ })));
}
async function handleSearch(request: SearchRequest): Promise {
@@ -61,15 +68,6 @@ async function handleSearch(request: SearchRequest): Promise {
return getBookmarks(query);
case "closed":
return getRecentlyClosed();
- case "all": {
- const [tabs, history, bookmarks, closed] = await Promise.all([
- getOpenTabs(),
- getHistory(query),
- getBookmarks(query),
- getRecentlyClosed(),
- ]);
- return [...tabs, ...history, ...bookmarks, ...closed];
- }
}
}
diff --git a/src/chrome.d.ts b/src/chrome.d.ts
index 1076b63..035901f 100644
--- a/src/chrome.d.ts
+++ b/src/chrome.d.ts
@@ -7,6 +7,7 @@ declare namespace chrome {
url?: string;
favIconUrl?: string;
active?: boolean;
+ lastAccessed?: number;
}
function query(queryInfo: Record): Promise;
function get(tabId: number): Promise;
@@ -42,6 +43,7 @@ declare namespace chrome {
namespace sessions {
interface Session {
+ lastModified?: number;
tab?: tabs.Tab & { sessionId?: string };
window?: { sessionId?: string };
}
diff --git a/src/sciezka.ts b/src/sciezka.ts
index f1d1934..984dbfe 100644
--- a/src/sciezka.ts
+++ b/src/sciezka.ts
@@ -1,13 +1,12 @@
import { search } from "./search";
import type { SearchItem, SearchMode, SearchMethod, SearchResult, Message } from "./types";
-const MODES: SearchMode[] = ["tabs", "history", "bookmarks", "closed", "all"];
+const MODES: SearchMode[] = ["tabs", "history", "bookmarks", "closed"];
const MODE_LABELS: Record = {
tabs: "Tabs",
history: "History",
bookmarks: "Bookmarks",
closed: "Closed",
- all: "All",
};
const METHODS: SearchMethod[] = ["fuzzy", "fulltext", "prefix"];
diff --git a/src/search.ts b/src/search.ts
index 623a4dd..e28c959 100644
--- a/src/search.ts
+++ b/src/search.ts
@@ -138,6 +138,9 @@ export function search(items: SearchItem[], query: string, method: SearchMethod)
}
}
- results.sort((a, b) => b.score - a.score);
+ results.sort((a, b) => {
+ if (b.score !== a.score) return b.score - a.score;
+ return (b.item.lastAccessed ?? 0) - (a.item.lastAccessed ?? 0);
+ });
return results;
}
diff --git a/src/types.ts b/src/types.ts
index 1dde0bd..19cc463 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -1,4 +1,4 @@
-export type SearchMode = "tabs" | "history" | "bookmarks" | "closed" | "all";
+export type SearchMode = "tabs" | "history" | "bookmarks" | "closed";
export type SearchMethod = "fuzzy" | "fulltext" | "prefix";
export interface SearchItem {
@@ -7,6 +7,7 @@ export interface SearchItem {
url: string;
type: SearchMode;
favIconUrl?: string;
+ lastAccessed?: number;
}
export interface SearchResult {