Skip to content

Commit

Permalink
fix: update tabid
Browse files Browse the repository at this point in the history
  • Loading branch information
oeyoews committed Jul 27, 2024
1 parent 4f120f4 commit d648196
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
38 changes: 21 additions & 17 deletions entrypoints/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ export default defineBackground({

setTimeout(() => {
browser.tabs.onUpdated.addListener((tabId, info, tab) => {
// console.log('update');
if (!tab.url || tab.url === 'null') {
// chrome.sidePanel.setOptions({
// tabId,
// enabled: false,
// });
console.log('none');
chrome.sidePanel.setOptions({
tabId: 61,
enabled: false,
});
return;
}

Expand All @@ -152,26 +152,29 @@ export default defineBackground({

const origin = tab.url;

switch (true) {
case origin.startsWith('https://') && !domains.includes(url.origin):
if (info.status === 'complete') {
if (info.status === 'complete') {
switch (true) {
case origin.startsWith('https://') && !domains.includes(url.origin):
// console.log('update');
chrome.sidePanel.setOptions({
tabId: 61, // HACK: 使用统一个ID, 确保只有一个侧边栏存在
// @deprecated HACK: 使用统一个ID, 确保只有一个侧边栏存在(会导致其他页面无法使用)
tabId: 61,
enabled: true,
path: pages.sidePanelPage,
});
chrome.tabs.sendMessage(tabId, {
type: 'routeUpdate',
// data: origin
});
}
break;
break;

default:
chrome.sidePanel.setOptions({
tabId,
enabled: false,
});
default:
// console.log('close');
chrome.sidePanel.setOptions({
tabId: 61,
enabled: false,
});
}
}

// 页面路由发生变化通知侧边栏前端页面更新
Expand Down Expand Up @@ -243,7 +246,8 @@ export default defineBackground({
// 右键打开侧边栏
chrome.sidePanel
.open({
tabId: tab?.id!,
// tabId: tab?.id!,
tabId: 61,
// windowId: tab?.windowId,
})
.catch((error) => console.error(error));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "usewiki2",
"description": "Convert HTML to Markdown, and save to your computer, support nodejs tiddlywiki",
"private": true,
"version": "4.9.4",
"version": "4.9.5",
"type": "module",
"scripts": {
"dev": "wxt --mode development",
Expand Down

0 comments on commit d648196

Please sign in to comment.