add remove sessions

This commit is contained in:
Julian Freeman
2026-04-17 14:04:44 -04:00
parent ad838086ed
commit d724db6f0f
7 changed files with 76 additions and 6 deletions

View File

@@ -148,6 +148,28 @@ fn cleanup_profile_history_files(profile_path: &Path, profile_id: &str) -> Clean
remove_sidecar_files(&file_path);
}
let sessions_directory = profile_path.join("Sessions");
match cleanup_sessions_directory(&sessions_directory) {
Ok(session_deleted) => {
if session_deleted {
deleted_files.push("Sessions".to_string());
} else {
skipped_files.push("Sessions".to_string());
}
}
Err(error) => {
return CleanupHistoryResult {
profile_id: profile_id.to_string(),
deleted_files,
skipped_files,
error: Some(format!(
"Failed to clean {}: {error}",
sessions_directory.display()
)),
};
}
}
CleanupHistoryResult {
profile_id: profile_id.to_string(),
deleted_files,
@@ -164,3 +186,21 @@ fn remove_sidecar_files(path: &Path) {
}
}
}
fn cleanup_sessions_directory(path: &Path) -> Result<bool, std::io::Error> {
if !path.is_dir() {
return Ok(false);
}
let mut deleted_any = false;
for entry in path.read_dir()? {
let entry = entry?;
let entry_path = entry.path();
if entry_path.is_file() {
fs::remove_file(&entry_path)?;
deleted_any = true;
}
}
Ok(deleted_any)
}

View File

@@ -83,6 +83,7 @@ pub struct HistoryCleanupSummary {
pub history: CleanupFileStatus,
pub top_sites: CleanupFileStatus,
pub visited_links: CleanupFileStatus,
pub sessions: CleanupFileStatus,
}
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]

View File

@@ -101,6 +101,7 @@ fn scan_browser(config: BrowserConfigEntry) -> Option<BrowserView> {
cleanup.history == CleanupFileStatus::Found
|| cleanup.top_sites == CleanupFileStatus::Found
|| cleanup.visited_links == CleanupFileStatus::Found
|| cleanup.sessions == CleanupFileStatus::Found
})
.count();
@@ -195,6 +196,7 @@ fn scan_history_cleanup_status(profile_path: &Path) -> HistoryCleanupSummary {
history: cleanup_file_status(&profile_path.join("History")),
top_sites: cleanup_file_status(&profile_path.join("Top Sites")),
visited_links: cleanup_file_status(&profile_path.join("Visited Links")),
sessions: cleanup_sessions_status(&profile_path.join("Sessions")),
}
}
@@ -206,6 +208,18 @@ fn cleanup_file_status(path: &Path) -> CleanupFileStatus {
}
}
fn cleanup_sessions_status(path: &Path) -> CleanupFileStatus {
let Ok(entries) = path.read_dir() else {
return CleanupFileStatus::Missing;
};
if entries.flatten().any(|entry| entry.path().is_file()) {
CleanupFileStatus::Found
} else {
CleanupFileStatus::Missing
}
}
fn resolve_profile_avatar(
_root: &Path,
profile_path: &Path,

View File

@@ -23,6 +23,7 @@ const selectableProfiles = computed(() =>
profile.historyCleanup.history,
profile.historyCleanup.topSites,
profile.historyCleanup.visitedLinks,
profile.historyCleanup.sessions,
]),
),
);
@@ -52,6 +53,7 @@ function isSelectable(profile: ProfileSummary) {
profile.historyCleanup.history,
profile.historyCleanup.topSites,
profile.historyCleanup.visitedLinks,
profile.historyCleanup.sessions,
]);
}
@@ -96,6 +98,7 @@ function hasAnyHistoryFile(statuses: CleanupFileStatus[]) {
<div class="header-cell">History</div>
<div class="header-cell">Top Sites</div>
<div class="header-cell">Visited Links</div>
<div class="header-cell">Sessions</div>
<div class="header-cell actions-cell">Action</div>
</div>
<div class="data-table-body styled-scrollbar">
@@ -143,6 +146,11 @@ function hasAnyHistoryFile(statuses: CleanupFileStatus[]) {
{{ statusLabel(profile.historyCleanup.visitedLinks) }}
</span>
</div>
<div class="row-cell">
<span class="status-pill" :class="statusClass(profile.historyCleanup.sessions)">
{{ statusLabel(profile.historyCleanup.sessions) }}
</span>
</div>
<div class="row-cell actions-cell">
<button
class="danger-button action-button"
@@ -284,7 +292,7 @@ function hasAnyHistoryFile(statuses: CleanupFileStatus[]) {
.history-grid {
display: grid;
grid-template-columns: 52px 56px minmax(170px, 1fr) 118px 118px 128px 108px;
grid-template-columns: 52px 56px minmax(170px, 1fr) 118px 118px 128px 118px 108px;
gap: 12px;
align-items: center;
}
@@ -401,7 +409,7 @@ function hasAnyHistoryFile(statuses: CleanupFileStatus[]) {
@media (max-width: 900px) {
.history-grid {
grid-template-columns: 52px 56px minmax(160px, 1fr) 110px 110px 118px 100px;
grid-template-columns: 52px 56px minmax(160px, 1fr) 110px 110px 118px 110px 100px;
}
}
@@ -417,7 +425,8 @@ function hasAnyHistoryFile(statuses: CleanupFileStatus[]) {
.history-grid > :nth-child(5),
.history-grid > :nth-child(6),
.history-grid > :nth-child(7) {
.history-grid > :nth-child(7),
.history-grid > :nth-child(8) {
display: none;
}
}

View File

@@ -29,7 +29,7 @@ const emit = defineEmits<{
<template v-if="mode === 'confirm'">
<p class="modal-copy">
The selected profiles will have <code>History</code>, <code>Top Sites</code>, and
<code>Visited Links</code> removed.
<code>Visited Links</code> removed, and all files inside <code>Sessions</code> cleared.
</p>
<div class="profile-list styled-scrollbar">

View File

@@ -352,7 +352,8 @@ export function useBrowserManager() {
return (
cleanup.history === "found" ||
cleanup.topSites === "found" ||
cleanup.visitedLinks === "found"
cleanup.visitedLinks === "found" ||
cleanup.sessions === "found"
);
})
.map((profile) => profile.id);
@@ -373,7 +374,8 @@ export function useBrowserManager() {
return (
cleanup.history === "found" ||
cleanup.topSites === "found" ||
cleanup.visitedLinks === "found"
cleanup.visitedLinks === "found" ||
cleanup.sessions === "found"
);
})
.map((profile) => profile.id);
@@ -430,6 +432,9 @@ export function useBrowserManager() {
if (deletedFiles.includes("Visited Links")) {
profile.historyCleanup.visitedLinks = "missing";
}
if (deletedFiles.includes("Sessions")) {
profile.historyCleanup.sessions = "missing";
}
}
browser.stats.historyCleanupProfileCount = cleanupProfileIdsWithHistory(browser).length;

View File

@@ -46,6 +46,7 @@ export type HistoryCleanupSummary = {
history: CleanupFileStatus;
topSites: CleanupFileStatus;
visitedLinks: CleanupFileStatus;
sessions: CleanupFileStatus;
};
export type CleanupFileStatus = "found" | "missing";