diff --git a/AGENTS.md b/AGENTS.md index 2f0fa9b3cd..0ff0e881e5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -30,6 +30,9 @@ npm run prettier # multi-file format npm run lint # multi-file lint npm test # all unit tests (Jasmine/Karma, .spec.ts co-located) npm run test:file # single spec +npm run test:electron # main-process tests — `electron/*.test.cjs`, NOT .spec.ts + # (tsconfig.electron.json excludes *.spec.ts, so a spec + # placed under electron/ silently never runs) npm run e2e # all E2E (Playwright, slow) npm run e2e:file -- --retries=0 # single E2E (~20s/test); add --grep "name" for one test npm start # Electron dev diff --git a/docs/wiki/2.09-Configure-Sync-Backend.md b/docs/wiki/2.09-Configure-Sync-Backend.md index 6ff4005f36..b5678a733b 100755 --- a/docs/wiki/2.09-Configure-Sync-Backend.md +++ b/docs/wiki/2.09-Configure-Sync-Backend.md @@ -17,6 +17,7 @@ The rest of the form depends on the selected provider. Common options (sync inte - **Info:** The app shows a short note that SuperSync keeps your tasks in sync across devices in real time and that data is stored on the sync server. SuperSync is currently in Beta. - **Get a token:** Click **Open Server & Get Token** to open the server login page in your browser. After logging in, copy your access token. - **Access Token:** Paste the token into the **Access Token** field. Required for SuperSync. +- **Multiple devices:** You can reuse the same access token on every device or sign in separately on each device to get another token. Both options connect to the same SuperSync account and synchronize the same data. Do not use **Revoke & Replace Token** when adding a device; it invalidates all existing tokens and disconnects every device. - **Advanced:** Under **Advanced**, you can set a custom **Server URL** (leave as-is for the official server). Here you can also **Enable Encryption** for end-to-end encryption; the app shows warnings about password loss and server data being replaced. - **Encryption:** If encryption is enabled, you can **Change Password** or **Disable Encryption** from the same form. These actions replace server data and require the same password on all devices (or re-upload with a new password). @@ -42,6 +43,7 @@ OneDrive sync requires your own **Microsoft Entra** (Azure AD) app registration - **Android / manual fallback:** `https://login.microsoftonline.com/common/oauth2/nativeclient` Do **not** register these under the **Web** or **Single-page application (SPA)** platforms — token redemption then fails with `HTTP 400` (e.g. `AADSTS9002327`). + 2. **Allow public client flows:** In **Authentication**, set **Allow public client flows** to **Yes**. Super Productivity authenticates with PKCE and sends no client secret; if this is **No**, sign-in appears to succeed but the token step fails with `HTTP 400 Bad Request` (`AADSTS7000218: ... 'client_assertion' or 'client_secret'`). 3. **API permissions:** Under **API permissions**, add the Microsoft Graph **delegated** permissions `Files.ReadWrite.AppFolder` and `offline_access`. diff --git a/docs/wiki/3.06-User-Data.md b/docs/wiki/3.06-User-Data.md index 0e65964db5..c8047647f0 100644 --- a/docs/wiki/3.06-User-Data.md +++ b/docs/wiki/3.06-User-Data.md @@ -41,7 +41,7 @@ For Snap packages on Linux, the app uses the `SNAP_USER_COMMON` directory so tha ### Windows Store -The Windows Store build uses a different path that includes the Windows Store package identifier (under `Local\Packages\...\LocalCache\Roaming` instead of `Roaming`). +The Windows Store build may use a different path that includes the Windows Store package identifier (under `Local\Packages\...\LocalCache\Roaming` instead of `Roaming`). This depends on whether Windows virtualizes the package: virtualized packages have their `AppData` writes redirected into `LocalCache`, while full-trust ones write to the plain `Roaming` path. Settings shows whichever location actually exists on your machine, so check there rather than assuming either one. ## Directory Structure diff --git a/electron/backup.test.cjs b/electron/backup.test.cjs new file mode 100644 index 0000000000..885be47eab --- /dev/null +++ b/electron/backup.test.cjs @@ -0,0 +1,110 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const path = require('node:path'); +const Module = require('node:module'); + +require('ts-node/register/transpile-only'); + +const originalModuleLoad = Module._load; +const backupModulePath = path.resolve(__dirname, 'backup.ts'); + +// Windows-shaped so the `.replace('Roaming', ...)` derivation actually fires on +// Linux/macOS CI too — otherwise BACKUP_DIR_WINSTORE would equal BACKUP_DIR and +// every assertion below would pass vacuously. +const USER_DATA = 'C:\\Users\\testuser\\AppData\\Roaming\\superProductivity'; +// path.join, like the module under test — the separator is the host's, not '\'. +const BACKUP_DIR = path.join(USER_DATA, 'backups'); +const BACKUP_DIR_WINSTORE = BACKUP_DIR.replace( + 'Roaming', + 'Local\\Packages\\53707johannesjo.SuperProductivity_ch45amy23cdv6\\LocalCache\\Roaming', +); + +let existingPaths; + +const resetModule = () => { + delete require.cache[backupModulePath]; +}; + +const installMocks = () => { + Module._load = function patchedLoad(request, parent, isMain) { + if (request === 'electron') { + return { + app: { getPath: () => USER_DATA }, + ipcMain: { on: () => {}, handle: () => {} }, + }; + } + + if (request === 'electron-log/main') { + return { log: () => {}, error: () => {} }; + } + + // Scoped to backup.ts so ts-node / node:test keep the real fs. + if ( + request === 'fs' && + parent && + typeof parent.filename === 'string' && + parent.filename.endsWith('backup.ts') + ) { + const realFs = originalModuleLoad.call(this, request, parent, isMain); + return { ...realFs, existsSync: (p) => existingPaths.has(p) }; + } + + return originalModuleLoad.call(this, request, parent, isMain); + }; +}; + +const loadBackupModule = () => { + resetModule(); + // eslint-disable-next-line @typescript-eslint/no-var-requires + return require(backupModulePath); +}; + +test.beforeEach(() => { + existingPaths = new Set(); + installMocks(); +}); + +test.afterEach(() => { + Module._load = originalModuleLoad; + delete process.windowsStore; + resetModule(); +}); + +// Sanity check: without this the Windows-only branches below could never be +// reached on a Linux CI runner and the suite would be green for the wrong reason. +test('derives a distinct Windows Store path from the userData path', () => { + assert.notEqual(BACKUP_DIR_WINSTORE, BACKUP_DIR); + assert.match(BACKUP_DIR_WINSTORE, /LocalCache\\Roaming/); +}); + +test('non-Store builds always get the real backup dir', () => { + const { getBackupDirForDisplay } = loadBackupModule(); + + // Even if a LocalCache dir is left over from a previous Store install. + existingPaths.add(BACKUP_DIR_WINSTORE); + + assert.equal(getBackupDirForDisplay(), BACKUP_DIR); +}); + +// Regression test for #995: a virtualized Store package redirects its writes +// into LocalCache, so showing the plain Roaming path sends the user to a folder +// their backups are not in. +test('Store builds get the LocalCache path when it exists', () => { + process.windowsStore = true; + const { getBackupDirForDisplay } = loadBackupModule(); + + existingPaths.add(BACKUP_DIR_WINSTORE); + + assert.equal(getBackupDirForDisplay(), BACKUP_DIR_WINSTORE); +}); + +// Regression test for #9209: a non-virtualized Store package writes to the real +// AppData\Roaming, so the LocalCache path does not exist and must not be shown. +test('Store builds fall back to the real backup dir when LocalCache is absent', () => { + process.windowsStore = true; + const { getBackupDirForDisplay } = loadBackupModule(); + + existingPaths.add(BACKUP_DIR); + + assert.equal(getBackupDirForDisplay(), BACKUP_DIR); +}); diff --git a/electron/backup.ts b/electron/backup.ts index 4a27a74169..09341a2d7c 100644 --- a/electron/backup.ts +++ b/electron/backup.ts @@ -22,11 +22,42 @@ import { } from './shared-with-frontend/backup-file-cleanup.util'; export const BACKUP_DIR = path.join(app.getPath('userData'), `backups`); -export const BACKUP_DIR_WINSTORE = BACKUP_DIR.replace( + +/** + * Where a virtualized MSIX package's writes to BACKUP_DIR physically land, so + * Explorer (which runs outside the package and sees no redirection) can be + * pointed at them. Display-oriented but not inert: `BACKUP_LOAD_DATA` below + * also accepts it as an allow-listed read root. + * + * shortcut: the package family name is hardcoded and nothing in CI would notice + * it drifting (the appx config lives in the WIN_STORE_ELECTRON_BUILDER_YML + * secret); drift just fails the probe and we show BACKUP_DIR. Verified against + * the shipped v18.15.1 appx on 2026-07-21 — it is `_`, + * PublisherId being base32(SHA-256(UTF-16LE Publisher)[0..8]), so any release + * artifact re-checks it without a Windows machine. + */ +const BACKUP_DIR_WINSTORE = BACKUP_DIR.replace( 'Roaming', `Local\\Packages\\53707johannesjo.SuperProductivity_ch45amy23cdv6\\LocalCache\\Roaming`, ); +/** + * The backup location to *show* the user, which is not always the one we write + * to. Redirection applies only to virtualized packages and, since Windows 10 + * 1903, is decided per file — it cannot be known statically, and assuming it + * always applies is what made #9209 the mirror image of #995. + * + * shortcut: an install that flipped from virtualized to full-trust keeps a + * stale LocalCache dir that still wins the probe, showing real but outdated + * backups. Accepted — restore reads BACKUP_DIR either way, so only manual + * recovery is affected. Upgrade path: probe for the newest filename in + * BACKUP_DIR (timestamps sort lexically) instead of for the directory. + */ +export const getBackupDirForDisplay = (): string => + process.windowsStore && existsSync(BACKUP_DIR_WINSTORE) + ? BACKUP_DIR_WINSTORE + : BACKUP_DIR; + // eslint-disable-next-line prefer-arrow/prefer-arrow-functions export function initBackupAdapter(): void { console.log('Saving backups to', BACKUP_DIR); diff --git a/electron/ipc-handlers/app-data.ts b/electron/ipc-handlers/app-data.ts index a415dca898..931ecc740e 100644 --- a/electron/ipc-handlers/app-data.ts +++ b/electron/ipc-handlers/app-data.ts @@ -1,17 +1,11 @@ import { app, ipcMain } from 'electron'; import { IPC } from '../shared-with-frontend/ipc-events.const'; -import { BACKUP_DIR, BACKUP_DIR_WINSTORE } from '../backup'; +import { getBackupDirForDisplay } from '../backup'; export const initAppDataIpc = (): void => { ipcMain.handle(IPC.GET_PATH, (ev, name: string) => { return app.getPath(name as Parameters[0]); }); - ipcMain.handle(IPC.GET_BACKUP_PATH, () => { - if (process?.windowsStore) { - return BACKUP_DIR_WINSTORE; - } else { - return BACKUP_DIR; - } - }); + ipcMain.handle(IPC.GET_BACKUP_PATH, () => getBackupDirForDisplay()); }; diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 24d20c58f3..546517767e 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -1492,7 +1492,7 @@ }, "PASSWORD_SET_INFO": "🔒 Encryption password is set.", "SUPER_SYNC": { - "ACCESS_TOKEN_DESCRIPTION": "Paste the token you copied from the server login page", + "ACCESS_TOKEN_DESCRIPTION": "Paste a token for your SuperSync account. On another device, reuse this token or sign in again to get another one.", "BTN_CHANGE_PASSWORD": "Change Password", "BTN_DISABLE_ENCRYPTION": "Disable Encryption", "BTN_ENABLE_ENCRYPTION": "Enable Encryption",