mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-07-20 18:08:55 +00:00
Phase 2 of #8228. Closes the renderer-supplied-absolute-path hole: the file-sync IPCs now take a relative path; main resolves it against a sync folder it owns and never trusts the renderer's copy of. Main side - sync-folder-store: persists the path in simple-store (still inside userData, still renderer-unreachable via assertPathOutside) with an in-memory cache so per-IPC lookup doesn't stat the file every call. initSyncFolderStore() is fire-and-forget at adapter init; each handler awaits it defensively because it's idempotent via _loadOnce. - FILE_SYNC_SAVE/LOAD/REMOVE: accept { relativePath, ... }, pass through resolveSyncPath, write/read/delete the vetted absolute path. - CHECK_DIR_EXISTS and FILE_SYNC_LIST_FILES: accept an optional relativePath; default to the sync root itself so the existing "is the sync folder reachable?" check still works. - PICK_DIRECTORY: now persists the chosen folder via setSyncFolderPath before returning the display string to the renderer. The renderer receiving the string is no longer load-bearing — it's display only. - New GET_SYNC_FOLDER_PATH IPC returns the current value for display (settings form, "sync folder: …" labels). - TO_FILE_URL: pulls in the assertPathOutside(userData) backstop that was missing on master, so a userData path cannot be laundered into a file:// URL that later flows through READ_LOCAL_IMAGE_AS_DATA_URL or the navigation guard. Package (@sp/sync-providers/local-file) - LocalFileSyncElectron.isReady now asks main (getMainSyncFolderPath dep) instead of reading the renderer's privateCfg. This drives the migration UX: an existing install with a legacy privateCfg value but no main-side path lands on "not configured" and gets re-prompted by the picker. A one-cycle "please pick again" is the migration cost; we decided against silently promoting the renderer's persisted value because it could be tampered with. - getFilePath returns the *relative* path (no absolute folder prefix). The leading-slash strip is preserved so existing call sites that prepend '/' still work. - pickDirectory no longer writes to renderer privateCfg — main owns persistence. The dep contract still returns the display string. - The privateCfg.syncFolderPath field is marked @deprecated; the field is kept for migration of older configs and may be removed in a later pass once the migration has rolled out. Renderer - ElectronFileAdapter forwards the relative path verbatim to the IPC. - The renderer's LocalFileSyncElectron deps wire pickDirectory and the new getMainSyncFolderPath to the bridge. Tests - electron/local-file-sync.test.cjs rewritten for the new signatures: happy path, traversal escapes, absolute-relativePath rejection, sync-folder-equals-userData rejection (grant-file forgery defense), PICK persists main-side, GET returns the configured path, TO_FILE_URL refuses userData. - electron/sync-folder-store.test.cjs covers persistence, init-before-get throw, null/empty handling, idempotent set. - The package's local-file-sync-electron.spec.ts is updated for the new deps shape and asserts the package no longer writes to the renderer credential store. All 56 electron-side tests pass; 374 sync-providers tests pass.
256 lines
6.5 KiB
TypeScript
256 lines
6.5 KiB
TypeScript
import { IpcRendererEvent } from 'electron';
|
|
import {
|
|
GlobalConfigState,
|
|
TakeABreakConfig,
|
|
TaskWidgetConfig,
|
|
} from '../src/app/features/config/global-config.model';
|
|
import { KeyboardConfig } from '../src/app/features/config/keyboard-config.model';
|
|
import { JiraCfg } from '../src/app/features/issue/providers/jira/jira.model';
|
|
import { AppDataCompleteLegacy } from '../src/app/imex/sync/sync.model';
|
|
import { Task } from '../src/app/features/tasks/task.model';
|
|
import { LocalBackupMeta } from '../src/app/imex/local-backup/local-backup.model';
|
|
import { AppDataComplete } from '../src/app/op-log/model/model-config';
|
|
import {
|
|
PluginNodeScriptRequest,
|
|
PluginNodeScriptResult,
|
|
} from '../packages/plugin-api/src/types';
|
|
import {
|
|
LocalRestApiRequestPayload,
|
|
LocalRestApiResponsePayload,
|
|
} from './shared-with-frontend/local-rest-api.model';
|
|
import { ElectronDistChannel } from './shared-with-frontend/get-dist-channel';
|
|
|
|
export interface PluginNodeExecutionElectronApi {
|
|
requestGrant(pluginId: string): Promise<{ token: string } | null>;
|
|
executeScript(
|
|
pluginId: string,
|
|
grantToken: string,
|
|
request: PluginNodeScriptRequest,
|
|
): Promise<PluginNodeScriptResult>;
|
|
revokeGrant(pluginId: string, grantToken: string): Promise<void>;
|
|
}
|
|
|
|
export interface ElectronAPI {
|
|
on(
|
|
channel: string,
|
|
listener: (event: IpcRendererEvent, ...args: unknown[]) => void,
|
|
): void;
|
|
|
|
// SYNC
|
|
// ----
|
|
getDistChannel(): ElectronDistChannel | null;
|
|
|
|
// INVOKE
|
|
// ------
|
|
getUserDataPath(): Promise<string>;
|
|
|
|
getBackupPath(): Promise<string>;
|
|
|
|
checkBackupAvailable(): Promise<false | LocalBackupMeta>;
|
|
|
|
loadBackupData(backupPath: string): Promise<string>;
|
|
|
|
fileSyncSave(args: {
|
|
relativePath: string;
|
|
localRev: string | null;
|
|
dataStr: string;
|
|
}): Promise<string | Error>;
|
|
|
|
fileSyncLoad(args: {
|
|
relativePath: string;
|
|
localRev: string | null;
|
|
}): Promise<{ rev: string; dataStr: string | undefined } | Error>;
|
|
|
|
fileSyncRemove(args: { relativePath: string }): Promise<unknown | Error>;
|
|
|
|
fileSyncListFiles(args: { relativePath?: string }): Promise<string[] | Error>;
|
|
|
|
checkDirExists(args: { relativePath?: string }): Promise<true | Error>;
|
|
|
|
pickDirectory(): Promise<string | undefined>;
|
|
|
|
/**
|
|
* Returns the main-owned sync folder path for display, or null if not yet
|
|
* configured. The renderer must not pass this value back to file-sync IPCs
|
|
* — those take only the relative path; main resolves against its own copy.
|
|
*/
|
|
getSyncFolderPath(): Promise<string | null>;
|
|
|
|
showOpenDialog(options: {
|
|
properties: string[];
|
|
title?: string;
|
|
defaultPath?: string;
|
|
filters?: { name: string; extensions: string[] }[];
|
|
}): Promise<string[] | undefined>;
|
|
|
|
toFileUrl(filePath: string): Promise<string>;
|
|
|
|
readLocalImageAsDataUrl(filePathOrUrl: string): Promise<string | null>;
|
|
|
|
// checkDirExists(dirPath: string): Promise<true | Error>;
|
|
|
|
// STANDARD
|
|
// --------
|
|
setZoomFactor(zoomFactor: number): void;
|
|
|
|
getZoomFactor(): number;
|
|
|
|
openPath(path: string): void;
|
|
|
|
openExternalUrl(url: string): void;
|
|
|
|
saveFileDialog(
|
|
filename: string,
|
|
data: string,
|
|
): Promise<{ success: boolean; path?: string }>;
|
|
|
|
shareNative(payload: {
|
|
text?: string;
|
|
url?: string;
|
|
title?: string;
|
|
files?: string[];
|
|
}): Promise<{ success: boolean; error?: string }>;
|
|
|
|
isLinux(): boolean;
|
|
|
|
isGnomeDesktop(): boolean;
|
|
|
|
isMacOS(): boolean;
|
|
|
|
isAppleSilicon(): boolean;
|
|
|
|
isSnap(): boolean;
|
|
|
|
isFlatpak(): boolean;
|
|
|
|
// CLIPBOARD IMAGES
|
|
// ----------------
|
|
saveClipboardImage(
|
|
basePath: string,
|
|
fileName: string,
|
|
base64Data: string,
|
|
mimeType: string,
|
|
): Promise<string>;
|
|
|
|
loadClipboardImage(
|
|
basePath: string,
|
|
imageId: string,
|
|
): Promise<{ base64: string; mimeType: string } | null>;
|
|
|
|
deleteClipboardImage(basePath: string, imageId: string): Promise<boolean>;
|
|
|
|
listClipboardImages(
|
|
basePath: string,
|
|
): Promise<{ id: string; mimeType: string; createdAt: number; size: number }[]>;
|
|
|
|
getClipboardImagePath(basePath: string, imageId: string): Promise<string | null>;
|
|
|
|
getClipboardFilePaths(): Promise<string[]>;
|
|
copyClipboardImageFile(
|
|
basePath: string,
|
|
filePath: string,
|
|
): Promise<{
|
|
id: string;
|
|
mimeType: string;
|
|
size: number;
|
|
createdAt: number;
|
|
} | null>;
|
|
|
|
readClipboardImage(basePath: string): Promise<{
|
|
id: string;
|
|
mimeType: string;
|
|
size: number;
|
|
createdAt: number;
|
|
} | null>;
|
|
|
|
getPathForFile(file: File): string | null;
|
|
|
|
// SEND
|
|
// ----
|
|
reloadMainWin(): void;
|
|
|
|
openDevTools(): void;
|
|
|
|
showEmojiPanel(): void;
|
|
|
|
relaunch(): void;
|
|
|
|
exit(exitCode: number): void;
|
|
|
|
shutdownNow(): void;
|
|
|
|
flashFrame(): void;
|
|
|
|
showOrFocus(): void;
|
|
|
|
lockScreen(): void;
|
|
|
|
informAboutAppReady(): void;
|
|
|
|
scheduleRegisterBeforeClose(id: string): void;
|
|
|
|
unscheduleRegisterBeforeClose(id: string): void;
|
|
|
|
setDoneRegisterBeforeClose(id: string): void;
|
|
|
|
setProgressBar(args: {
|
|
progress: number;
|
|
progressBarMode: 'normal' | 'pause' | 'none';
|
|
}): void;
|
|
|
|
sendAppSettingsToElectron(globalCfg: GlobalConfigState): void;
|
|
|
|
sendSettingsUpdate(globalCfg: GlobalConfigState): void;
|
|
|
|
updateTaskWidgetSettings(cfg: TaskWidgetConfig): void;
|
|
|
|
updateTitleBarDarkMode(isDarkMode: boolean): void;
|
|
|
|
registerGlobalShortcuts(keyboardConfig: KeyboardConfig): void;
|
|
|
|
showFullScreenBlocker(args: { msg?: string; takeABreakCfg: TakeABreakConfig }): void;
|
|
|
|
// TODO use invoke instead
|
|
makeJiraRequest(args: {
|
|
requestId: string;
|
|
url: string;
|
|
requestInit: RequestInit;
|
|
jiraCfg: JiraCfg;
|
|
}): void;
|
|
|
|
jiraSetupImgHeaders(args: { jiraCfg: JiraCfg }): void;
|
|
|
|
backupAppData(args: {
|
|
data: AppDataCompleteLegacy | AppDataComplete;
|
|
maxBackupFiles?: number | null;
|
|
}): void;
|
|
|
|
updateCurrentTask(
|
|
task: Task | null,
|
|
isPomodoroEnabled: boolean,
|
|
currentPomodoroSessionTime: number,
|
|
isFocusModeEnabled?: boolean,
|
|
currentFocusSessionTime?: number,
|
|
focusModeMode?: string,
|
|
);
|
|
|
|
updateTodayTasks(
|
|
tasks: { id: string; title: string; timeEstimate: number; timeSpent: number }[],
|
|
): void;
|
|
|
|
onSwitchTask(listener: (taskId: string) => void): void;
|
|
|
|
exec(command: string): void;
|
|
|
|
consumePluginNodeExecutionApi(): PluginNodeExecutionElectronApi | null;
|
|
|
|
// Plugin OAuth
|
|
pluginOAuthPrepare(): Promise<{ port: number }>;
|
|
pluginOAuthStart(url: string): void;
|
|
onPluginOAuthCb(
|
|
listener: (data: { code?: string; error?: string; state?: string }) => void,
|
|
): void;
|
|
|
|
onLocalRestApiRequest(listener: (payload: LocalRestApiRequestPayload) => void): void;
|
|
sendLocalRestApiResponse(payload: LocalRestApiResponsePayload): void;
|
|
}
|