Skip to content

Commit eb2b0b7

Browse files
committed
🐛 批量更新页全局复用唯一窗口
1 parent 2d05287 commit eb2b0b7

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

‎src/app/service/service_worker/script.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,18 @@ export class ScriptService {
12681268
async openBatchUpdatePage(opts: TOpenBatchUpdatePageOption) {
12691269
const { q, dontCheckNow } = opts;
12701270
const p = q ? `?${q}` : "";
1271-
await openInCurrentTab(`/src/batchupdate.html${p}`);
1271+
const pageUrl = chrome.runtime.getURL(`/src/batchupdate.html${p}`);
1272+
const pageBaseUrl = chrome.runtime.getURL("/src/batchupdate.html");
1273+
const existing = await chrome.tabs.query({ url: `${pageBaseUrl}*` });
1274+
const existingTab = existing.find((tab) => typeof tab.id === "number");
1275+
if (existingTab?.id !== undefined) {
1276+
await chrome.tabs.update(existingTab.id, { active: true });
1277+
if (typeof existingTab.windowId === "number") {
1278+
await chrome.windows.update(existingTab.windowId, { focused: true });
1279+
}
1280+
} else {
1281+
await openInCurrentTab(pageUrl);
1282+
}
12721283
if (!dontCheckNow) {
12731284
await this.checkScriptUpdate({ checkType: "user", noUpdateCheck: 10 * 60 * 1000 });
12741285
}

0 commit comments

Comments
 (0)