Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"storage",
"contextMenus",
"notifications",
"tabs",
"offscreen"
],

Expand Down
50 changes: 40 additions & 10 deletions src/background/managers/completion-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -134,16 +136,12 @@ export class CompletionHandler {
}

private async closeCompletionPages(): Promise<void> {
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!);
// 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);
}
}

Expand Down Expand Up @@ -172,6 +170,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
Expand All @@ -185,6 +187,34 @@ export class CompletionHandler {
}
}

public async saveCompletionPageTabId(tabId: number): Promise<void> {
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<number> {
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');
Expand Down