Refractoring Stage 6.3 Convert mail UI to explicit feature APIs and remove legacy global dependencies.
This commit is contained in:
+6
-5
@@ -102,7 +102,8 @@ This is a gradual destination, not a requirement to move everything at once. IPC
|
|||||||
|
|
||||||
- [x] Introduce a namespaced shared renderer-state module with transitional classic-script accessors (`renderer-state.js`).
|
- [x] Introduce a namespaced shared renderer-state module with transitional classic-script accessors (`renderer-state.js`).
|
||||||
- [x] Extract mail HTML sanitization and remote-image approval checks into a dedicated renderer API (`mail-content-security.js`).
|
- [x] Extract mail HTML sanitization and remote-image approval checks into a dedicated renderer API (`mail-content-security.js`).
|
||||||
- [ ] Convert mail UI to explicit feature APIs and remove legacy global dependencies.
|
- [x] Add an explicit mail feature API and migrate the account manager to it (`renderer-mail-api.js`, `account-ui.js`).
|
||||||
|
- [ ] Migrate remaining mail-related consumers and remove transitional global dependencies.
|
||||||
- Replace hidden globals and script-order dependencies with imports or passed 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.
|
- Keep root web assets canonical and generated copies out of hand-edited workflows.
|
||||||
- Preserve CSP, HTML sanitization, and per-message remote-image approval behavior.
|
- Preserve CSP, HTML sanitization, and per-message remote-image approval behavior.
|
||||||
@@ -128,7 +129,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`.
|
- 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.
|
- 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.
|
- `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.14`; Android derives `versionName 0.4.14` and `versionCode 414`. `release/` currently contains Windows artifacts through `0.4.13`; no `0.4.14` artifact has been built yet.
|
- Latest version check: `package.json` and both lockfile version fields are `0.4.15`; Android derives `versionName 0.4.15` and `versionCode 415`. `release/` contains Windows artifacts through `0.4.14`; the `0.4.15` artifact has not been built yet.
|
||||||
|
|
||||||
## Progress log
|
## Progress log
|
||||||
|
|
||||||
@@ -147,9 +148,9 @@ 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 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 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.
|
- 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.14`; package and lockfile match, and Android's derived build number is `414`. The latest artifact observed is Windows `0.4.13`.
|
- Added a build-version consistency check. Package/lockfile are now `0.4.15`, with Android build number `415`; the latest artifact observed is Windows `0.4.14`.
|
||||||
- Step 5 grouped mail/account handlers and added a release-version consistency test; current package/lockfile/Android version alignment was checked and documented.
|
- 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 and `mail-content-security.js` as a dedicated sanitizer/remote-image API. Transitional classic-script accessors remain; bootstrap order and desktop/Android/offline asset inclusion are tested.
|
- Step 6 added `renderer-state.js`, extracted the mail HTML security API, and introduced `renderer-mail-api.js`; `account-ui.js` now uses that explicit API instead of several mail globals. Transitional aliases remain for other classic scripts.
|
||||||
- Step 6's first renderer slice passes 119 tests. The `0.4.14` artifact has not been built as part of this renderer change.
|
- Step 6's renderer API slice passes 120 tests. The `0.4.15` artifact has not been built as part of this renderer change.
|
||||||
- The current IPC/DAV validation changes pass the full suite: 108 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.
|
- While work continued, `package.json` and `package-lock.json` reflected a version bump to `0.4.6`; those changes were preserved.
|
||||||
|
|||||||
+6
-4
@@ -1,3 +1,5 @@
|
|||||||
|
const mailUi = window.epMailFeatures.mail;
|
||||||
|
|
||||||
async function openAccountManager(){
|
async function openAccountManager(){
|
||||||
const root=$('#modal-root');
|
const root=$('#modal-root');
|
||||||
try{
|
try{
|
||||||
@@ -8,16 +10,16 @@ async function openAccountManager(){
|
|||||||
const close=()=>root.innerHTML='';
|
const close=()=>root.innerHTML='';
|
||||||
root.querySelectorAll('.modal-close').forEach(button=>button.onclick=close);
|
root.querySelectorAll('.modal-close').forEach(button=>button.onclick=close);
|
||||||
root.querySelector('.modal-overlay').onclick=event=>{if(event.target.classList.contains('modal-overlay'))close()};
|
root.querySelector('.modal-overlay').onclick=event=>{if(event.target.classList.contains('modal-overlay'))close()};
|
||||||
root.querySelector('#add-mail-account').onclick=()=>{close();openMailAccount()};
|
root.querySelector('#add-mail-account').onclick=()=>{close();mailUi.openMailAccount()};
|
||||||
root.onclick=async event=>{
|
root.onclick=async event=>{
|
||||||
const switchButton=event.target.closest('[data-switch-account]');
|
const switchButton=event.target.closest('[data-switch-account]');
|
||||||
if(switchButton){switchButton.disabled=true;try{connectedMailAccount=await window.daybreakMail.selectAccount(switchButton.dataset.switchAccount);activeFolder='Inbox';mailPageOffset=0;document.querySelectorAll('.folder').forEach(button=>button.classList.toggle('active',button.dataset.folder==='Inbox'));$('#sidebar-title').textContent='Inbox';$('#crumb-current').textContent='Inbox';updateAccountCard(connectedMailAccount);close();await syncMailbox(true,{offset:0})}catch(error){toast(error.message||'Could not switch accounts');switchButton.disabled=false}return}
|
if(switchButton){switchButton.disabled=true;try{mailUi.connectedAccount=await window.daybreakMail.selectAccount(switchButton.dataset.switchAccount);mailUi.state.activeFolder='Inbox';mailUi.setPageOffset(0);document.querySelectorAll('.folder').forEach(button=>button.classList.toggle('active',button.dataset.folder==='Inbox'));$('#sidebar-title').textContent='Inbox';$('#crumb-current').textContent='Inbox';mailUi.updateAccountCard(mailUi.connectedAccount);close();await mailUi.syncMailbox(true,{offset:0})}catch(error){toast(error.message||'Could not switch accounts');switchButton.disabled=false}return}
|
||||||
const davButton=event.target.closest('[data-open-dav]');
|
const davButton=event.target.closest('[data-open-dav]');
|
||||||
if(davButton){close();openDavManager(davButton.dataset.openDav);return}
|
if(davButton){close();openDavManager(davButton.dataset.openDav);return}
|
||||||
const editButton=event.target.closest('[data-edit-account]');
|
const editButton=event.target.closest('[data-edit-account]');
|
||||||
if(editButton){const account=accounts.find(item=>item.id===editButton.dataset.editAccount);if(account)openMailAccount(account);return}
|
if(editButton){const account=accounts.find(item=>item.id===editButton.dataset.editAccount);if(account)mailUi.openMailAccount(account);return}
|
||||||
const removeButton=event.target.closest('[data-remove-account]');
|
const removeButton=event.target.closest('[data-remove-account]');
|
||||||
if(removeButton){const email=removeButton.closest('.account-row').querySelector('strong').textContent;if(!confirm(`Remove ${email} from this device?`))return;removeButton.disabled=true;try{const result=await window.daybreakMail.removeAccount(removeButton.dataset.removeAccount);const active=result.accounts.find(account=>account.id===result.activeId)||null;connectedMailAccount=active;if(active){updateAccountCard(active);close();activeFolder='Inbox';mailPageOffset=0;await syncMailbox(false,{offset:0})}else{updateAccountCard({email:'Connect a mailbox',imapHost:''});messages.splice(0,messages.length);renderList();$('#reader-pane').innerHTML=emptyReader();toast('Mail account removed');openAccountManager()}}catch(error){toast(error.message||'Could not remove the account');removeButton.disabled=false}return}
|
if(removeButton){const email=removeButton.closest('.account-row').querySelector('strong').textContent;if(!confirm(`Remove ${email} from this device?`))return;removeButton.disabled=true;try{const result=await window.daybreakMail.removeAccount(removeButton.dataset.removeAccount);const active=result.accounts.find(account=>account.id===result.activeId)||null;mailUi.connectedAccount=active;if(active){mailUi.updateAccountCard(active);close();mailUi.state.activeFolder='Inbox';mailUi.setPageOffset(0);await mailUi.syncMailbox(false,{offset:0})}else{mailUi.updateAccountCard({email:'Connect a mailbox',imapHost:''});mailUi.state.messages.splice(0,mailUi.state.messages.length);mailUi.renderList();$('#reader-pane').innerHTML=mailUi.emptyReader();toast('Mail account removed');openAccountManager()}}catch(error){toast(error.message||'Could not remove the account');removeButton.disabled=false}return}
|
||||||
};
|
};
|
||||||
}catch(error){toast(error.message||'Could not load mail accounts')}
|
}catch(error){toast(error.message||'Could not load mail accounts')}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,7 @@
|
|||||||
<script src="mail-content-security.js"></script>
|
<script src="mail-content-security.js"></script>
|
||||||
<script src="app.js"></script>
|
<script src="app.js"></script>
|
||||||
<script src="platform-bridge.js"></script>
|
<script src="platform-bridge.js"></script>
|
||||||
|
<script src="renderer-mail-api.js"></script>
|
||||||
<script src="mail-ui.js"></script>
|
<script src="mail-ui.js"></script>
|
||||||
<script src="productivity.js"></script>
|
<script src="productivity.js"></script>
|
||||||
<script src="snooze-ui.js"></script>
|
<script src="snooze-ui.js"></script>
|
||||||
|
|||||||
+13
@@ -784,3 +784,16 @@ if (window.daybreakMail) {
|
|||||||
syncMailbox(false);
|
syncMailbox(false);
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mailUiApi = window.epMailUiModules.createMailUiApi({
|
||||||
|
state: window.epMailState,
|
||||||
|
getConnectedAccount: () => connectedMailAccount,
|
||||||
|
setConnectedAccount: account => { connectedMailAccount = account; },
|
||||||
|
setPageOffset: offset => { mailPageOffset = offset; },
|
||||||
|
syncMailbox,
|
||||||
|
updateAccountCard,
|
||||||
|
renderList,
|
||||||
|
emptyReader,
|
||||||
|
openMailAccount
|
||||||
|
});
|
||||||
|
window.epMailFeatures = Object.freeze({ ...(window.epMailFeatures || {}), mail: mailUiApi });
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "ep-mail",
|
"name": "ep-mail",
|
||||||
"version": "0.4.14",
|
"version": "0.4.15",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "ep-mail",
|
"name": "ep-mail",
|
||||||
"version": "0.4.14",
|
"version": "0.4.15",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@capacitor/android": "^8.5.2",
|
"@capacitor/android": "^8.5.2",
|
||||||
"@capacitor/core": "^8.5.2",
|
"@capacitor/core": "^8.5.2",
|
||||||
|
|||||||
+2
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ep-mail",
|
"name": "ep-mail",
|
||||||
"version": "0.4.14",
|
"version": "0.4.15",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Eternity Project mail client",
|
"description": "Eternity Project mail client",
|
||||||
"homepage": "https://git.eternityproject.fi/thuttu/ep-mail-client",
|
"homepage": "https://git.eternityproject.fi/thuttu/ep-mail-client",
|
||||||
@@ -44,6 +44,7 @@
|
|||||||
"branding.css",
|
"branding.css",
|
||||||
"renderer-state.js",
|
"renderer-state.js",
|
||||||
"mail-content-security.js",
|
"mail-content-security.js",
|
||||||
|
"renderer-mail-api.js",
|
||||||
"app.js",
|
"app.js",
|
||||||
"mail-ui.js",
|
"mail-ui.js",
|
||||||
"productivity.js",
|
"productivity.js",
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
(function installMailUiApiFactory(root) {
|
||||||
|
function createMailUiApi({
|
||||||
|
state,
|
||||||
|
getConnectedAccount,
|
||||||
|
setConnectedAccount,
|
||||||
|
setPageOffset,
|
||||||
|
syncMailbox,
|
||||||
|
updateAccountCard,
|
||||||
|
renderList,
|
||||||
|
emptyReader,
|
||||||
|
openMailAccount
|
||||||
|
}) {
|
||||||
|
return Object.freeze({
|
||||||
|
state,
|
||||||
|
get connectedAccount() { return getConnectedAccount(); },
|
||||||
|
set connectedAccount(account) { setConnectedAccount(account); },
|
||||||
|
setPageOffset,
|
||||||
|
syncMailbox,
|
||||||
|
updateAccountCard,
|
||||||
|
renderList,
|
||||||
|
emptyReader,
|
||||||
|
openMailAccount
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof module === 'object' && module.exports) {
|
||||||
|
module.exports = { createMailUiApi };
|
||||||
|
} else {
|
||||||
|
Object.defineProperty(root, 'epMailUiModules', {
|
||||||
|
value: Object.freeze({ createMailUiApi }),
|
||||||
|
enumerable: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})(typeof window === 'undefined' ? globalThis : window);
|
||||||
@@ -10,6 +10,7 @@ const assets = [
|
|||||||
'branding.css',
|
'branding.css',
|
||||||
'renderer-state.js',
|
'renderer-state.js',
|
||||||
'mail-content-security.js',
|
'mail-content-security.js',
|
||||||
|
'renderer-mail-api.js',
|
||||||
'app.js',
|
'app.js',
|
||||||
'mail-ui.js',
|
'mail-ui.js',
|
||||||
'productivity.js',
|
'productivity.js',
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
const CACHE='ep-mail-v10';
|
const CACHE='ep-mail-v11';
|
||||||
const FILES=['./','./index.html','./styles.css','./branding.css','./renderer-state.js','./mail-content-security.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'];
|
const FILES=['./','./index.html','./styles.css','./branding.css','./renderer-state.js','./mail-content-security.js','./renderer-mail-api.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('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('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'))))});
|
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'))))});
|
||||||
|
|||||||
@@ -10,15 +10,18 @@ test('renderer bootstrap loads shared state and mail security before the applica
|
|||||||
const html = read('index.html');
|
const html = read('index.html');
|
||||||
const state = html.indexOf('<script src="renderer-state.js"></script>');
|
const state = html.indexOf('<script src="renderer-state.js"></script>');
|
||||||
const contentSecurity = html.indexOf('<script src="mail-content-security.js"></script>');
|
const contentSecurity = html.indexOf('<script src="mail-content-security.js"></script>');
|
||||||
|
const mailApi = html.indexOf('<script src="renderer-mail-api.js"></script>');
|
||||||
const app = html.indexOf('<script src="app.js"></script>');
|
const app = html.indexOf('<script src="app.js"></script>');
|
||||||
assert.ok(state >= 0 && contentSecurity > state && app > contentSecurity);
|
const platformBridge = html.indexOf('<script src="platform-bridge.js"></script>');
|
||||||
|
const mailUi = html.indexOf('<script src="mail-ui.js"></script>');
|
||||||
|
assert.ok(state >= 0 && contentSecurity > state && app > contentSecurity && mailApi > platformBridge && mailUi > mailApi);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('desktop, Android web generation, and offline cache include renderer support modules', () => {
|
test('desktop, Android web generation, and offline cache include renderer support modules', () => {
|
||||||
const buildFiles = require(path.join(root, 'package.json')).build.files;
|
const buildFiles = require(path.join(root, 'package.json')).build.files;
|
||||||
const androidAssets = read('scripts/prepare-android-web.cjs');
|
const androidAssets = read('scripts/prepare-android-web.cjs');
|
||||||
const worker = read('service-worker.js');
|
const worker = read('service-worker.js');
|
||||||
for (const file of ['renderer-state.js', 'mail-content-security.js']) {
|
for (const file of ['renderer-state.js', 'mail-content-security.js', 'renderer-mail-api.js']) {
|
||||||
assert.ok(buildFiles.includes(file), `Electron package is missing ${file}`);
|
assert.ok(buildFiles.includes(file), `Electron package is missing ${file}`);
|
||||||
assert.ok(androidAssets.includes(`'${file}'`), `Android web generator is missing ${file}`);
|
assert.ok(androidAssets.includes(`'${file}'`), `Android web generator is missing ${file}`);
|
||||||
assert.ok(worker.includes(`'./${file}'`), `service worker is missing ${file}`);
|
assert.ok(worker.includes(`'./${file}'`), `service worker is missing ${file}`);
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
const test = require('node:test');
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
const { createMailUiApi } = require('../renderer-mail-api.js');
|
||||||
|
|
||||||
|
test('mail feature API exposes explicit state and account/sync UI actions', () => {
|
||||||
|
const calls = [];
|
||||||
|
let connectedAccount = { id: 'first' };
|
||||||
|
const state = { activeFolder: 'Inbox' };
|
||||||
|
const methods = {
|
||||||
|
setPageOffset: value => calls.push(['offset', value]),
|
||||||
|
syncMailbox: (...args) => calls.push(['sync', ...args]),
|
||||||
|
updateAccountCard: value => calls.push(['card', value]),
|
||||||
|
renderList: () => calls.push(['render']),
|
||||||
|
emptyReader: () => '<empty>',
|
||||||
|
openMailAccount: value => calls.push(['open-account', value])
|
||||||
|
};
|
||||||
|
const api = createMailUiApi({
|
||||||
|
state,
|
||||||
|
getConnectedAccount: () => connectedAccount,
|
||||||
|
setConnectedAccount: value => { connectedAccount = value; },
|
||||||
|
...methods
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(api.state, state);
|
||||||
|
assert.equal(api.connectedAccount.id, 'first');
|
||||||
|
api.connectedAccount = { id: 'second' };
|
||||||
|
assert.equal(connectedAccount.id, 'second');
|
||||||
|
api.setPageOffset(0);
|
||||||
|
api.syncMailbox(false, { offset: 0 });
|
||||||
|
api.updateAccountCard(api.connectedAccount);
|
||||||
|
api.renderList();
|
||||||
|
assert.equal(api.emptyReader(), '<empty>');
|
||||||
|
api.openMailAccount();
|
||||||
|
assert.deepEqual(calls.map(call => call[0]), ['offset', 'sync', 'card', 'render', 'open-account']);
|
||||||
|
assert.equal(Object.isFrozen(api), true);
|
||||||
|
});
|
||||||
+6
-4
@@ -1,3 +1,5 @@
|
|||||||
|
const mailUi = window.epMailFeatures.mail;
|
||||||
|
|
||||||
async function openAccountManager(){
|
async function openAccountManager(){
|
||||||
const root=$('#modal-root');
|
const root=$('#modal-root');
|
||||||
try{
|
try{
|
||||||
@@ -8,16 +10,16 @@ async function openAccountManager(){
|
|||||||
const close=()=>root.innerHTML='';
|
const close=()=>root.innerHTML='';
|
||||||
root.querySelectorAll('.modal-close').forEach(button=>button.onclick=close);
|
root.querySelectorAll('.modal-close').forEach(button=>button.onclick=close);
|
||||||
root.querySelector('.modal-overlay').onclick=event=>{if(event.target.classList.contains('modal-overlay'))close()};
|
root.querySelector('.modal-overlay').onclick=event=>{if(event.target.classList.contains('modal-overlay'))close()};
|
||||||
root.querySelector('#add-mail-account').onclick=()=>{close();openMailAccount()};
|
root.querySelector('#add-mail-account').onclick=()=>{close();mailUi.openMailAccount()};
|
||||||
root.onclick=async event=>{
|
root.onclick=async event=>{
|
||||||
const switchButton=event.target.closest('[data-switch-account]');
|
const switchButton=event.target.closest('[data-switch-account]');
|
||||||
if(switchButton){switchButton.disabled=true;try{connectedMailAccount=await window.daybreakMail.selectAccount(switchButton.dataset.switchAccount);activeFolder='Inbox';mailPageOffset=0;document.querySelectorAll('.folder').forEach(button=>button.classList.toggle('active',button.dataset.folder==='Inbox'));$('#sidebar-title').textContent='Inbox';$('#crumb-current').textContent='Inbox';updateAccountCard(connectedMailAccount);close();await syncMailbox(true,{offset:0})}catch(error){toast(error.message||'Could not switch accounts');switchButton.disabled=false}return}
|
if(switchButton){switchButton.disabled=true;try{mailUi.connectedAccount=await window.daybreakMail.selectAccount(switchButton.dataset.switchAccount);mailUi.state.activeFolder='Inbox';mailUi.setPageOffset(0);document.querySelectorAll('.folder').forEach(button=>button.classList.toggle('active',button.dataset.folder==='Inbox'));$('#sidebar-title').textContent='Inbox';$('#crumb-current').textContent='Inbox';mailUi.updateAccountCard(mailUi.connectedAccount);close();await mailUi.syncMailbox(true,{offset:0})}catch(error){toast(error.message||'Could not switch accounts');switchButton.disabled=false}return}
|
||||||
const davButton=event.target.closest('[data-open-dav]');
|
const davButton=event.target.closest('[data-open-dav]');
|
||||||
if(davButton){close();openDavManager(davButton.dataset.openDav);return}
|
if(davButton){close();openDavManager(davButton.dataset.openDav);return}
|
||||||
const editButton=event.target.closest('[data-edit-account]');
|
const editButton=event.target.closest('[data-edit-account]');
|
||||||
if(editButton){const account=accounts.find(item=>item.id===editButton.dataset.editAccount);if(account)openMailAccount(account);return}
|
if(editButton){const account=accounts.find(item=>item.id===editButton.dataset.editAccount);if(account)mailUi.openMailAccount(account);return}
|
||||||
const removeButton=event.target.closest('[data-remove-account]');
|
const removeButton=event.target.closest('[data-remove-account]');
|
||||||
if(removeButton){const email=removeButton.closest('.account-row').querySelector('strong').textContent;if(!confirm(`Remove ${email} from this device?`))return;removeButton.disabled=true;try{const result=await window.daybreakMail.removeAccount(removeButton.dataset.removeAccount);const active=result.accounts.find(account=>account.id===result.activeId)||null;connectedMailAccount=active;if(active){updateAccountCard(active);close();activeFolder='Inbox';mailPageOffset=0;await syncMailbox(false,{offset:0})}else{updateAccountCard({email:'Connect a mailbox',imapHost:''});messages.splice(0,messages.length);renderList();$('#reader-pane').innerHTML=emptyReader();toast('Mail account removed');openAccountManager()}}catch(error){toast(error.message||'Could not remove the account');removeButton.disabled=false}return}
|
if(removeButton){const email=removeButton.closest('.account-row').querySelector('strong').textContent;if(!confirm(`Remove ${email} from this device?`))return;removeButton.disabled=true;try{const result=await window.daybreakMail.removeAccount(removeButton.dataset.removeAccount);const active=result.accounts.find(account=>account.id===result.activeId)||null;mailUi.connectedAccount=active;if(active){mailUi.updateAccountCard(active);close();mailUi.state.activeFolder='Inbox';mailUi.setPageOffset(0);await mailUi.syncMailbox(false,{offset:0})}else{mailUi.updateAccountCard({email:'Connect a mailbox',imapHost:''});mailUi.state.messages.splice(0,mailUi.state.messages.length);mailUi.renderList();$('#reader-pane').innerHTML=mailUi.emptyReader();toast('Mail account removed');openAccountManager()}}catch(error){toast(error.message||'Could not remove the account');removeButton.disabled=false}return}
|
||||||
};
|
};
|
||||||
}catch(error){toast(error.message||'Could not load mail accounts')}
|
}catch(error){toast(error.message||'Could not load mail accounts')}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,7 @@
|
|||||||
<script src="mail-content-security.js"></script>
|
<script src="mail-content-security.js"></script>
|
||||||
<script src="app.js"></script>
|
<script src="app.js"></script>
|
||||||
<script src="platform-bridge.js"></script>
|
<script src="platform-bridge.js"></script>
|
||||||
|
<script src="renderer-mail-api.js"></script>
|
||||||
<script src="mail-ui.js"></script>
|
<script src="mail-ui.js"></script>
|
||||||
<script src="productivity.js"></script>
|
<script src="productivity.js"></script>
|
||||||
<script src="snooze-ui.js"></script>
|
<script src="snooze-ui.js"></script>
|
||||||
|
|||||||
@@ -784,3 +784,16 @@ if (window.daybreakMail) {
|
|||||||
syncMailbox(false);
|
syncMailbox(false);
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mailUiApi = window.epMailUiModules.createMailUiApi({
|
||||||
|
state: window.epMailState,
|
||||||
|
getConnectedAccount: () => connectedMailAccount,
|
||||||
|
setConnectedAccount: account => { connectedMailAccount = account; },
|
||||||
|
setPageOffset: offset => { mailPageOffset = offset; },
|
||||||
|
syncMailbox,
|
||||||
|
updateAccountCard,
|
||||||
|
renderList,
|
||||||
|
emptyReader,
|
||||||
|
openMailAccount
|
||||||
|
});
|
||||||
|
window.epMailFeatures = Object.freeze({ ...(window.epMailFeatures || {}), mail: mailUiApi });
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
(function installMailUiApiFactory(root) {
|
||||||
|
function createMailUiApi({
|
||||||
|
state,
|
||||||
|
getConnectedAccount,
|
||||||
|
setConnectedAccount,
|
||||||
|
setPageOffset,
|
||||||
|
syncMailbox,
|
||||||
|
updateAccountCard,
|
||||||
|
renderList,
|
||||||
|
emptyReader,
|
||||||
|
openMailAccount
|
||||||
|
}) {
|
||||||
|
return Object.freeze({
|
||||||
|
state,
|
||||||
|
get connectedAccount() { return getConnectedAccount(); },
|
||||||
|
set connectedAccount(account) { setConnectedAccount(account); },
|
||||||
|
setPageOffset,
|
||||||
|
syncMailbox,
|
||||||
|
updateAccountCard,
|
||||||
|
renderList,
|
||||||
|
emptyReader,
|
||||||
|
openMailAccount
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof module === 'object' && module.exports) {
|
||||||
|
module.exports = { createMailUiApi };
|
||||||
|
} else {
|
||||||
|
Object.defineProperty(root, 'epMailUiModules', {
|
||||||
|
value: Object.freeze({ createMailUiApi }),
|
||||||
|
enumerable: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})(typeof window === 'undefined' ? globalThis : window);
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
const CACHE='ep-mail-v10';
|
const CACHE='ep-mail-v11';
|
||||||
const FILES=['./','./index.html','./styles.css','./branding.css','./renderer-state.js','./mail-content-security.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'];
|
const FILES=['./','./index.html','./styles.css','./branding.css','./renderer-state.js','./mail-content-security.js','./renderer-mail-api.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('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('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'))))});
|
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