change history to clean
This commit is contained in:
@@ -2,13 +2,7 @@ import { computed, onMounted, ref, watch } from "vue";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { open } from "@tauri-apps/plugin-dialog";
|
||||
|
||||
import {
|
||||
sortBookmarks,
|
||||
sortExtensions,
|
||||
sortHistoryDomains,
|
||||
sortPasswordSites,
|
||||
sortProfiles,
|
||||
} from "../utils/sort";
|
||||
import { sortBookmarks, sortExtensions, sortPasswordSites, sortProfiles } from "../utils/sort";
|
||||
import type {
|
||||
ActiveSection,
|
||||
AppPage,
|
||||
@@ -18,9 +12,10 @@ import type {
|
||||
BrowserConfigEntry,
|
||||
BrowserConfigListResponse,
|
||||
BrowserView,
|
||||
CleanupHistoryInput,
|
||||
CleanupHistoryResponse,
|
||||
CreateCustomBrowserConfigInput,
|
||||
ExtensionSortKey,
|
||||
HistoryDomainSortKey,
|
||||
PasswordSiteSortKey,
|
||||
ProfileSortKey,
|
||||
ScanResponse,
|
||||
@@ -56,7 +51,10 @@ export function useBrowserManager() {
|
||||
const extensionSortKey = ref<ExtensionSortKey>("name");
|
||||
const bookmarkSortKey = ref<BookmarkSortKey>("title");
|
||||
const passwordSiteSortKey = ref<PasswordSiteSortKey>("domain");
|
||||
const historyDomainSortKey = ref<HistoryDomainSortKey>("visits");
|
||||
const cleanupHistorySelectedProfiles = ref<string[]>([]);
|
||||
const historyCleanupBusy = ref(false);
|
||||
const cleanupHistoryError = ref("");
|
||||
const cleanupHistoryResults = ref<CleanupHistoryResponse["results"]>([]);
|
||||
|
||||
const browsers = computed(() => response.value.browsers);
|
||||
const currentBrowser = computed<BrowserView | null>(
|
||||
@@ -78,9 +76,6 @@ export function useBrowserManager() {
|
||||
const sortedPasswordSites = computed(() =>
|
||||
sortPasswordSites(currentBrowser.value?.passwordSites ?? [], passwordSiteSortKey.value),
|
||||
);
|
||||
const sortedHistoryDomains = computed(() =>
|
||||
sortHistoryDomains(currentBrowser.value?.historyDomains ?? [], historyDomainSortKey.value),
|
||||
);
|
||||
|
||||
watch(
|
||||
browsers,
|
||||
@@ -104,6 +99,9 @@ export function useBrowserManager() {
|
||||
watch(selectedBrowserId, () => {
|
||||
openProfileError.value = "";
|
||||
associatedProfilesModal.value = null;
|
||||
cleanupHistorySelectedProfiles.value = [];
|
||||
cleanupHistoryResults.value = [];
|
||||
cleanupHistoryError.value = "";
|
||||
});
|
||||
|
||||
async function loadBrowserConfigs() {
|
||||
@@ -284,21 +282,13 @@ export function useBrowserManager() {
|
||||
return name.trim().slice(0, 1).toUpperCase() || "?";
|
||||
}
|
||||
|
||||
function domainFromUrl(url: string) {
|
||||
try {
|
||||
return new URL(url).hostname;
|
||||
} catch {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
function sectionCount(section: ActiveSection) {
|
||||
if (!currentBrowser.value) return 0;
|
||||
if (section === "profiles") return currentBrowser.value.profiles.length;
|
||||
if (section === "extensions") return currentBrowser.value.extensions.length;
|
||||
if (section === "bookmarks") return currentBrowser.value.bookmarks.length;
|
||||
if (section === "passwords") return currentBrowser.value.passwordSites.length;
|
||||
return currentBrowser.value.historyDomains.length;
|
||||
return currentBrowser.value.stats.historyCleanupProfileCount;
|
||||
}
|
||||
|
||||
function showExtensionProfilesModal(extensionId: string) {
|
||||
@@ -334,17 +324,78 @@ export function useBrowserManager() {
|
||||
};
|
||||
}
|
||||
|
||||
function showHistoryDomainProfilesModal(domain: string) {
|
||||
const historyDomain = currentBrowser.value?.historyDomains.find(
|
||||
(item) => item.domain === domain,
|
||||
);
|
||||
if (!historyDomain || !currentBrowser.value) return;
|
||||
associatedProfilesModal.value = {
|
||||
title: `${historyDomain.domain} Profiles`,
|
||||
browserId: currentBrowser.value.browserId,
|
||||
profiles: historyDomain.profiles,
|
||||
isBookmark: false,
|
||||
};
|
||||
function toggleHistoryProfile(profileId: string) {
|
||||
if (cleanupHistorySelectedProfiles.value.includes(profileId)) {
|
||||
cleanupHistorySelectedProfiles.value = cleanupHistorySelectedProfiles.value.filter(
|
||||
(selectedId) => selectedId !== profileId,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
cleanupHistorySelectedProfiles.value = [
|
||||
...cleanupHistorySelectedProfiles.value,
|
||||
profileId,
|
||||
];
|
||||
}
|
||||
|
||||
function toggleAllHistoryProfiles() {
|
||||
const current = currentBrowser.value;
|
||||
if (!current) return;
|
||||
|
||||
const selectableIds = current.profiles
|
||||
.filter((profile) => {
|
||||
const cleanup = profile.historyCleanup;
|
||||
return (
|
||||
cleanup.history === "found" ||
|
||||
cleanup.topSites === "found" ||
|
||||
cleanup.visitedLinks === "found"
|
||||
);
|
||||
})
|
||||
.map((profile) => profile.id);
|
||||
|
||||
const allSelected =
|
||||
selectableIds.length > 0 &&
|
||||
selectableIds.every((profileId) =>
|
||||
cleanupHistorySelectedProfiles.value.includes(profileId),
|
||||
);
|
||||
|
||||
cleanupHistorySelectedProfiles.value = allSelected ? [] : selectableIds;
|
||||
}
|
||||
|
||||
async function cleanupHistoryProfiles(profileIds: string[]) {
|
||||
if (!currentBrowser.value || profileIds.length === 0) return;
|
||||
|
||||
historyCleanupBusy.value = true;
|
||||
cleanupHistoryError.value = "";
|
||||
cleanupHistoryResults.value = [];
|
||||
|
||||
try {
|
||||
const input: CleanupHistoryInput = {
|
||||
browserId: currentBrowser.value.browserId,
|
||||
profileIds,
|
||||
};
|
||||
const result = await invoke<CleanupHistoryResponse>("cleanup_history_files", { input });
|
||||
cleanupHistoryResults.value = result.results;
|
||||
cleanupHistorySelectedProfiles.value = cleanupHistorySelectedProfiles.value.filter(
|
||||
(profileId) => !profileIds.includes(profileId),
|
||||
);
|
||||
await scanBrowsers();
|
||||
} catch (cleanupErrorValue) {
|
||||
cleanupHistoryError.value =
|
||||
cleanupErrorValue instanceof Error
|
||||
? cleanupErrorValue.message
|
||||
: "Failed to clean history files.";
|
||||
} finally {
|
||||
historyCleanupBusy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function cleanupSelectedHistoryProfiles() {
|
||||
await cleanupHistoryProfiles(cleanupHistorySelectedProfiles.value);
|
||||
}
|
||||
|
||||
async function cleanupHistoryForProfile(profileId: string) {
|
||||
await cleanupHistoryProfiles([profileId]);
|
||||
}
|
||||
|
||||
function closeAssociatedProfilesModal() {
|
||||
@@ -369,11 +420,15 @@ export function useBrowserManager() {
|
||||
createCustomBrowserConfig,
|
||||
currentBrowser,
|
||||
deleteCustomBrowserConfig,
|
||||
domainFromUrl,
|
||||
error,
|
||||
extensionMonogram,
|
||||
extensionSortKey,
|
||||
historyDomainSortKey,
|
||||
cleanupHistoryError,
|
||||
cleanupHistoryForProfile,
|
||||
cleanupHistoryResults,
|
||||
cleanupHistorySelectedProfiles,
|
||||
cleanupSelectedHistoryProfiles,
|
||||
historyCleanupBusy,
|
||||
isDeletingConfig,
|
||||
isOpeningProfile,
|
||||
loading,
|
||||
@@ -390,13 +445,13 @@ export function useBrowserManager() {
|
||||
selectedBrowserId,
|
||||
showBookmarkProfilesModal,
|
||||
showExtensionProfilesModal,
|
||||
showHistoryDomainProfilesModal,
|
||||
showPasswordSiteProfilesModal,
|
||||
sortedBookmarks,
|
||||
sortedExtensions,
|
||||
sortedHistoryDomains,
|
||||
sortedPasswordSites,
|
||||
sortedProfiles,
|
||||
toggleAllHistoryProfiles,
|
||||
toggleHistoryProfile,
|
||||
closeAssociatedProfilesModal,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user