* chore: remove dead/unreferenced files across ui, vscode Remove 59 unused source files (components, hooks, lib utils, stores, barrels, and orphaned vscode github modules) that are not imported by any entry-reachable code. Also drop a stale test mock for the removed execCommands module. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * refactor: remove unused exported symbols (types, functions, consts, hooks) Remove exported symbols whose identifier is referenced nowhere in the repository (verified via repo-wide search), across ui types/contracts, lib utilities, sync layer, stores, and components. Also drop the few imports/private helpers orphaned by these removals. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * refactor: remove more unused exports (desktop, shortcuts, worktree, vscode) Continue removing repo-wide unreferenced exported functions, consts and types across lib/desktop, shortcuts, worktreeSessionCreator, sync, and vscode gitService, with cascading orphaned helpers/imports cleaned up. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * chore: add dead-code cleanup tooling * refactor: checkpoint dead-code cleanup * refactor: remove dead-code suppressions --------- Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
import { requestExistingFileAccess } from '@/lib/desktop';
|
|
import { isFilePathWithinDirectory, normalizeFilePath } from '@/lib/path-utils';
|
|
|
|
type OutsideFileGrantEntry = {
|
|
outsideFileGrant: string;
|
|
expiresAt: number;
|
|
};
|
|
|
|
const DEFAULT_GRANT_TTL_MS = 10 * 60 * 1000;
|
|
const grantsByPath = new Map<string, OutsideFileGrantEntry>();
|
|
|
|
export const getOutsideFileGrant = (path: string): string | undefined => {
|
|
const normalizedPath = normalizeFilePath(path);
|
|
if (!normalizedPath) {
|
|
return undefined;
|
|
}
|
|
|
|
const entry = grantsByPath.get(normalizedPath);
|
|
if (!entry) {
|
|
return undefined;
|
|
}
|
|
|
|
if (entry.expiresAt <= Date.now()) {
|
|
grantsByPath.delete(normalizedPath);
|
|
return undefined;
|
|
}
|
|
|
|
return entry.outsideFileGrant;
|
|
};
|
|
|
|
const rememberOutsideFileGrant = (
|
|
path: string,
|
|
outsideFileGrant: string,
|
|
expiresAt?: number,
|
|
): void => {
|
|
const normalizedPath = normalizeFilePath(path);
|
|
if (!normalizedPath || !outsideFileGrant) {
|
|
return;
|
|
}
|
|
|
|
grantsByPath.set(normalizedPath, {
|
|
outsideFileGrant,
|
|
expiresAt: typeof expiresAt === 'number' && Number.isFinite(expiresAt)
|
|
? expiresAt
|
|
: Date.now() + DEFAULT_GRANT_TTL_MS,
|
|
});
|
|
};
|
|
|
|
export const ensureOutsideFileGrantForDesktop = async (
|
|
path: string,
|
|
workspaceRoot: string,
|
|
): Promise<string | undefined> => {
|
|
const normalizedPath = normalizeFilePath(path);
|
|
if (!normalizedPath || !workspaceRoot || isFilePathWithinDirectory(normalizedPath, workspaceRoot)) {
|
|
return undefined;
|
|
}
|
|
|
|
const existing = getOutsideFileGrant(normalizedPath);
|
|
if (existing) {
|
|
return existing;
|
|
}
|
|
|
|
const result = await requestExistingFileAccess(normalizedPath);
|
|
if (!result.success || !result.path || !result.outsideFileGrant) {
|
|
return undefined;
|
|
}
|
|
|
|
rememberOutsideFileGrant(result.path, result.outsideFileGrant);
|
|
if (normalizeFilePath(result.path) !== normalizedPath) {
|
|
rememberOutsideFileGrant(normalizedPath, result.outsideFileGrant);
|
|
}
|
|
return result.outsideFileGrant;
|
|
};
|