From bc550cc929d568c846db6a62032f360fd61031a0 Mon Sep 17 00:00:00 2001 From: Tero Date: Fri, 16 Oct 2026 23:10:21 +0300 Subject: [PATCH] Refractoring Stage 6.23 Moved the mail API factory from the standalone window.epMailUiModules global into window.epMailFeatures.modules; mail-ui.js now uses the shared feature namespace. Bumped to 0.4.35 (Android version code 435) and updated REFACTOR_PLAN.md. --- REFACTOR_PLAN.md | 4 +++- mail-ui.js | 3 +-- package-lock.json | 4 ++-- package.json | 2 +- renderer-mail-api.js | 3 ++- tests/renderer-mail-api.test.cjs | 12 ++++++++++++ www/mail-ui.js | 3 +-- www/renderer-mail-api.js | 3 ++- 8 files changed, 24 insertions(+), 10 deletions(-) diff --git a/REFACTOR_PLAN.md b/REFACTOR_PLAN.md index 79542e0..9ea4a03 100644 --- a/REFACTOR_PLAN.md +++ b/REFACTOR_PLAN.md @@ -123,6 +123,7 @@ This is a gradual destination, not a requirement to move everything at once. IPC - [x] Encapsulate snooze UI helpers locally while preserving explicit mail/productivity API usage (`snooze-ui.js`). - [x] Encapsulate keyboard shortcut settings and handlers locally; integrations remain through the mail/productivity feature APIs (`shortcuts.js`). - [x] Remove transitional renderer-state globals after all consumers migrated to the namespaced state API (`renderer-state.js`). +- [x] Register the mail API factory under the shared feature namespace instead of a standalone renderer global (`renderer-mail-api.js`, `mail-ui.js`). - [x] Migrate additional mail-related consumers to unique local aliases to avoid classic-script lexical redeclarations. - [x] Add a combined-script parse test to prevent duplicate top-level lexical declarations from stopping later UI scripts. - [ ] Migrate remaining mail-related consumers and remove transitional global dependencies. @@ -151,7 +152,7 @@ This is a gradual destination, not a requirement to move everything at once. IPC - Electron Builder and the desktop Actions artifact name derive from `package.json`. - Android `versionName` derives from the same package version. Its current `versionCode` mapping is `major * 10000 + minor * 100 + patch`; keep minor and patch below 100, and revise the mapping before reaching that boundary to avoid collisions. - `scripts/build-all.ps1` uses the package version for APK naming. Before a release, bump once with `npm run bump:build`, verify the lockfile and computed Android version code, and build every target without another bump. -- Latest version check: `package.json` and both lockfile version fields are `0.4.34`; Android derives `versionName 0.4.34` and `versionCode 434`. The user confirms the previous artifact works; this bump is for the next build. +- Latest version check: `package.json` and both lockfile version fields are `0.4.35`; Android derives `versionName 0.4.35` and `versionCode 435`. The user confirms the previous artifact works; this bump is for the next build. ## Progress log @@ -188,5 +189,6 @@ This is a gradual destination, not a requirement to move everything at once. IPC - Step 6 at version `0.4.32` scopes snooze UI helpers; message labeling and mail-state access remain routed through feature APIs. - Step 6 at version `0.4.33` scopes keyboard shortcut helpers and event handlers without changing their Preferences integration. - Step 6 at version `0.4.34` removes legacy global renderer-state accessors; the state module now exposes only `window.epMailState` to the renderer. +- Step 6 at version `0.4.35` consolidates the mail API factory under `window.epMailFeatures.modules`, removing the separate `window.epMailUiModules` global. - The current IPC/DAV validation changes pass the full suite: 108 tests. - While work continued, `package.json` and `package-lock.json` reflected a version bump to `0.4.6`; those changes were preserved. diff --git a/mail-ui.js b/mail-ui.js index 02318f6..7c7ec9d 100644 --- a/mail-ui.js +++ b/mail-ui.js @@ -791,7 +791,7 @@ if (window.daybreakMail) { }).catch(() => {}); } -const mailUiApi = window.epMailUiModules.createMailUiApi({ +const mailUiApi = window.epMailFeatures.modules.createMailUiApi({ state: window.epMailState, getConnectedAccount: () => mailFeatureState.connectedAccount, setConnectedAccount: account => { mailFeatureState.connectedAccount = account; }, @@ -813,6 +813,5 @@ const mailUiApi = window.epMailUiModules.createMailUiApi({ setOpenMessage: renderer => appShell.wrapOpenMessage(() => renderer), setShowCompose: renderer => appShell.wrapShowCompose(() => renderer) }); -window.epMailFeatures = window.epMailFeatures || {}; window.epMailFeatures.mail = mailUiApi; })(); diff --git a/package-lock.json b/package-lock.json index 9fbe14f..176ccfc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ep-mail", - "version": "0.4.34", + "version": "0.4.35", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ep-mail", - "version": "0.4.34", + "version": "0.4.35", "dependencies": { "@capacitor/android": "^8.5.2", "@capacitor/core": "^8.5.2", diff --git a/package.json b/package.json index 68ab5a6..f00d708 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ep-mail", - "version": "0.4.34", + "version": "0.4.35", "private": true, "description": "Eternity Project mail client", "homepage": "https://git.eternityproject.fi/thuttu/ep-mail-client", diff --git a/renderer-mail-api.js b/renderer-mail-api.js index 2197e9a..461877c 100644 --- a/renderer-mail-api.js +++ b/renderer-mail-api.js @@ -48,7 +48,8 @@ if (typeof module === 'object' && module.exports) { module.exports = { createMailUiApi }; } else { - Object.defineProperty(root, 'epMailUiModules', { + root.epMailFeatures = root.epMailFeatures || {}; + Object.defineProperty(root.epMailFeatures, 'modules', { value: Object.freeze({ createMailUiApi }), enumerable: false }); diff --git a/tests/renderer-mail-api.test.cjs b/tests/renderer-mail-api.test.cjs index be90485..0b8eeec 100644 --- a/tests/renderer-mail-api.test.cjs +++ b/tests/renderer-mail-api.test.cjs @@ -2,6 +2,7 @@ const test = require('node:test'); const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); +const vm = require('node:vm'); const { createMailUiApi } = require('../renderer-mail-api.js'); test('mail feature API exposes explicit state and account/sync UI actions', () => { @@ -56,6 +57,16 @@ test('mail feature API exposes explicit state and account/sync UI actions', () = assert.equal(Object.isFrozen(api), true); }); +test('browser mail API factory is registered under the shared feature namespace', () => { + const root = path.resolve(__dirname, '..'); + const source = fs.readFileSync(path.join(root, 'renderer-mail-api.js'), 'utf8'); + const window = {}; + vm.runInNewContext(source, { window }); + assert.equal(typeof window.epMailFeatures.modules.createMailUiApi, 'function'); + assert.equal(Object.isFrozen(window.epMailFeatures.modules), true); + assert.equal(Object.hasOwn(window, 'epMailUiModules'), false); +}); + test('account and snooze UI consume the explicit mail API instead of selected legacy globals', () => { const root = path.resolve(__dirname, '..'); const accountUi = fs.readFileSync(path.join(root, 'account-ui.js'), 'utf8'); @@ -88,6 +99,7 @@ test('account and snooze UI consume the explicit mail API instead of selected le assert.match(mailUi, /appShell\.wrapOpenMessage/); assert.match(mailUi, /appShell\.wrapShowCompose/); assert.match(mailUi, /^\(\(\) => \{/); + assert.match(mailUi, /window\.epMailFeatures\.modules\.createMailUiApi/); assert.match(mailUi, /window\.epMailFeatures\.mail = mailUiApi/); assert.doesNotMatch(mailUi, /(? {}); } -const mailUiApi = window.epMailUiModules.createMailUiApi({ +const mailUiApi = window.epMailFeatures.modules.createMailUiApi({ state: window.epMailState, getConnectedAccount: () => mailFeatureState.connectedAccount, setConnectedAccount: account => { mailFeatureState.connectedAccount = account; }, @@ -813,6 +813,5 @@ const mailUiApi = window.epMailUiModules.createMailUiApi({ setOpenMessage: renderer => appShell.wrapOpenMessage(() => renderer), setShowCompose: renderer => appShell.wrapShowCompose(() => renderer) }); -window.epMailFeatures = window.epMailFeatures || {}; window.epMailFeatures.mail = mailUiApi; })(); diff --git a/www/renderer-mail-api.js b/www/renderer-mail-api.js index 2197e9a..461877c 100644 --- a/www/renderer-mail-api.js +++ b/www/renderer-mail-api.js @@ -48,7 +48,8 @@ if (typeof module === 'object' && module.exports) { module.exports = { createMailUiApi }; } else { - Object.defineProperty(root, 'epMailUiModules', { + root.epMailFeatures = root.epMailFeatures || {}; + Object.defineProperty(root.epMailFeatures, 'modules', { value: Object.freeze({ createMailUiApi }), enumerable: false });