From 800f07714000c20cc6f6b42c405c5e2f75b85694 Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Wed, 4 Nov 2026 15:03:37 +0100 Subject: [PATCH 1/8] feat: add the files sync contract and policies for files on this computer --- desktop-policies/Bulwark.admx | 19 ++ desktop-policies/de-DE/Bulwark.adml | 7 + desktop-policies/en-US/Bulwark.adml | 7 + .../org.bulwarkmail.desktop.mobileconfig | 6 + desktop-policies/policies.json | 3 + lib/desktop/__tests__/policy-schema.test.ts | 24 +- lib/desktop/policy-schema.ts | 63 ++++- lib/desktop/types.ts | 219 ++++++++++++++++++ lib/files-sync/types.ts | 131 +++++++++++ stores/files-sync-store.ts | 35 +++ 10 files changed, 512 insertions(+), 2 deletions(-) create mode 100644 lib/files-sync/types.ts create mode 100644 stores/files-sync-store.ts diff --git a/desktop-policies/Bulwark.admx b/desktop-policies/Bulwark.admx index 1b60d0497..d944d2db0 100644 --- a/desktop-policies/Bulwark.admx +++ b/desktop-policies/Bulwark.admx @@ -224,5 +224,24 @@ + + + + + + + + + + + + + + + + + + + diff --git a/desktop-policies/de-DE/Bulwark.adml b/desktop-policies/de-DE/Bulwark.adml index 2975e98f9..e9aa9a943 100644 --- a/desktop-policies/de-DE/Bulwark.adml +++ b/desktop-policies/de-DE/Bulwark.adml @@ -67,6 +67,12 @@ Wenn aktiviert oder nicht konfiguriert, trägt sich die App unter Windows in die Liste „Öffnen mit“ für gängige Dokumente und Bilder und in das Menü „Senden an“ ein, damit Benutzer eine Datei aus dem Dateimanager an eine neue Nachricht anhängen können. Sie wird nie zum Standardprogramm für diese Dateien. Wenn deaktiviert, entfernt die App diese Einträge für den Benutzer. Mail-Links und .eml-, .ics- und .vcf-Dateien sind nicht betroffen. Entwicklertools Dieselben Werte wie die gleichnamige Richtlinie von Chrome. 2: Die Entwicklertools sind aus und die Einstellung ist gesperrt. 0 oder 1 oder nicht konfiguriert: Benutzer können sie nach einer Warnung in den Einstellungen einschalten. Mit den Entwicklertools kann jeder an der Tastatur alles lesen, was die App enthält, auch E-Mails und Passwörter im Speicher. + Dateien als Laufwerk zulassen + Wenn aktiviert oder nicht konfiguriert, können Benutzer ihre Dateien im Dateimanager als Laufwerk anzeigen. Dateien werden beim Öffnen heruntergeladen. Vorerst nur unter Windows. Wenn deaktiviert, wird das Laufwerk nicht angeboten, und ein vorhandenes Laufwerk wird mit den Kopien der Dateien darin entfernt. Die Dateien auf dem Server sind davon nicht betroffen. + Synchronisieren von Ordnern mit Dateien zulassen + Wenn aktiviert oder nicht konfiguriert, können Benutzer einen Ordner auf dem Computer und einen Ordner in Dateien in beide Richtungen gleich halten. Wenn deaktiviert, wird dies nicht angeboten, und Ordner, die gerade synchronisiert werden, hören damit auf. Die Dateien in diesen Ordnern bleiben, wo sie sind. + Laufwerksbuchstabe für Dateien + Nur unter Windows. Ein Buchstabe von D bis Z gibt dem Laufwerk Dateien für jeden Benutzer diesen Buchstaben, und Benutzer können ihn nicht ändern. Geben Sie none ein, damit es nie einen Buchstaben bekommt. Wenn nicht konfiguriert, wählen Benutzer in den Einstellungen, und bis dahin gibt es keinen Buchstaben. Ein Wert, den die App nicht lesen kann, gilt als none. @@ -86,6 +92,7 @@ Adressen Wert (0, 1 oder 2) + diff --git a/desktop-policies/en-US/Bulwark.adml b/desktop-policies/en-US/Bulwark.adml index 9ae91340a..ade37900b 100644 --- a/desktop-policies/en-US/Bulwark.adml +++ b/desktop-policies/en-US/Bulwark.adml @@ -67,6 +67,12 @@ When enabled or not configured, the app adds itself to the "Open with" list for common documents and pictures and to the "Send to" menu on Windows, so people can attach a file to a new message from the file manager. It never becomes the default program for those files. When disabled, the app removes these entries for the user. Mail links and .eml, .ics and .vcf files are not affected. Developer tools The same values as Chrome's policy of this name. 2: developer tools are off and the setting is locked. 0 or 1, or not configured: people can turn them on under Settings, after a warning. Developer tools let anyone at the keyboard read everything the app holds, mail and passwords in memory included. + Allow Files as a drive + When enabled or not configured, people can show their Files in the file manager as a drive, with files downloaded when opened. Windows only for now. When disabled, the drive is not offered, and a drive that is already there is removed with the copies of files in it. Files on the server are not affected. + Allow syncing folders with Files + When enabled or not configured, people can keep a folder on the computer and a folder in Files the same, in both directions. When disabled, this is not offered and folders that sync now stop. The files in those folders stay where they are. + Drive letter for Files + Windows only. A letter from D to Z gives the Files drive that letter for every user, and they can't change it. Enter none to never give it a letter. When not configured, people choose under Settings, and there is no letter until they do. A value the app can't read counts as none. @@ -86,6 +92,7 @@ Addresses Value (0, 1 or 2) + diff --git a/desktop-policies/org.bulwarkmail.desktop.mobileconfig b/desktop-policies/org.bulwarkmail.desktop.mobileconfig index 23ddb522c..9658e41cc 100644 --- a/desktop-policies/org.bulwarkmail.desktop.mobileconfig +++ b/desktop-policies/org.bulwarkmail.desktop.mobileconfig @@ -69,6 +69,12 @@ DeveloperToolsAvailability 2 + FilesDriveEnabled + + FilesFolderSyncEnabled + + FilesDriveLetter + none Recommended UpdateChannel diff --git a/desktop-policies/policies.json b/desktop-policies/policies.json index 89dd1e510..40d390fc3 100644 --- a/desktop-policies/policies.json +++ b/desktop-policies/policies.json @@ -29,6 +29,9 @@ "BrowserSignIn": true, "OpenWithEnabled": true, "DeveloperToolsAvailability": 2, + "FilesDriveEnabled": true, + "FilesFolderSyncEnabled": true, + "FilesDriveLetter": "none", "Recommended": { "UpdateChannel": "stable" } diff --git a/lib/desktop/__tests__/policy-schema.test.ts b/lib/desktop/__tests__/policy-schema.test.ts index 07b11863c..1a73d1a85 100644 --- a/lib/desktop/__tests__/policy-schema.test.ts +++ b/lib/desktop/__tests__/policy-schema.test.ts @@ -32,7 +32,7 @@ describe('the schema', () => { 'PluginsMode', 'PluginAllowlist', 'OfflineEnabled', 'AppLockRequired', 'AppLockTimeoutMinutes', 'TelemetryAllowed', 'CrashReportsAllowed', 'QuickComposeShortcut', 'AuthServerAllowlist', 'AuthNegotiateDelegateAllowlist', 'AutoSelectCertificateForUrls', 'KeystoreEnabled', 'KeystoreAllowedOrigins', 'BrowserSignIn', 'WipeOfflineData', - 'OpenWithEnabled', 'DeveloperToolsAvailability', + 'OpenWithEnabled', 'DeveloperToolsAvailability', 'FilesDriveEnabled', 'FilesFolderSyncEnabled', 'FilesDriveLetter', ]); for (const key of POLICY_KEYS) { const { title, description } = POLICY_SCHEMA[key]; @@ -58,6 +58,28 @@ describe('developer tools and Open with', () => { }); }); +describe('Files on this computer', () => { + it('turn the drive and folder sync off only by force, and a value nobody can read leaves them off', () => { + for (const key of ['FilesDriveEnabled', 'FilesFolderSyncEnabled'] as const) { + expect(resolvePolicies(layers({}))[key]).toMatchObject({ value: true, locked: false }); + expect(resolvePolicies(layers({ recommendedUser: { [key]: 0 } }))[key]).toMatchObject({ value: true, locked: false }); + expect(resolvePolicies(layers({ forcedUser: { [key]: 0 } }))[key]).toMatchObject({ value: false, locked: true }); + expect(resolvePolicies(layers({ forcedMachine: { [key]: 'perhaps' } }))[key]).toMatchObject({ value: false, locked: true }); + } + }); + + it('takes a drive letter from D to Z or none, forced only, and a value nobody can read means no letter', () => { + expect(parsePolicyValue('FilesDriveLetter', 'x')).toEqual({ ok: true, value: 'X' }); + expect(parsePolicyValue('FilesDriveLetter', ' Q: ')).toEqual({ ok: true, value: 'Q' }); + expect(parsePolicyValue('FilesDriveLetter', 'NONE')).toEqual({ ok: true, value: 'none' }); + for (const bad of ['C', 'A:', 'B', 'QQ', 'Q:\\', '', 4, null]) expect(parsePolicyValue('FilesDriveLetter', bad).ok, String(bad)).toBe(false); + expect(resolvePolicies(layers({})).FilesDriveLetter).toMatchObject({ value: null, locked: false }); + expect(resolvePolicies(layers({ recommendedMachine: { FilesDriveLetter: 'R' } })).FilesDriveLetter).toMatchObject({ value: null, locked: false }); + expect(resolvePolicies(layers({ forcedMachine: { FilesDriveLetter: 'r' } })).FilesDriveLetter).toMatchObject({ value: 'R', locked: true }); + expect(resolvePolicies(layers({ forcedUser: { FilesDriveLetter: 'C' } })).FilesDriveLetter).toMatchObject({ value: 'none', locked: true }); + }); +}); + describe('precedence', () => { it('forced machine > forced user > recommended machine > recommended user > default', () => { const all = { diff --git a/lib/desktop/policy-schema.ts b/lib/desktop/policy-schema.ts index e3229f2dd..22535bbea 100644 --- a/lib/desktop/policy-schema.ts +++ b/lib/desktop/policy-schema.ts @@ -82,6 +82,9 @@ export interface PolicyValues { WipeOfflineData: string | null; OpenWithEnabled: boolean; DeveloperToolsAvailability: number | null; + FilesDriveEnabled: boolean; + FilesFolderSyncEnabled: boolean; + FilesDriveLetter: string | null; } export type PolicyKey = keyof PolicyValues; @@ -128,7 +131,7 @@ export type PolicyDefinition = PolicyBase & } | { type: 'string'; - format: 'instanceUrl' | 'shortcut' | 'hostList' | 'nonce'; + format: 'instanceUrl' | 'shortcut' | 'hostList' | 'nonce' | 'driveLetter'; default: null; maxLength: number; label: PolicyText; @@ -466,6 +469,47 @@ export const POLICY_SCHEMA: Record = { de: 'Dieselben Werte wie die gleichnamige Richtlinie von Chrome. 2: Die Entwicklertools sind aus und die Einstellung ist gesperrt. 0 oder 1 oder nicht konfiguriert: Benutzer können sie nach einer Warnung in den Einstellungen einschalten. Mit den Entwicklertools kann jeder an der Tastatur alles lesen, was die App enthält, auch E-Mails und Passwörter im Speicher.', }, }, + FilesDriveEnabled: { + category: 'system', + type: 'boolean', + default: true, + onInvalid: false, + forcedOnly: true, + sample: true, + title: { en: 'Allow Files as a drive', de: 'Dateien als Laufwerk zulassen' }, + description: { + en: 'When enabled or not configured, people can show their Files in the file manager as a drive, with files downloaded when opened. Windows only for now. When disabled, the drive is not offered, and a drive that is already there is removed with the copies of files in it. Files on the server are not affected.', + de: 'Wenn aktiviert oder nicht konfiguriert, können Benutzer ihre Dateien im Dateimanager als Laufwerk anzeigen. Dateien werden beim Öffnen heruntergeladen. Vorerst nur unter Windows. Wenn deaktiviert, wird das Laufwerk nicht angeboten, und ein vorhandenes Laufwerk wird mit den Kopien der Dateien darin entfernt. Die Dateien auf dem Server sind davon nicht betroffen.', + }, + }, + FilesFolderSyncEnabled: { + category: 'system', + type: 'boolean', + default: true, + onInvalid: false, + forcedOnly: true, + sample: true, + title: { en: 'Allow syncing folders with Files', de: 'Synchronisieren von Ordnern mit Dateien zulassen' }, + description: { + en: 'When enabled or not configured, people can keep a folder on the computer and a folder in Files the same, in both directions. When disabled, this is not offered and folders that sync now stop. The files in those folders stay where they are.', + de: 'Wenn aktiviert oder nicht konfiguriert, können Benutzer einen Ordner auf dem Computer und einen Ordner in Dateien in beide Richtungen gleich halten. Wenn deaktiviert, wird dies nicht angeboten, und Ordner, die gerade synchronisiert werden, hören damit auf. Die Dateien in diesen Ordnern bleiben, wo sie sind.', + }, + }, + FilesDriveLetter: { + category: 'system', + forcedOnly: true, + type: 'string', + format: 'driveLetter', + default: null, + maxLength: 8, + sample: 'none', + label: { en: 'Drive letter', de: 'Laufwerksbuchstabe' }, + title: { en: 'Drive letter for Files', de: 'Laufwerksbuchstabe für Dateien' }, + description: { + en: 'Windows only. A letter from D to Z gives the Files drive that letter for every user, and they can\'t change it. Enter none to never give it a letter. When not configured, people choose under Settings, and there is no letter until they do. A value the app can\'t read counts as none.', + de: 'Nur unter Windows. Ein Buchstabe von D bis Z gibt dem Laufwerk Dateien für jeden Benutzer diesen Buchstaben, und Benutzer können ihn nicht ändern. Geben Sie none ein, damit es nie einen Buchstaben bekommt. Wenn nicht konfiguriert, wählen Benutzer in den Einstellungen, und bis dahin gibt es keinen Buchstaben. Ein Wert, den die App nicht lesen kann, gilt als none.', + }, + }, }; export const POLICY_KEYS = Object.keys(POLICY_SCHEMA) as PolicyKey[]; @@ -617,6 +661,16 @@ export function pluginAllowedByPolicy(mode: PluginsMode, allowlist: readonly str const SHORTCUT = /^(?:(?:Command|Cmd|Control|Ctrl|CommandOrControl|CmdOrCtrl|Alt|Option|AltGr|Shift|Super|Meta)\+){1,4}(?:[A-Z0-9]|F[1-9]|F1[0-9]|F2[0-4]|Space|Tab|Enter|Backspace|Delete|Insert|Home|End|PageUp|PageDown|Up|Down|Left|Right|Plus|[-=,./;'`[\]\\])$/i; +/** A drive letter from D to Z, upper case, or `none`. */ +function parseDriveLetter(raw: unknown): Parsed { + if (typeof raw !== 'string') return fail('not_text'); + const text = raw.trim(); + if (text.toLowerCase() === 'none') return { ok: true, value: 'none' }; + const match = /^([D-Za-z]):?$/.exec(text); + if (!match || !/^[D-Z]$/i.test(match[1])) return fail('invalid_drive_letter'); + return { ok: true, value: match[1].toUpperCase() }; +} + function parseShortcut(raw: unknown): Parsed { if (typeof raw !== 'string') return fail('not_text'); const text = raw.trim(); @@ -796,6 +850,8 @@ export function parsePolicyValue(key: PolicyKey, raw: unknown, allowInsecure = f return parseHostList(raw); case 'nonce': return parseNonce(raw); + case 'driveLetter': + return parseDriveLetter(raw); } break; case 'list': @@ -821,6 +877,8 @@ function failClosedValue(key: PolicyKey): PolicyValues[PolicyKey] { if (definition.type === 'list') return [] as PolicyValues[PolicyKey]; // A shortcut nobody can read doesn't get the built-in one instead. if (definition.type === 'string' && definition.format === 'shortcut') return 'off' as PolicyValues[PolicyKey]; + // A drive letter nobody can read means no letter, not the user's own. + if (definition.type === 'string' && definition.format === 'driveLetter') return 'none' as PolicyValues[PolicyKey]; // A limit nobody can read is the tightest one, not the user's own. if (definition.type === 'integer') return (definition.onInvalid !== undefined ? definition.onInvalid : definition.min) as PolicyValues[PolicyKey]; return definition.default as PolicyValues[PolicyKey]; @@ -965,6 +1023,9 @@ export const POLICY_CONSUMERS: Record = { BrowserSignIn: { repo: 'shell', file: 'src/main/features/browser-sign-in.ts' }, OpenWithEnabled: { repo: 'shell', file: 'src/main/features/os-default-app.ts' }, DeveloperToolsAvailability: { repo: 'shell', file: 'src/main/features/dev-tools.ts' }, + FilesDriveEnabled: { repo: 'shell', file: 'src/main/features/files-drive.ts' }, + FilesFolderSyncEnabled: { repo: 'shell', file: 'src/main/features/files-folders.ts' }, + FilesDriveLetter: { repo: 'shell', file: 'src/main/features/files-drive.ts' }, }; /** The part the embedded server enforces. Sent to it by message. */ diff --git a/lib/desktop/types.ts b/lib/desktop/types.ts index 467f918d1..68891ca12 100644 --- a/lib/desktop/types.ts +++ b/lib/desktop/types.ts @@ -845,6 +845,223 @@ export interface DesktopEditBridge { onChange: (listener: (sessions: DesktopEditSession[]) => void) => () => void; } +/* + * Files on this computer: folders kept the same as a Files folder, and on Windows the + * Files drive (Cloud Files API placeholders). The sync engine is the page's + * (lib/files-sync in the webmail): it holds the JMAP session and decides. Main only does + * what the page can't: the disk, the folder picker, the OS's sync root, and the + * callbacks Windows makes when someone opens a file that isn't on the disk yet. + * + * Paths here are always relative to a root, with `/` between parts, never `..`, never + * absolute. Main resolves them inside the root and refuses anything that leaves it, + * through a link or otherwise. + */ + +/** A place on this computer kept the same as Files: a folder the user picked, or the drive. */ +export interface FilesRoot { + /** Main's id for it. Random, never a path. */ + id: string; + kind: 'folder' | 'drive'; + /** The page's local account id it belongs to. */ + account: string; + /** Where it is on disk, to show and nothing else. */ + path: string; + /** A folder: the Files folder it pairs with (null: the top of Files). The drive: null. */ + remoteId: string | null; + /** What the page called the Files side when it was added, to show. */ + remoteLabel: string; + paused: boolean; + createdAt: number; +} + +/** One file or folder under a root, as it is on disk now. */ +export interface FilesLocalEntry { + /** Relative to the root, `/` between parts. */ + path: string; + kind: 'file' | 'directory'; + size: number; + mtimeMs: number; + /** The same across a rename on the same volume (file id, inode), to tell a move from a delete and a create. */ + fileId: string; + /** The drive only: what the placeholder says. */ + placeholder?: FilesPlaceholderState; +} + +export interface FilesPlaceholderState { + /** The FileNode id written into it. Null for something made in Explorer that isn't a placeholder yet. */ + identity: string | null; + /** Main or the page marked it in sync and nobody changed it since. */ + inSync: boolean; + /** The content is on this disk. */ + hydrated: boolean; + pin: 'pinned' | 'unpinned' | 'unspecified'; +} + +/** What the page expects a path to be, so main refuses to act on something that changed meanwhile. */ +export interface FilesExpect { + fileId: string; + size: number; + mtimeMs: number; +} + +export type FilesError = + /** Not there. */ + | 'missing' + /** Something is already at the target. */ + | 'exists' + /** It changed since the page looked (`expect` didn't match). */ + | 'changed' + /** Another program has it open. */ + | 'busy' + | 'denied' + /** The path leaves the root, or goes through a link. */ + | 'outside' + /** A name this file system can't hold. */ + | 'name' + /** The disk is full. */ + | 'full' + /** The organisation's policy says no. */ + | 'policy' + /** No real click came with a call that needs one. */ + | 'gesture' + /** The user closed the picker. */ + | 'cancelled' + /** The folder is inside another root, holds one, or is a system folder. */ + | 'overlap' + /** The root is paused, gone, or the app is locked. */ + | 'inactive' + | 'unsupported' + | 'failed'; + +export type FilesResult = { ok: true; value: T } | { ok: false; error: FilesError }; + +/** Something on disk under a root changed. `paths: null`: too much at once, scan it all. */ +export interface FilesChangeEvent { + rootId: string; + paths: string[] | null; +} + +/** Windows wants bytes of a file that isn't on the disk yet: someone opened it. */ +export interface FilesFetchRequest { + fetchId: string; + rootId: string; + /** The FileNode id in the placeholder. */ + identity: string; + path: string; + /** What Windows asked for. Supplying from 0 to the end is always fine. */ + offset: number; + length: number; + /** The size in the placeholder. */ + total: number; +} + +/** A remote file or folder the drive should show, before any content is fetched. */ +export interface FilesPlaceholder { + path: string; + kind: 'file' | 'directory'; + size: number; + mtimeMs: number; + identity: string; +} + +export interface FilesDriveLetterState { + /** In use now. */ + letter: string | null; + /** The user's own choice, kept even while a policy overrides it. */ + chosen: string | null; + /** `FilesDriveLetter` forces it (a letter, or `none`). */ + locked: boolean; + /** Letters free now, D to Z. */ + available: string[]; +} + +export interface FilesDriveState { + /** Windows 10 1809 or later with the helper loaded. */ + supported: boolean; + /** `FilesDriveEnabled` is off. */ + forcedOff: boolean; + /** Accounts the user turned the drive on for, whether or not it's registered right now. */ + wanted: string[]; + letter: FilesDriveLetterState; +} + +/** + * What the main page takes once, in its first render (`files.claim()`), like `auth.claim`: + * a same-origin frame reaches the bridge through `parent`, and main can't tell its calls + * apart. Main also takes these calls only from the main window. + */ +export interface FilesControls { + roots: () => Promise; + /** Shows the OS folder picker. Needs a real click. */ + addFolder: (request: { account: string; remoteId: string | null; remoteLabel: string }) => Promise>; + /** A folder: forgotten, its files stay. The drive: as `drive.disable(account, 'user')`. */ + removeRoot: (rootId: string) => Promise; + setPaused: (rootId: string, paused: boolean) => Promise; + /** Everything under `under` (default: the whole root). Skips links and main's own temporary files. */ + scan: (rootId: string, under?: string) => Promise>; + stat: (rootId: string, path: string) => Promise>; + /** A URL the page fetches once for the file's bytes (Range works). Refused for a drive file that isn't on the disk. */ + openRead: (rootId: string, path: string) => Promise>; + /** + * Writing a file: chunks go to a temporary file next to it, `commitWrite` puts it in place + * if what's there is still `expect` (null: nothing may be there), and sets `mtimeMs`. + */ + beginWrite: (rootId: string, path: string, options: { expect: FilesExpect | null; mtimeMs: number; size: number }) => Promise>; + writeChunk: (writeId: string, data: Uint8Array) => Promise>; + commitWrite: (writeId: string) => Promise>; + abortWrite: (writeId: string) => Promise; + mkdir: (rootId: string, path: string) => Promise>; + /** Never overwrites. A case-only rename works on a case-insensitive disk. */ + move: (rootId: string, from: string, to: string, expect: FilesExpect | null) => Promise>; + /** A folder: to the OS's trash where it has one. Refused when it changed since `expect`. */ + remove: (rootId: string, path: string, expect: FilesExpect | null) => Promise>; + onChange: (listener: (event: FilesChangeEvent) => void) => () => void; + /** The engine's own record of a root (what both sides looked like at the last sync). */ + loadState: (rootId: string) => Promise; + saveState: (rootId: string, state: string) => Promise; + /** Opens Explorer, Finder or the file manager on it. */ + showInFolder: (rootId: string, path: string) => Promise; + /** Windows only. Absent elsewhere. */ + drive?: FilesDriveControls; +} + +export interface FilesDriveControls { + state: () => Promise; + onStateChange: (listener: (state: FilesDriveState) => void) => () => void; + /** + * Registers and connects the account's sync root. Needs a real click unless the user + * turned it on before (a sign-in brings it back). `label` is the address, shown when + * there are several accounts. + */ + enable: (account: string, label: string) => Promise>; + /** + * `user`: turned off. `signed-out`: the account signed out, and comes back at the next + * sign-in. `wipe` and `refused`: a wipe or a refused login. Each unregisters the sync root + * and deletes it with everything in it; only `signed-out` keeps the wish. + */ + disable: (account: string, reason: 'user' | 'signed-out' | 'wipe' | 'refused') => Promise; + /** New placeholders, parents first. One answer per entry. */ + place: (rootId: string, entries: FilesPlaceholder[]) => Promise>; + /** + * New metadata from the server for a placeholder that is in sync. `dehydrate`: the + * content changed, drop the copy on disk (a pinned one is fetched again). Refused + * with `changed` when someone edited it here meanwhile. + */ + update: (rootId: string, path: string, meta: { size: number; mtimeMs: number; identity: string; dehydrate: boolean }, expect: FilesExpect | null) => Promise>; + /** After an upload: makes it a placeholder with this identity if it isn't one, and marks it in sync. */ + markInSync: (rootId: string, path: string, identity: string, expect: FilesExpect) => Promise>; + onFetch: (listener: (request: FilesFetchRequest) => void) => () => void; + onFetchCancel: (listener: (fetchId: string) => void) => () => void; + /** Bytes for a fetch, in order from `offset`. False when Windows no longer wants them. */ + supply: (fetchId: string, offset: number, data: Uint8Array) => Promise; + fail: (fetchId: string, error: 'offline' | 'missing' | 'failed') => void; + setLetter: (letter: string | null) => Promise>; +} + +export interface FilesBridge { + claim: () => FilesControls | null; +} + export interface BulwarkDesktopBridge { version: number; platform: 'win32' | 'darwin' | 'linux'; @@ -874,6 +1091,8 @@ export interface BulwarkDesktopBridge { edit?: DesktopEditBridge; /** Absent on older shells. */ devTools?: DesktopDevToolsBridge; + /** Files on this computer. Absent on older shells. */ + files?: FilesBridge; } declare global { diff --git a/lib/files-sync/types.ts b/lib/files-sync/types.ts new file mode 100644 index 000000000..5e7cdb744 --- /dev/null +++ b/lib/files-sync/types.ts @@ -0,0 +1,131 @@ +/** + * Files on this computer, the page's side: what the sync engine reports and what the + * settings page and the Files screen can ask of it. The engine (lib/files-sync) keeps + * folders on disk and the Windows drive the same as Files; the desktop shell does the + * disk work (FilesControls in lib/desktop/types.ts). + * + * The store (stores/files-sync-store.ts) holds this state for the UI. The engine sets + * it and registers a controller there; the UI never talks to the bridge itself. + */ + +import type { FilesDriveLetterState, FilesDriveState, FilesResult, FilesRoot } from '@/lib/desktop/types'; + +export type FilesSyncRootState = + /** Reading both sides for the first time since the app started. */ + | 'starting' + | 'syncing' + /** Both sides are the same. */ + | 'idle' + | 'paused' + /** The server can't be reached; changes wait. */ + | 'offline' + | 'error' + /** A mass delete stopped it: the user has to say yes or no (`massDelete`). */ + | 'confirm-delete' + /** The organisation's policy stopped it. */ + | 'blocked'; + +export interface FilesSyncRootStatus { + rootId: string; + state: FilesSyncRootState; + /** Changes waiting to go either way. */ + pending: number; + /** Done in the current run. */ + done: number; + lastSyncedAt: number | null; + /** For `error`: a key in the `files_sync` namespace saying what went wrong. */ + errorKey?: string; + /** For `confirm-delete`: how many items would go, and where. */ + massDelete?: { count: number; side: 'local' | 'remote' }; +} + +export type FilesSyncActivityKind = + | 'uploaded' + | 'downloaded' + | 'folder-created' + | 'renamed' + | 'moved' + /** Deleted for good: the server has no trash, or it was deleted on this computer by the other side. */ + | 'deleted' + /** Into Files' trash, or the computer's. */ + | 'trashed' + /** Both sides changed. Neither is lost: `detail` is the name of the copy kept next to it. */ + | 'conflict' + /** A name this computer can't hold, shown under another name (`detail`). */ + | 'renamed-for-disk' + /** Bigger than the server takes. Stays on this computer only. `detail`: the limit in bytes. */ + | 'too-large' + /** Waiting for the server. */ + | 'waiting' + /** Stopped before deleting many items, see FilesSyncRootStatus.massDelete. */ + | 'mass-delete' + | 'error'; + +export interface FilesSyncActivity { + id: string; + at: number; + rootId: string; + kind: FilesSyncActivityKind; + /** `up`: to Files. `down`: to this computer. */ + direction: 'up' | 'down' | null; + /** Relative to the root, `/` between parts. */ + path: string; + detail?: string; + /** For `error` and `waiting`: a key in the `files_sync` namespace. */ + messageKey?: string; +} + +/** Where a FileNode is on this computer. */ +export interface FilesSyncCoverage { + rootId: string; + kind: 'folder' | 'drive'; + /** Relative to the root. */ + path: string; +} + +export type FilesSyncItemStatus = + /** The same on both sides. */ + | 'synced' + /** Going one way right now. */ + | 'syncing' + /** Waiting to go. */ + | 'pending' + | 'error' + /** The drive: only in Files, fetched when opened. */ + | 'online-only'; + +/** What the UI can ask of the engine. Registered by the engine in the store. */ +export interface FilesSyncController { + /** Shows the folder picker; needs the click it came from. */ + addFolder: (remoteId: string | null, remoteLabel: string) => Promise>; + /** A folder stops syncing; its files stay. The drive: turned off. */ + removeRoot: (rootId: string) => Promise; + setPaused: (rootId: string, paused: boolean) => Promise; + /** Answer to `confirm-delete`. No: the deleted items come back from the other side. */ + confirmMassDelete: (rootId: string, allow: boolean) => Promise; + /** The current account's drive. */ + setDriveEnabled: (enabled: boolean) => Promise>; + setDriveLetter: (letter: string | null) => Promise>; + /** Where a FileNode of the current account is on this computer, if a root covers it. */ + coverage: (nodeId: string) => FilesSyncCoverage | null; + /** Explorer, Finder or the file manager, on that file or folder. */ + showInFolder: (nodeId: string) => Promise; + clearActivity: () => void; +} + +export interface FilesSyncSnapshot { + /** In the desktop app, with a shell that has the files bridge, in the main window. */ + available: boolean; + /** The local account the engine runs for, or null when nobody is signed in. */ + account: string | null; + roots: FilesRoot[]; + status: Record; + /** Newest first, capped. */ + activity: FilesSyncActivity[]; + /** Null off Windows or on an older shell. */ + drive: FilesDriveState | null; + /** `FilesFolderSyncEnabled` is off. */ + folderSyncForcedOff: boolean; + /** Per FileNode id of the current account, for rows in the Files screen. */ + items: Record; +} diff --git a/stores/files-sync-store.ts b/stores/files-sync-store.ts new file mode 100644 index 000000000..a6f1af6af --- /dev/null +++ b/stores/files-sync-store.ts @@ -0,0 +1,35 @@ +import { create } from 'zustand'; +import type { FilesSyncController, FilesSyncSnapshot } from '@/lib/files-sync/types'; + +/** + * Files on this computer, for the UI: the engine (lib/files-sync) writes the snapshot + * and registers its controller; the settings page and the Files screen read it and + * call the controller. Nothing here touches the bridge. + */ +interface FilesSyncStore extends FilesSyncSnapshot { + controller: FilesSyncController | null; + /** The engine's: replaces what it says changed. */ + publish: (patch: Partial) => void; + setController: (controller: FilesSyncController | null) => void; + /** Back to nothing: signed out, or the engine stopped. */ + reset: () => void; +} + +const EMPTY: FilesSyncSnapshot = { + available: false, + account: null, + roots: [], + status: {}, + activity: [], + drive: null, + folderSyncForcedOff: false, + items: {}, +}; + +export const useFilesSyncStore = create((set) => ({ + ...EMPTY, + controller: null, + publish: (patch) => set(patch), + setController: (controller) => set({ controller }), + reset: () => set({ ...EMPTY, controller: null }), +})); From 62ab5cbb7632d8bd62d662fb14ff3edeffc4940a Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:40:03 +0100 Subject: [PATCH 2/8] feat: add a Files on this computer settings page to the desktop app The settings nav test drew every page but recovery; the new page waits for the desktop app's sync engine like recovery waits for its probe, so the test leaves it out too and a new test checks it shows while the engine runs. --- app/boot-skeleton.css | 2 + .../boot-skeleton/settings-skeleton.tsx | 2 + components/files-sync/files-sync-prompts.tsx | 156 ++++++++ .../files-sync/files-sync-status-line.tsx | 60 +++ components/files-sync/files-sync-text.ts | 46 +++ .../__tests__/desktop-files-settings.test.tsx | 314 ++++++++++++++++ .../__tests__/settings-boot-skeleton.test.tsx | 19 +- .../settings-search-anchors.test.tsx | 17 +- .../settings/desktop-files-settings.tsx | 346 ++++++++++++++++++ components/settings/settings-app.tsx | 6 + components/settings/settings-tab-icons.ts | 4 +- lib/settings-search.ts | 11 + lib/settings-tabs.ts | 2 +- locales/ar/common.json | 106 ++++++ locales/ca/common.json | 106 ++++++ locales/cs/common.json | 106 ++++++ locales/da/common.json | 106 ++++++ locales/de/common.json | 106 ++++++ locales/en/common.json | 106 ++++++ locales/es/common.json | 106 ++++++ locales/et/common.json | 106 ++++++ locales/fa/common.json | 106 ++++++ locales/fr/common.json | 106 ++++++ locales/he/common.json | 106 ++++++ locales/hu/common.json | 106 ++++++ locales/it/common.json | 106 ++++++ locales/ja/common.json | 106 ++++++ locales/ko/common.json | 106 ++++++ locales/lv/common.json | 106 ++++++ locales/mn/common.json | 106 ++++++ locales/nb/common.json | 106 ++++++ locales/nl/common.json | 106 ++++++ locales/pl/common.json | 106 ++++++ locales/pt/common.json | 106 ++++++ locales/ro/common.json | 106 ++++++ locales/ru/common.json | 106 ++++++ locales/sk/common.json | 106 ++++++ locales/th/common.json | 106 ++++++ locales/tr/common.json | 106 ++++++ locales/uk/common.json | 106 ++++++ locales/vi/common.json | 106 ++++++ locales/zh-TW/common.json | 106 ++++++ locales/zh/common.json | 106 ++++++ 43 files changed, 4158 insertions(+), 7 deletions(-) create mode 100644 components/files-sync/files-sync-prompts.tsx create mode 100644 components/files-sync/files-sync-status-line.tsx create mode 100644 components/files-sync/files-sync-text.ts create mode 100644 components/settings/__tests__/desktop-files-settings.test.tsx create mode 100644 components/settings/desktop-files-settings.tsx diff --git a/app/boot-skeleton.css b/app/boot-skeleton.css index dbf7543cf..0592e4bfd 100644 --- a/app/boot-skeleton.css +++ b/app/boot-skeleton.css @@ -220,6 +220,7 @@ [data-boot-settings-tab="calendar"] [data-sk-settings-tab="calendar"], [data-boot-settings-tab="contacts"] [data-sk-settings-tab="contacts"], [data-boot-settings-tab="files"] [data-sk-settings-tab="files"], + [data-boot-settings-tab="files_sync"] [data-sk-settings-tab="files_sync"], [data-boot-settings-tab="addons"] [data-sk-settings-tab="addons"], [data-boot-settings-tab="offline"] [data-sk-settings-tab="offline"], [data-boot-settings-tab="privacy"] [data-sk-settings-tab="privacy"], @@ -239,6 +240,7 @@ @custom-variant boot-no-settings-addons (&:where([data-boot-settings-tabs]:not([data-boot-settings-tabs~="addons"]) *)); @custom-variant boot-no-settings-offline (&:where([data-boot-settings-tabs]:not([data-boot-settings-tabs~="offline"]) *)); @custom-variant boot-settings-recovery (&:where([data-boot-settings-tabs~="recovery"] *)); +@custom-variant boot-settings-files-sync (&:where([data-boot-settings-tabs~="files_sync"] *)); /* Settings pages with one section have no section jump row (SectionNav). */ @custom-variant boot-settings-one-section (&:where([data-boot-settings-tab="security"] *, [data-boot-settings-tab="filters"] *, [data-boot-settings-tab="vacation"] *, [data-boot-settings-tab="recovery"] *, [data-boot-settings-tab="addons"] *)); diff --git a/components/boot-skeleton/settings-skeleton.tsx b/components/boot-skeleton/settings-skeleton.tsx index c49515063..82477c6bb 100644 --- a/components/boot-skeleton/settings-skeleton.tsx +++ b/components/boot-skeleton/settings-skeleton.tsx @@ -27,6 +27,8 @@ const OPTIONAL: Partial> = { calendar: "boot-no-calendar:hidden boot-no-settings-calendar:hidden", contacts: "boot-no-settings-contacts:hidden", files: "boot-no-files:hidden boot-no-settings-files:hidden", + // Desktop app only, while the files sync runs. + files_sync: "hidden boot-settings-files-sync:flex", addons: "boot-no-settings-addons:hidden", // Not in the static Lite build. offline: "boot-no-settings-offline:hidden", diff --git a/components/files-sync/files-sync-prompts.tsx b/components/files-sync/files-sync-prompts.tsx new file mode 100644 index 000000000..fdf938506 --- /dev/null +++ b/components/files-sync/files-sync-prompts.tsx @@ -0,0 +1,156 @@ +"use client"; + +import { useEffect, useState, useSyncExternalStore } from "react"; +import { useTranslations } from "next-intl"; +import { AlertTriangle } from "@/components/icons"; +import { Button } from "@/components/ui/button"; +import { Dialog } from "@/components/ui/dialog"; +import { useFilesSyncStore } from "@/stores/files-sync-store"; +import type { FilesRoot } from "@/lib/desktop/types"; +import type { FilesSyncRootStatus } from "@/lib/files-sync/types"; +import { rootName } from "./files-sync-text"; + +/* + * The mass-delete question (FILES-SYNC-BRIEF: more than 50 items or more than half a + * pair at once pauses the pair and asks). The settings page asks it in the folder's + * row; everywhere else FilesSyncPrompts asks it in a dialog, so the user sees it + * wherever they are. + */ + +let inlineHosts = 0; +const inlineListeners = new Set<() => void>(); +const subscribeInline = (listener: () => void) => { + inlineListeners.add(listener); + return () => { inlineListeners.delete(listener); }; +}; +const inlineShown = () => inlineHosts > 0; + +/** The settings page asks in its rows while it's open: the dialog stays away meanwhile. */ +export function useInlineMassDeleteQuestions(): void { + useEffect(() => { + inlineHosts += 1; + inlineListeners.forEach((listener) => listener()); + return () => { + inlineHosts -= 1; + inlineListeners.forEach((listener) => listener()); + }; + }, []); +} + +/** The question's text, for a root in `confirm-delete`. */ +export function useMassDeleteText(root: FilesRoot, massDelete: NonNullable): string { + const t = useTranslations("files_sync"); + // The side the items went from: this computer's folder, or the Files folder. + return massDelete.side === "local" + ? t("mass_delete.local", { count: massDelete.count, folder: rootName(root, t("drive.root_name")) }) + : t("mass_delete.remote", { count: massDelete.count, folder: root.remoteLabel || t("drive.root_name") }); +} + +interface AnswerButtonsProps { + rootId: string; + count: number; + /** After an answer went out. */ + onAnswered?: () => void; +} + +/** "Delete them" and "Bring them back", straight to the engine. */ +export function MassDeleteAnswers({ rootId, count, onAnswered }: AnswerButtonsProps) { + const t = useTranslations("files_sync"); + const controller = useFilesSyncStore((s) => s.controller); + const [busy, setBusy] = useState(false); + const answer = (allow: boolean) => { + if (!controller) return; + setBusy(true); + void controller.confirmMassDelete(rootId, allow).catch(() => {}).finally(() => { + setBusy(false); + onAnswered?.(); + }); + }; + return ( + <> + + + + ); +} + +/** The question inside a folder's row on the settings page. */ +export function MassDeleteQuestion({ root, status }: { root: FilesRoot; status: FilesSyncRootStatus }) { + const massDelete = status.massDelete ?? { count: 0, side: "local" as const }; + const text = useMassDeleteText(root, massDelete); + return ( +
+

+

+
+ +
+
+ ); +} + +function PromptDialog({ root, status, onLater }: { root: FilesRoot; status: FilesSyncRootStatus; onLater: () => void }) { + const t = useTranslations("files_sync"); + const massDelete = status.massDelete!; + const text = useMassDeleteText(root, massDelete); + return ( + +