Refractoring Stage 6.1 Started renderer modularization with shared state.
This commit is contained in:
+6
-4
@@ -98,9 +98,10 @@ This is a gradual destination, not a requirement to move everything at once. IPC
|
||||
|
||||
**Result:** OpenPGP, mail/account, and DAV handler groups now register through the same sender and payload validation wrapper. Registration/schema tests cover all feature modules.
|
||||
|
||||
### 6. Modularize renderer incrementally
|
||||
### 6. Modularize renderer incrementally — in progress
|
||||
|
||||
- Introduce explicit modules and feature initialization APIs, starting with shared state and mail UI.
|
||||
- [x] Introduce a namespaced shared renderer-state module with transitional classic-script accessors (`renderer-state.js`).
|
||||
- [ ] Convert mail UI to explicit feature APIs and remove legacy global dependencies.
|
||||
- Replace hidden globals and script-order dependencies with imports or passed dependencies.
|
||||
- Keep root web assets canonical and generated copies out of hand-edited workflows.
|
||||
- Preserve CSP, HTML sanitization, and per-message remote-image approval behavior.
|
||||
@@ -126,7 +127,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.12`; Android derives `versionName 0.4.12` and `versionCode 412`. The existing Windows artifacts are through `ep-mail 0.4.11.exe`; no `0.4.12` release artifact has been built yet.
|
||||
- Latest version check: `package.json` and both lockfile version fields are `0.4.13`; Android derives `versionName 0.4.13` and `versionCode 413`. The user confirmed the `0.4.12` artifact was built and tested; `release/` contains its Windows executable. The `0.4.13` artifact has not yet been built.
|
||||
|
||||
## Progress log
|
||||
|
||||
@@ -145,7 +146,8 @@ This is a gradual destination, not a requirement to move everything at once. IPC
|
||||
- Step 5 moved OpenPGP handler registration and message-source fetching into a feature module and added registration/schema coverage.
|
||||
- Step 5 moved DAV handler registration into a feature module and added registration/schema coverage; the full suite passes 110 tests.
|
||||
- Step 5 grouped mail/account handlers in `desktop/ipc/mail.cjs`; all 114 tests pass and the remaining app-version handler stays in the Electron shell.
|
||||
- Added a build-version consistency check. The user bumped to `0.4.12`; package and lockfile match, and Android's derived build number is `412`. The release artifacts have not yet been built for this version.
|
||||
- Added a build-version consistency check. The user bumped to `0.4.13`; package and lockfile match, and Android's derived build number is `413`. The verified release artifact remains `0.4.12`.
|
||||
- Step 5 grouped mail/account handlers and added a release-version consistency test; current package/lockfile/Android version alignment was checked and documented.
|
||||
- Step 6 added `renderer-state.js` as the namespaced owner of shared mail/view state, retaining temporary classic-script accessors. It is included in desktop, Android-web, and service-worker asset lists and covered by state/parity tests.
|
||||
- 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.
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
if('serviceWorker'in navigator)window.addEventListener('load',()=>navigator.serviceWorker.register('./service-worker.js').catch(()=>{}));
|
||||
const messages = [];
|
||||
const contacts=[];
|
||||
let activeMessage=1,activeFolder='Inbox',activeView='mail',query='',toastTimer,selectedIds=new Set();
|
||||
const $=s=>document.querySelector(s), $$=s=>[...document.querySelectorAll(s)];
|
||||
function esc(x){return String(x).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]))}
|
||||
function safeRemoteImageUrl(value){if(typeof value!=='string'||value.length>2048)return null;try{const url=new URL(value);return url.protocol==='https:'&&url.hostname&&!url.username&&!url.password?url.href:null}catch{return null}}
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
</div>
|
||||
<div id="modal-root"></div>
|
||||
<div id="toast" class="toast" role="status" aria-live="polite"></div>
|
||||
<script src="renderer-state.js"></script>
|
||||
<script src="app.js"></script>
|
||||
<script src="platform-bridge.js"></script>
|
||||
<script src="mail-ui.js"></script>
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "ep-mail",
|
||||
"version": "0.4.12",
|
||||
"version": "0.4.13",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "ep-mail",
|
||||
"version": "0.4.12",
|
||||
"version": "0.4.13",
|
||||
"dependencies": {
|
||||
"@capacitor/android": "^8.5.2",
|
||||
"@capacitor/core": "^8.5.2",
|
||||
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ep-mail",
|
||||
"version": "0.4.12",
|
||||
"version": "0.4.13",
|
||||
"private": true,
|
||||
"description": "Eternity Project mail client",
|
||||
"homepage": "https://git.eternityproject.fi/thuttu/ep-mail-client",
|
||||
@@ -42,6 +42,7 @@
|
||||
"platform-bridge.js",
|
||||
"styles.css",
|
||||
"branding.css",
|
||||
"renderer-state.js",
|
||||
"app.js",
|
||||
"mail-ui.js",
|
||||
"productivity.js",
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
(function installRendererState(root, createState) {
|
||||
if (typeof module === 'object' && module.exports) {
|
||||
module.exports = { createRendererState: createState };
|
||||
return;
|
||||
}
|
||||
createState(root);
|
||||
})(typeof window === 'undefined' ? globalThis : window, function createRendererState(root) {
|
||||
const state = {
|
||||
messages: [],
|
||||
contacts: [],
|
||||
activeMessage: 1,
|
||||
activeFolder: 'Inbox',
|
||||
activeView: 'mail',
|
||||
query: '',
|
||||
toastTimer: null,
|
||||
selectedIds: new Set()
|
||||
};
|
||||
|
||||
Object.defineProperty(root, 'epMailState', {
|
||||
value: state,
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
writable: false
|
||||
});
|
||||
|
||||
// Transitional aliases keep the existing classic-script features working while they migrate.
|
||||
for (const key of Object.keys(state)) {
|
||||
Object.defineProperty(root, key, {
|
||||
get() { return state[key]; },
|
||||
set(value) { state[key] = value; },
|
||||
enumerable: false,
|
||||
configurable: false
|
||||
});
|
||||
}
|
||||
|
||||
return state;
|
||||
});
|
||||
@@ -8,6 +8,7 @@ const assets = [
|
||||
'index.html',
|
||||
'styles.css',
|
||||
'branding.css',
|
||||
'renderer-state.js',
|
||||
'app.js',
|
||||
'mail-ui.js',
|
||||
'productivity.js',
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
const CACHE='ep-mail-v8';
|
||||
const FILES=['./','./index.html','./styles.css','./branding.css','./app.js','./platform-bridge.js','./mail-ui.js','./productivity.js','./snooze-ui.js','./account-ui.js','./dav-ui.js','./shortcuts.js','./attachments.js','./pgp-ui.js','./pgp-mail-ui.js','./manifest.webmanifest','./icon.svg','./logo-ep-daylight.svg','./logo-ep-wasteland.svg'];
|
||||
const CACHE='ep-mail-v9';
|
||||
const FILES=['./','./index.html','./styles.css','./branding.css','./renderer-state.js','./app.js','./platform-bridge.js','./mail-ui.js','./productivity.js','./snooze-ui.js','./account-ui.js','./dav-ui.js','./shortcuts.js','./attachments.js','./pgp-ui.js','./pgp-mail-ui.js','./manifest.webmanifest','./icon.svg','./logo-ep-daylight.svg','./logo-ep-wasteland.svg'];
|
||||
self.addEventListener('install',event=>event.waitUntil(caches.open(CACHE).then(cache=>cache.addAll(FILES))));
|
||||
self.addEventListener('activate',event=>event.waitUntil(caches.keys().then(keys=>Promise.all(keys.filter(k=>k!==CACHE).map(k=>caches.delete(k))))));
|
||||
self.addEventListener('fetch',event=>{if(event.request.method!=='GET')return;event.respondWith(caches.match(event.request).then(cached=>cached||fetch(event.request).then(response=>{if(new URL(event.request.url).origin===location.origin){const copy=response.clone();caches.open(CACHE).then(cache=>cache.put(event.request,copy))}return response}).catch(()=>caches.match('./index.html'))))});
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const vm = require('node:vm');
|
||||
const { createRendererState } = require('../renderer-state.js');
|
||||
|
||||
test('creates namespaced shared renderer state with compatibility accessors', () => {
|
||||
const root = {};
|
||||
const state = createRendererState(root);
|
||||
|
||||
assert.equal(root.epMailState, state);
|
||||
assert.deepEqual(state.messages, []);
|
||||
assert.deepEqual(state.contacts, []);
|
||||
assert.equal(root.activeFolder, 'Inbox');
|
||||
assert.equal(root.activeView, 'mail');
|
||||
assert.equal(root.activeMessage, 1);
|
||||
assert.equal(root.query, '');
|
||||
assert.ok(root.selectedIds instanceof Set);
|
||||
|
||||
root.activeFolder = 'Archive';
|
||||
assert.equal(state.activeFolder, 'Archive');
|
||||
state.query = 'from:alice';
|
||||
assert.equal(root.query, 'from:alice');
|
||||
vm.createContext(root);
|
||||
vm.runInContext('messages.push({ id: 1 }); activeFolder = "Sent"; selectedIds.add(5);', root);
|
||||
assert.equal(state.messages.length, 1);
|
||||
assert.equal(state.messages[0].id, 1);
|
||||
assert.equal(state.activeFolder, 'Sent');
|
||||
assert.equal(state.selectedIds.has(5), true);
|
||||
root.epMailState = {};
|
||||
assert.equal(root.epMailState, state);
|
||||
});
|
||||
@@ -1,7 +1,4 @@
|
||||
if('serviceWorker'in navigator)window.addEventListener('load',()=>navigator.serviceWorker.register('./service-worker.js').catch(()=>{}));
|
||||
const messages = [];
|
||||
const contacts=[];
|
||||
let activeMessage=1,activeFolder='Inbox',activeView='mail',query='',toastTimer,selectedIds=new Set();
|
||||
const $=s=>document.querySelector(s), $$=s=>[...document.querySelectorAll(s)];
|
||||
function esc(x){return String(x).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]))}
|
||||
function safeRemoteImageUrl(value){if(typeof value!=='string'||value.length>2048)return null;try{const url=new URL(value);return url.protocol==='https:'&&url.hostname&&!url.username&&!url.password?url.href:null}catch{return null}}
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
</div>
|
||||
<div id="modal-root"></div>
|
||||
<div id="toast" class="toast" role="status" aria-live="polite"></div>
|
||||
<script src="renderer-state.js"></script>
|
||||
<script src="app.js"></script>
|
||||
<script src="platform-bridge.js"></script>
|
||||
<script src="mail-ui.js"></script>
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
(function installRendererState(root, createState) {
|
||||
if (typeof module === 'object' && module.exports) {
|
||||
module.exports = { createRendererState: createState };
|
||||
return;
|
||||
}
|
||||
createState(root);
|
||||
})(typeof window === 'undefined' ? globalThis : window, function createRendererState(root) {
|
||||
const state = {
|
||||
messages: [],
|
||||
contacts: [],
|
||||
activeMessage: 1,
|
||||
activeFolder: 'Inbox',
|
||||
activeView: 'mail',
|
||||
query: '',
|
||||
toastTimer: null,
|
||||
selectedIds: new Set()
|
||||
};
|
||||
|
||||
Object.defineProperty(root, 'epMailState', {
|
||||
value: state,
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
writable: false
|
||||
});
|
||||
|
||||
// Transitional aliases keep the existing classic-script features working while they migrate.
|
||||
for (const key of Object.keys(state)) {
|
||||
Object.defineProperty(root, key, {
|
||||
get() { return state[key]; },
|
||||
set(value) { state[key] = value; },
|
||||
enumerable: false,
|
||||
configurable: false
|
||||
});
|
||||
}
|
||||
|
||||
return state;
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
const CACHE='ep-mail-v8';
|
||||
const FILES=['./','./index.html','./styles.css','./branding.css','./app.js','./platform-bridge.js','./mail-ui.js','./productivity.js','./snooze-ui.js','./account-ui.js','./dav-ui.js','./shortcuts.js','./attachments.js','./pgp-ui.js','./pgp-mail-ui.js','./manifest.webmanifest','./icon.svg','./logo-ep-daylight.svg','./logo-ep-wasteland.svg'];
|
||||
const CACHE='ep-mail-v9';
|
||||
const FILES=['./','./index.html','./styles.css','./branding.css','./renderer-state.js','./app.js','./platform-bridge.js','./mail-ui.js','./productivity.js','./snooze-ui.js','./account-ui.js','./dav-ui.js','./shortcuts.js','./attachments.js','./pgp-ui.js','./pgp-mail-ui.js','./manifest.webmanifest','./icon.svg','./logo-ep-daylight.svg','./logo-ep-wasteland.svg'];
|
||||
self.addEventListener('install',event=>event.waitUntil(caches.open(CACHE).then(cache=>cache.addAll(FILES))));
|
||||
self.addEventListener('activate',event=>event.waitUntil(caches.keys().then(keys=>Promise.all(keys.filter(k=>k!==CACHE).map(k=>caches.delete(k))))));
|
||||
self.addEventListener('fetch',event=>{if(event.request.method!=='GET')return;event.respondWith(caches.match(event.request).then(cached=>cached||fetch(event.request).then(response=>{if(new URL(event.request.url).origin===location.origin){const copy=response.clone();caches.open(CACHE).then(cache=>cache.put(event.request,copy))}return response}).catch(()=>caches.match('./index.html'))))});
|
||||
|
||||
Reference in New Issue
Block a user