From cf911472d7c7ce979ed51412ff5530251fd1ae61 Mon Sep 17 00:00:00 2001 From: Andrei Vacaroiu Date: Wed, 26 Nov 2025 23:19:34 +0200 Subject: [PATCH 1/2] Reduce required permissions: tabs permission can be removed if we store the completion tab id. This way we don't need to iterate (and read) through all tabs anymore to find it. --- public/manifest.json | 1 - src/background/managers/completion-handler.ts | 44 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/public/manifest.json b/public/manifest.json index e42e9f1..9937da5 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -30,7 +30,6 @@ "storage", "contextMenus", "notifications", - "tabs", "offscreen" ], diff --git a/src/background/managers/completion-handler.ts b/src/background/managers/completion-handler.ts index fc4509f..fe77ab5 100644 --- a/src/background/managers/completion-handler.ts +++ b/src/background/managers/completion-handler.ts @@ -4,6 +4,8 @@ import { addCompletedSession } from '../core/pomodoro-history'; import { settingsManager } from './settings-manager'; import { debugLogger } from '../services/debug-logger'; +const COMPLETION_PAGE_TAB_ID_KEY = 'completion_page_tab_id'; + export class CompletionHandler { private lastState: TimerState | null = null; @@ -134,6 +136,15 @@ export class CompletionHandler { } private async closeCompletionPages(): Promise { + // actually close only the last one + const completionTabId = await this.getAndClearCompletionPageTabId() + + if (completionTabId) { + console.log('[DEBUG][CompletionHandler] Closing completion tab:', { tabId: completionTabId }); + await chrome.tabs.remove(completionTabId); + } + + /* const tabs = await chrome.tabs.query({ url: chrome.runtime.getURL('phaseComplete.html') }); console.log('[DEBUG][CompletionHandler] closeCompletionPages:', { timestamp: new Date().toISOString(), @@ -145,6 +156,7 @@ export class CompletionHandler { console.log('[DEBUG][CompletionHandler] Closing completion tab:', { tabId: tab.id }); await chrome.tabs.remove(tab.id!); } + */ } private async openCompletionPage(): Promise { @@ -172,6 +184,10 @@ export class CompletionHandler { newTabId: newTab.id, newTabIndex: newTab.index }); + + if (typeof newTab.id !== 'undefined') { + await this.saveCompletionPageTabId(newTab.id); + } } catch (error) { console.error('[DEBUG][CompletionHandler] Error opening completion page:', error); // Fallback to opening without positioning @@ -185,6 +201,34 @@ export class CompletionHandler { } } + public async saveCompletionPageTabId(tabId: number): Promise { + try { + await chrome.storage.local.set({ [COMPLETION_PAGE_TAB_ID_KEY]: tabId }); + console.log('[DEBUG][CompletionHandler] Saved Completion Page Tab Id: ', tabId) + + } catch (error) { + console.error('Error saving Completion Page Tab ID:', error); + throw error; + } + } + + public async getAndClearCompletionPageTabId(): Promise { + try { + const result = await chrome.storage.local.get(COMPLETION_PAGE_TAB_ID_KEY); + const tabId = result[COMPLETION_PAGE_TAB_ID_KEY]; + + console.log('[DEBUG][CompletionHandler] Completion Page Tab Id Retrieved: ', tabId) + + + await chrome.storage.local.remove(COMPLETION_PAGE_TAB_ID_KEY); + + return tabId; + } catch (error) { + console.error('Error getting Completion Page Tab ID:', error); + throw error; + } + } + private clearNotifications(): void { // Clear any existing pomodoro completion notifications chrome.notifications.clear('pomodoro-complete'); From ab04dab273be23fef2e4f32ea2020f9fa2995680 Mon Sep 17 00:00:00 2001 From: Andrei Vacaroiu Date: Wed, 26 Nov 2025 23:27:22 +0200 Subject: [PATCH 2/2] Removed commented code --- src/background/managers/completion-handler.ts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/background/managers/completion-handler.ts b/src/background/managers/completion-handler.ts index fe77ab5..432e7e9 100644 --- a/src/background/managers/completion-handler.ts +++ b/src/background/managers/completion-handler.ts @@ -143,20 +143,6 @@ export class CompletionHandler { console.log('[DEBUG][CompletionHandler] Closing completion tab:', { tabId: completionTabId }); await chrome.tabs.remove(completionTabId); } - - /* - const tabs = await chrome.tabs.query({ url: chrome.runtime.getURL('phaseComplete.html') }); - console.log('[DEBUG][CompletionHandler] closeCompletionPages:', { - timestamp: new Date().toISOString(), - tabsFound: tabs.length, - tabIds: tabs.map(t => t.id) - }); - - for (const tab of tabs) { - console.log('[DEBUG][CompletionHandler] Closing completion tab:', { tabId: tab.id }); - await chrome.tabs.remove(tab.id!); - } - */ } private async openCompletionPage(): Promise {