From d101a6fe37480cb0b7bbb016a9a730f2c492815b Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 29 Apr 2024 23:26:47 -0400 Subject: [PATCH] added cleanup function --- src/App.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/App.tsx b/src/App.tsx index d4522c6..8de038b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -46,6 +46,8 @@ function App() { if (result.selectedThresholds) { setSelectedThresholds(result.selectedThresholds); } + + cleanupMissingTabs(); }); }, []); @@ -125,6 +127,23 @@ const handleDeleteTab = (id: number) => { setSelectedThresholds(updatedThresholds); }; +// Function to remove missing tabs +const cleanupMissingTabs = () => { + chrome.tabs.query({}, (currentTabs: any[]) => { + const currentTabIds = currentTabs.map(tab => tab.id); + + chrome.storage.local.get('tabs', (result: { tabs?: Tab[] }) => { + if (result.tabs) { + const updatedTabs = result.tabs.filter((tab: Tab) => currentTabIds.includes(tab.id)); + chrome.storage.local.set({ tabs: updatedTabs }, () => { + console.log("Tabs in local storage updated after cleanup."); + }); + } + }); + }); +}; + + return (