Skip to content
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
5 changes: 4 additions & 1 deletion src/main/browser/tabs/tab-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SplitTabGroup } from "@/browser/tabs/tab-groups/split";
import { windowTabsChanged } from "@/ipc/browser/tabs";
import { setWindowSpace } from "@/ipc/session/spaces";
import { TypedEventEmitter } from "@/modules/typed-event-emitter";
import { shouldArchiveTab } from "@/saving/tabs";
import { shouldArchiveTab, shouldSleepTab } from "@/saving/tabs";
import { getLastUsedSpace, getLastUsedSpaceFromProfile } from "@/sessions/spaces";
import { WebContents } from "electron";
import { TabGroupMode } from "~/types/tabs";
Expand Down Expand Up @@ -83,6 +83,9 @@ export class TabManager extends TypedEventEmitter<TabManagerEvents> {
if (!tab.visible && shouldArchiveTab(tab.lastActiveAt)) {
tab.destroy();
}
if (!tab.visible && !tab.asleep && shouldSleepTab(tab.lastActiveAt)) {
tab.putToSleep();
}
}
}, ARCHIVE_CHECK_INTERVAL_MS);

Expand Down
76 changes: 72 additions & 4 deletions src/main/modules/basic-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ export const ArchiveTabValueMap = {
never: Infinity
};

/**
* Maps sleep tab duration settings to their equivalent values in seconds.
* 'never' is mapped to Infinity.
*/
export const SleepTabValueMap = {
"5m": 5 * 60,
"10m": 10 * 60,
"30m": 30 * 60,
"1h": 60 * 60,
"2h": 2 * 60 * 60,
"4h": 4 * 60 * 60,
"8h": 8 * 60 * 60,
"12h": 12 * 60 * 60,
"24h": 24 * 60 * 60,
never: Infinity
};

export const BasicSettings: BasicSetting[] = [
// [GENERAL] Auto Update
{
Expand Down Expand Up @@ -140,6 +157,57 @@ export const BasicSettings: BasicSetting[] = [
]
},

// Sleep Tab After
{
id: "sleepTabAfter",
name: "Sleep Tab After",
showName: false,
type: "enum",
defaultValue: "never",
options: [
{
id: "5m",
name: "5 Minutes"
},
{
id: "10m",
name: "10 Minutes"
},
{
id: "30m",
name: "30 Minutes"
},
{
id: "1h",
name: "1 Hour"
},
{
id: "2h",
name: "2 Hours"
},
{
id: "4h",
name: "4 Hours"
},
{
id: "8h",
name: "8 Hours"
},
{
id: "12h",
name: "12 Hours"
},
{
id: "24h",
name: "24 Hours"
},
{
id: "never",
name: "Never"
}
]
},

// [ADVANCED] Enable mv2 extensions
{
id: "enableMv2Extensions",
Expand Down Expand Up @@ -179,11 +247,11 @@ export const BasicSettingCards: BasicSettingCard[] = [
settings: ["sidebarSide", "sidebarCollapseMode"]
},

// Archive Tab After Card
// Performance Settings Card
{
title: "Archive Tab After",
subtitle: "Choose how long tabs should be archived",
settings: ["archiveTabAfter"]
title: "Performance Settings",
subtitle: "Settings to improve performance",
settings: ["archiveTabAfter", "sleepTabAfter"]
},

// Onboarding Card (Internal)
Expand Down
13 changes: 12 additions & 1 deletion src/main/saving/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Browser } from "@/browser/browser";
import { SLEEP_MODE_URL, Tab } from "@/browser/tabs/tab";
import { browser } from "@/index";
import { getTabData } from "@/ipc/browser/tabs";
import { ArchiveTabValueMap } from "@/modules/basic-settings";
import { ArchiveTabValueMap, SleepTabValueMap } from "@/modules/basic-settings";
import { getDatastore } from "@/saving/datastore";
import { getSettingValueById } from "@/saving/settings";
import { app } from "electron";
Expand Down Expand Up @@ -61,6 +61,17 @@ export function shouldArchiveTab(lastActiveAt: number) {
return diff > archiveTabAfterSeconds;
}

export function shouldSleepTab(lastActiveAt: number) {
const sleepTabAfter = getSettingValueById("sleepTabAfter");
const sleepTabAfterSeconds = SleepTabValueMap[sleepTabAfter as keyof typeof SleepTabValueMap];

if (typeof sleepTabAfterSeconds !== "number") return false;

const now = Math.floor(Date.now() / 1000);
const diff = now - lastActiveAt;
return diff > sleepTabAfterSeconds;
}

export async function loadTabsFromStorage() {
const tabs: { [uniqueId: string]: TabData } = await TabsDataStore.getFullData();

Expand Down