Skip to content
This repository was archived by the owner on Oct 15, 2026. It is now read-only.
Merged
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
41 changes: 41 additions & 0 deletions src/background/alarms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { browser } from '@/shared/browser'
import { ALARM_NAMES, SUSPENSION_CHECK_INTERVAL_MINUTES, RECOVERY_CONFIG } from '@/shared/constants'

export async function setupSuspensionAlarm(): Promise<void> {
await browser.alarms.clear(ALARM_NAMES.SUSPENSION_CHECK)
await browser.alarms.create(ALARM_NAMES.SUSPENSION_CHECK, {
periodInMinutes: SUSPENSION_CHECK_INTERVAL_MINUTES,
})
}

export async function setupAutoSaveAlarm(intervalMinutes: number): Promise<void> {
await browser.alarms.clear(ALARM_NAMES.AUTO_SAVE)
await browser.alarms.create(ALARM_NAMES.AUTO_SAVE, {
periodInMinutes: intervalMinutes,
})
}

export async function setupCloudSyncAlarm(intervalMinutes: number): Promise<void> {
await browser.alarms.clear(ALARM_NAMES.CLOUD_SYNC)
await browser.alarms.create(ALARM_NAMES.CLOUD_SYNC, {
periodInMinutes: intervalMinutes,
})
}

export async function setupRecoverySnapshotAlarm(): Promise<void> {
await browser.alarms.clear(ALARM_NAMES.RECOVERY_SNAPSHOT)
await browser.alarms.create(ALARM_NAMES.RECOVERY_SNAPSHOT, {
periodInMinutes: RECOVERY_CONFIG.INTERVAL_MINUTES,
})
}

/**
* Daily check to decide whether an export reminder is due.
*/
export async function setupExportReminderAlarm(): Promise<void> {
await browser.alarms.clear(ALARM_NAMES.EXPORT_REMINDER)
await browser.alarms.create(ALARM_NAMES.EXPORT_REMINDER, {
periodInMinutes: 60 * 24,
delayInMinutes: 60,
})
}
21 changes: 21 additions & 0 deletions src/background/badge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { browser } from '@/shared/browser'
import { settingsStorage } from '@/shared/storage'
import { getTabCounts } from './suspension'

/**
* Update the extension badge with suspended tab count.
*/
export async function updateBadge(): Promise<void> {
const settings = await settingsStorage.get()

if (!settings.ui.showBadge) {
await browser.action.setBadgeText({ text: '' })
return
}

const counts = await getTabCounts()
const text = counts.suspended > 0 ? counts.suspended.toString() : ''

await browser.action.setBadgeText({ text })
await browser.action.setBadgeBackgroundColor({ color: '#c07a42' }) // raft-500
}
45 changes: 45 additions & 0 deletions src/background/contextMenus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { browser } from '@/shared/browser'

/**
* Set up context menus for right-click actions.
*/
export async function setupContextMenus(): Promise<void> {
await browser.contextMenus.removeAll()

try {
browser.contextMenus.create(
{
id: 'suspend-tab',
title: 'Suspend this tab',
contexts: ['page'],
},
() => {
if (browser.runtime.lastError) {
console.warn('[Raft] Failed to create suspend-tab menu:', browser.runtime.lastError)
}
}
)
} catch (err) {
console.warn('[Raft] Failed to create suspend-tab menu:', err)
}

try {
browser.contextMenus.create(
{
id: 'suspend-other-tabs',
title: 'Suspend other tabs in window',
contexts: ['page'],
},
() => {
if (browser.runtime.lastError) {
console.warn(
'[Raft] Failed to create suspend-other-tabs menu:',
browser.runtime.lastError
)
}
}
)
} catch (err) {
console.warn('[Raft] Failed to create suspend-other-tabs menu:', err)
}
}
Loading
Loading