From 718ceb6efe9d05208ce183c6153399ed1d887292 Mon Sep 17 00:00:00 2001 From: Tero Date: Fri, 16 Oct 2026 21:48:40 +0300 Subject: [PATCH] =?UTF-8?q?=20Refractoring=20Stage=206.9=20Moved=20the=20O?= =?UTF-8?q?penPGP=20key=20UI=E2=80=99s=20active-account=20lookup=20to=20th?= =?UTF-8?q?e=20mail=20feature=20API.=20The=20renderer=20now=20uses=20expli?= =?UTF-8?q?cit=20APIs=20for=20account,=20snooze,=20attachment,=20OpenPGP?= =?UTF-8?q?=20mail/key,=20shortcuts,=20and=20DAV=20integrations;=20remaini?= =?UTF-8?q?ng=20transitional=20globals=20are=20mainly=20in=20the=20core=20?= =?UTF-8?q?shell=20and=20cross-feature=20hooks.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- REFACTOR_PLAN.md | 7 +- mail-ui.js | 215 ++++++++++++++++--------------- package-lock.json | 4 +- package.json | 2 +- pgp-ui.js | 2 +- tests/renderer-mail-api.test.cjs | 3 + www/mail-ui.js | 215 ++++++++++++++++--------------- www/pgp-ui.js | 2 +- 8 files changed, 228 insertions(+), 222 deletions(-) diff --git a/REFACTOR_PLAN.md b/REFACTOR_PLAN.md index 67a7fd9..c76843c 100644 --- a/REFACTOR_PLAN.md +++ b/REFACTOR_PLAN.md @@ -108,6 +108,7 @@ This is a gradual destination, not a requirement to move everything at once. IPC - [x] Migrate OpenPGP mail UI reader/compose hooks to the mail feature API (`pgp-mail-ui.js`). - [x] Migrate shortcut mail-state access and preferences extension to feature APIs (`shortcuts.js`, `productivity.js`). - [x] Migrate Calendar/Contacts navigation and DAV UI to the productivity feature API (`app.js`, `dav-ui.js`). +- [x] Migrate OpenPGP key UI to the mail feature API for active-account access (`pgp-ui.js`). - [x] Make the core app shell consume the namespaced renderer state instead of compatibility aliases. - [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. @@ -137,7 +138,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.19`; Android derives `versionName 0.4.19` and `versionCode 419`. `release/` contains the user-verified Windows artifact `0.4.19`. +- Latest version check: `package.json` and both lockfile version fields are `0.4.21`; Android derives `versionName 0.4.21` and `versionCode 421`. The checked-in `release/` directory contains Windows artifacts through `0.4.20`; the user confirms the current artifact works. ## Progress log @@ -156,9 +157,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 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. Package/lockfile are `0.4.19`, with Android build number `419`; the user-verified artifact is `0.4.18`. +- Added a build-version consistency check. Package/lockfile are `0.4.21`, with Android build number `421`; the user confirms the current artifact works. - 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`, 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 migrated snooze, attachment, OpenPGP mail, shortcut, productivity state/render, and DAV UI integrations to feature APIs; compatibility globals remain in the core shell and some cross-feature hooks. The core app now reads shared state through `renderer-state.js`; the suite passes 123 tests. +- Step 6 migrated snooze, attachment, OpenPGP mail/key, shortcut, productivity state/render, and DAV UI integrations to feature APIs; compatibility globals remain in the core shell and some cross-feature hooks. The core app now reads shared state through `renderer-state.js`; the suite passes 123 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. diff --git a/mail-ui.js b/mail-ui.js index b351145..8c71809 100644 --- a/mail-ui.js +++ b/mail-ui.js @@ -1,10 +1,15 @@ -let connectedMailAccount = null; -let mailPageOffset = 0; -let mailTotal = 0; -let mailboxSyncPromise = null; -let mailboxSyncQueued = false; -let mailboxRefreshPending = false; -let folderBeforeSearch = null; +const rendererState = window.epMailState; +const mailFeatureState = { + connectedAccount: null, + pageOffset: 0, + total: 0, + syncPromise: null, + syncQueued: false, + refreshPending: false, + folderBeforeSearch: null, + customFolders: [], + selectedDraftIds: new Set() +}; const senderBrandDomains = { amazon: ['amazon.com', 'amazon.co.uk'], @@ -65,7 +70,7 @@ function messageLinks(message) { const originalOpenMessage = openMessage; openMessage = function (id) { originalOpenMessage(id); - const message = messages.find(item => item.id === id); + const message = rendererState.messages.find(item => item.id === id); if (!message) return; const senderReasons = suspiciousSenderReasons(message); const links = messageLinks(message); @@ -102,16 +107,14 @@ openMessage = function (id) { } }; -let customFolders = []; - function renderCustomFolders() { const box = $('#custom-folders'); if (!box) return; - box.replaceChildren(...customFolders.map(folder => { + box.replaceChildren(...mailFeatureState.customFolders.map(folder => { const button = document.createElement('button'); button.className = 'folder custom-folder'; button.dataset.folder = folder.id; - button.classList.toggle('active', activeFolder === folder.id); + button.classList.toggle('active', rendererState.activeFolder === folder.id); const glyph = document.createElement('span'); glyph.className = 'nav-glyph'; glyph.textContent = '▭'; @@ -120,12 +123,12 @@ function renderCustomFolders() { button.title = folder.path; button.append(glyph, label); button.addEventListener('click', () => { - if ($('#filter-folder').value) { $('#filter-folder').value = ''; folderBeforeSearch = null; } - activeFolder = folder.id; + if ($('#filter-folder').value) { $('#filter-folder').value = ''; mailFeatureState.folderBeforeSearch = null; } + rendererState.activeFolder = folder.id; $$('.folder').forEach(item => item.classList.toggle('active', item === button)); $('#sidebar-title').textContent = folder.name; $('#crumb-current').textContent = folder.name; - mailPageOffset = 0; + mailFeatureState.pageOffset = 0; void syncMailbox(false, { offset: 0 }); }); return button; @@ -133,16 +136,16 @@ function renderCustomFolders() { } async function loadCustomFolders() { - if (!connectedMailAccount || !window.daybreakMail?.listFolders) return; + if (!mailFeatureState.connectedAccount || !window.daybreakMail?.listFolders) return; try { - customFolders = (await window.daybreakMail.listFolders()).folders || []; + mailFeatureState.customFolders = (await window.daybreakMail.listFolders()).folders || []; renderCustomFolders(); } catch {} } // Destination options for the mail-rule folder picker: built-in folders plus the account's IMAP folders. function ruleFolderSelect(selected = 'Inbox') { - const options = [['Inbox', 'Inbox'], ['Archive', 'Archive'], ['Trash', 'Trash'], ...customFolders.map(folder => [folder.id, folder.name])]; + const options = [['Inbox', 'Inbox'], ['Archive', 'Archive'], ['Trash', 'Trash'], ...mailFeatureState.customFolders.map(folder => [folder.id, folder.name])]; if (!options.some(([value]) => value === selected)) { options.push([selected, String(selected).replace(/^[^:]*:/, '') || selected]); } @@ -170,12 +173,12 @@ function askText(title, label, placeholder = '') { } async function createMailFolder() { - if (!connectedMailAccount || !window.daybreakMail?.createFolder) { openMailAccount(); return; } + if (!mailFeatureState.connectedAccount || !window.daybreakMail?.createFolder) { openMailAccount(); return; } const name = await askText('New mail folder', 'Name'); if (!name) return; try { const result = await window.daybreakMail.createFolder(name); - customFolders = result.folders || customFolders; + mailFeatureState.customFolders = result.folders || mailFeatureState.customFolders; renderCustomFolders(); toast(`Folder “${result.folder?.name || name}” created`); } catch (error) { @@ -281,9 +284,9 @@ function openMailAccount(existingAccount = null) { if (editing) { const accountList = await window.daybreakMail.listAccounts(); if (accountList.activeId === account.id) { - connectedMailAccount = account; + mailFeatureState.connectedAccount = account; updateAccountCard(account); - mailPageOffset = 0; + mailFeatureState.pageOffset = 0; close(); await syncMailbox(false, { offset: 0 }); } else { @@ -291,7 +294,7 @@ function openMailAccount(existingAccount = null) { } toast('Mailbox settings updated'); } else { - connectedMailAccount = account; + mailFeatureState.connectedAccount = account; updateAccountCard(account); close(); toast('Mailbox connected securely'); @@ -317,15 +320,13 @@ function mailSearchFilters() { }; } -const selectedDraftIds = new Set(); - async function deleteSelectedDrafts() { - const ids = messages.map(message => String(message.id)).filter(id => selectedDraftIds.has(id)); + const ids = rendererState.messages.map(message => String(message.id)).filter(id => mailFeatureState.selectedDraftIds.has(id)); if (!ids.length) { toast('Select one or more drafts first'); return; } if (!confirm(`Delete ${ids.length} selected draft${ids.length === 1 ? '' : 's'}?`)) return; try { for (const id of ids) await window.daybreakMail.deleteDraft(id); - selectedDraftIds.clear(); + mailFeatureState.selectedDraftIds.clear(); toast(`${ids.length} draft${ids.length === 1 ? '' : 's'} deleted`); await syncMailbox(false); } catch (error) { toast(error.message || 'Could not delete the drafts'); } @@ -333,22 +334,22 @@ async function deleteSelectedDrafts() { // In the Drafts folder the shared toolbar acts on drafts, which use string ids. document.addEventListener('click', event => { - if (activeFolder !== 'Drafts') return; + if (rendererState.activeFolder !== 'Drafts') return; const button = event.target.closest('#select-all, #delete-selected, #archive-selected, #mark-unread'); if (!button) return; event.stopImmediatePropagation(); if (button.id === 'select-all') { - const ids = messages.map(message => String(message.id)); - const all = ids.length && ids.every(id => selectedDraftIds.has(id)); - ids.forEach(id => all ? selectedDraftIds.delete(id) : selectedDraftIds.add(id)); - renderDrafts(messages.map(message => message.draft)); + const ids = rendererState.messages.map(message => String(message.id)); + const all = ids.length && ids.every(id => mailFeatureState.selectedDraftIds.has(id)); + ids.forEach(id => all ? mailFeatureState.selectedDraftIds.delete(id) : mailFeatureState.selectedDraftIds.add(id)); + renderDrafts(rendererState.messages.map(message => message.draft)); } else if (button.id === 'delete-selected') void deleteSelectedDrafts(); }, true); function renderDrafts(drafts) { const present = new Set(drafts.map(draft => String(draft.id))); - [...selectedDraftIds].forEach(id => { if (!present.has(id)) selectedDraftIds.delete(id); }); - messages.splice(0, messages.length, ...drafts.map(draft => ({ + [...mailFeatureState.selectedDraftIds].forEach(id => { if (!present.has(id)) mailFeatureState.selectedDraftIds.delete(id); }); + rendererState.messages.splice(0, rendererState.messages.length, ...drafts.map(draft => ({ id: draft.id, sender: 'Draft', email: draft.to || 'No recipient', @@ -360,19 +361,19 @@ function renderDrafts(drafts) { color: '#dce6df', draft }))); - $('#message-list').innerHTML = messages.length ? messages.map(message => ` -
${message.initials}
+ $('#message-list').innerHTML = rendererState.messages.length ? rendererState.messages.map(message => ` +
${message.initials}
${esc(message.email)}
${esc(message.subject)}
${esc(message.snippet)}
${esc(message.date)}
`).join('') : '
✎

No saved drafts

Drafts are saved on this device and available offline.

'; const start = $('#start-draft'); if (start) start.onclick = () => showCompose(); $$('.message').forEach(row => row.onclick = event => { - const draft = messages.find(message => String(message.id) === row.dataset.id)?.draft; + const draft = rendererState.messages.find(message => String(message.id) === row.dataset.id)?.draft; if (event.target.closest('.row-check')) { event.stopPropagation(); const id = row.dataset.id; - selectedDraftIds.has(id) ? selectedDraftIds.delete(id) : selectedDraftIds.add(id); + mailFeatureState.selectedDraftIds.has(id) ? mailFeatureState.selectedDraftIds.delete(id) : mailFeatureState.selectedDraftIds.add(id); return; } if (event.target.closest('.draft-delete')) { @@ -386,7 +387,7 @@ function renderDrafts(drafts) { if (draft) showCompose(null, false, draft); }); $('#reader-pane').innerHTML = emptyReader(); - $('#pagination').textContent = `${messages.length} drafts`; + $('#pagination').textContent = `${rendererState.messages.length} drafts`; $('#load-more').classList.add('hidden'); } @@ -509,7 +510,7 @@ function setupDraftComposer() { try { await persist(); toast('Draft saved on this device'); - if (activeFolder === 'Drafts') void syncMailbox(false); + if (rendererState.activeFolder === 'Drafts') void syncMailbox(false); } catch (error) { toast(error.message || 'Could not save draft'); } }; modal.addEventListener('input', () => { @@ -519,13 +520,13 @@ function setupDraftComposer() { modal.querySelector('.modal-overlay')?.addEventListener('click', event => { if (!event.target.classList.contains('modal-overlay')) return; clearTimeout(saveTimer); - persist().then(() => { if (activeFolder === 'Drafts') void syncMailbox(false); }) + persist().then(() => { if (rendererState.activeFolder === 'Drafts') void syncMailbox(false); }) .catch(error => toast(error.message || 'Could not save draft')); closed = true; }, true); root.querySelector('.modal-close')?.addEventListener('click', () => { clearTimeout(saveTimer); - persist().then(() => { if (activeFolder === 'Drafts') void syncMailbox(false); }) + persist().then(() => { if (rendererState.activeFolder === 'Drafts') void syncMailbox(false); }) .catch(error => toast(error.message || 'Could not save draft')); closed = true; }, true); @@ -535,7 +536,7 @@ function setupDraftComposer() { try { if (modal.dataset.draftId) await window.daybreakMail.deleteDraft(modal.dataset.draftId); root.innerHTML = ''; - if (activeFolder === 'Drafts') void syncMailbox(false); + if (rendererState.activeFolder === 'Drafts') void syncMailbox(false); } catch (error) { toast(error.message || 'Could not delete draft'); } }; $('#send').addEventListener('click', () => { @@ -546,11 +547,11 @@ function setupDraftComposer() { } async function syncMailbox(showToast, options = {}) { - if (mailboxSyncPromise) { - mailboxSyncQueued = true; - return mailboxSyncPromise; + if (mailFeatureState.syncPromise) { + mailFeatureState.syncQueued = true; + return mailFeatureState.syncPromise; } - if (!connectedMailAccount || !window.daybreakMail) { + if (!mailFeatureState.connectedAccount || !window.daybreakMail) { openMailAccount(); return; } @@ -558,48 +559,48 @@ async function syncMailbox(showToast, options = {}) { if (refresh) refresh.disabled = true; const sync = (async () => { try { - if (activeFolder === 'Drafts') { + if (rendererState.activeFolder === 'Drafts') { const result = await window.daybreakMail.listDrafts(); renderDrafts(result.drafts || []); if (showToast) toast(`${result.drafts.length} saved drafts`); return; } - const previouslyActiveMessage = activeMessage; - const offset = options.offset ?? (options.append ? mailPageOffset + messages.length : mailPageOffset); - const result = await window.daybreakMail.syncFolder(activeFolder, offset, mailSearchFilters()); - if (options.append) messages.push(...result.messages); - else messages.splice(0, messages.length, ...result.messages); - messages.forEach(message => { + const previouslyActiveMessage = rendererState.activeMessage; + const offset = options.offset ?? (options.append ? mailFeatureState.pageOffset + rendererState.messages.length : mailFeatureState.pageOffset); + const result = await window.daybreakMail.syncFolder(rendererState.activeFolder, offset, mailSearchFilters()); + if (options.append) rendererState.messages.push(...result.messages); + else rendererState.messages.splice(0, rendererState.messages.length, ...result.messages); + rendererState.messages.forEach(message => { try { const localTags = JSON.parse(localStorage.getItem(`daybreak-message-labels-${message.id}`) || '[]'); message.tags = [...new Set([...(message.tags || []), ...localTags])]; } catch {} }); - if (!options.append) mailPageOffset = offset; - mailTotal = result.total; - activeMessage = messages.some(message => message.id === previouslyActiveMessage) + if (!options.append) mailFeatureState.pageOffset = offset; + mailFeatureState.total = result.total; + rendererState.activeMessage = rendererState.messages.some(message => message.id === previouslyActiveMessage) ? previouslyActiveMessage - : messages[0]?.id; - selectedIds.clear(); - const unread = messages.filter(message => message.unread).length; + : rendererState.messages[0]?.id; + rendererState.selectedIds.clear(); + const unread = rendererState.messages.filter(message => message.unread).length; const inboxCount = $('.folder[data-folder="Inbox"] .count'); if (inboxCount) inboxCount.textContent = String(unread); const pagination = $('#pagination'); if (pagination) pagination.textContent = result.total ? `${options.append ? 1 : result.start}–${options.append ? Math.min(offset + result.messages.length, result.total) : result.end} of ${result.total}` : '0 messages'; const loadMore = $('#load-more'); - if (loadMore) loadMore.classList.toggle('hidden', mailPageOffset + messages.length >= result.total); + if (loadMore) loadMore.classList.toggle('hidden', mailFeatureState.pageOffset + rendererState.messages.length >= result.total); query = ''; renderList(); - if (activeMessage) { - openMessage(activeMessage); - const current = messages.find(message => message.id === activeMessage); - if (current?.uid) window.daybreakMail.updateMessage({ uid: current.uid, folder: current.sourceFolder || activeFolder, action: 'unread', enabled: false }).catch(() => {}); + if (rendererState.activeMessage) { + openMessage(rendererState.activeMessage); + const current = rendererState.messages.find(message => message.id === rendererState.activeMessage); + if (current?.uid) window.daybreakMail.updateMessage({ uid: current.uid, folder: current.sourceFolder || rendererState.activeFolder, action: 'unread', enabled: false }).catch(() => {}); } else $('#reader-pane').innerHTML = emptyReader(); - updateAccountCard(connectedMailAccount); + updateAccountCard(mailFeatureState.connectedAccount); const status = $('#mail-status'); if (status) status.textContent = result.offline ? 'Offline — showing saved messages' : 'All caught up with your mail'; - if (showToast) toast(`Synced ${messages.length} messages`); + if (showToast) toast(`Synced ${rendererState.messages.length} messages`); } catch (error) { toast(error.message || 'Could not sync the inbox'); } finally { @@ -607,13 +608,13 @@ async function syncMailbox(showToast, options = {}) { } })(); - mailboxSyncPromise = sync; + mailFeatureState.syncPromise = sync; try { await sync; } finally { - mailboxSyncPromise = null; - if (mailboxSyncQueued) { - mailboxSyncQueued = false; + mailFeatureState.syncPromise = null; + if (mailFeatureState.syncQueued) { + mailFeatureState.syncQueued = false; void syncMailbox(false); } } @@ -636,28 +637,28 @@ if (window.daybreakMail) { $('#filter-before').value = ''; $('#filter-attachments').checked = false; $('#search').value = ''; - activeFolder = folderBeforeSearch || activeFolder; - folderBeforeSearch = null; - $$('.folder').forEach(button => button.classList.toggle('active', button.dataset.folder === activeFolder)); - $('#sidebar-title').textContent = activeFolder; - $('#crumb-current').textContent = activeFolder; + rendererState.activeFolder = mailFeatureState.folderBeforeSearch || rendererState.activeFolder; + mailFeatureState.folderBeforeSearch = null; + $$('.folder').forEach(button => button.classList.toggle('active', button.dataset.folder === rendererState.activeFolder)); + $('#sidebar-title').textContent = rendererState.activeFolder; + $('#crumb-current').textContent = rendererState.activeFolder; query = ''; renderList(); - mailPageOffset = 0; + mailFeatureState.pageOffset = 0; void syncMailbox(false, { offset: 0 }); }; for (const selector of searchControls) { $(selector).addEventListener(selector === '#search' ? 'input' : 'change', () => { if (selector === '#filter-folder' && $('#filter-folder').value) { - if (!folderBeforeSearch) folderBeforeSearch = activeFolder; - activeFolder = $('#filter-folder').value; - $$('.folder').forEach(button => button.classList.toggle('active', button.dataset.folder === activeFolder)); - $('#sidebar-title').textContent = activeFolder; - $('#crumb-current').textContent = activeFolder; + if (!mailFeatureState.folderBeforeSearch) mailFeatureState.folderBeforeSearch = rendererState.activeFolder; + rendererState.activeFolder = $('#filter-folder').value; + $$('.folder').forEach(button => button.classList.toggle('active', button.dataset.folder === rendererState.activeFolder)); + $('#sidebar-title').textContent = rendererState.activeFolder; + $('#crumb-current').textContent = rendererState.activeFolder; } clearTimeout(searchTimer); searchTimer = setTimeout(() => { - mailPageOffset = 0; + mailFeatureState.pageOffset = 0; void syncMailbox(false, { offset: 0 }); }, selector === '#search' ? 350 : 0); }); @@ -668,7 +669,7 @@ if (window.daybreakMail) { console.error('Could not read app version:', error); }); window.daybreakMail.onSyncUpdate(update => { - if (update.accountId !== connectedMailAccount?.id) return; + if (update.accountId !== mailFeatureState.connectedAccount?.id) return; if (update.error) { toast(update.error); return; @@ -677,23 +678,23 @@ if (window.daybreakMail) { if (document.visibilityState === 'visible') { syncMailbox(false, update.newCount ? { offset: 0 } : {}); } - else mailboxRefreshPending = true; + else mailFeatureState.refreshPending = true; } }); document.addEventListener('visibilitychange', () => { - if (document.visibilityState === 'visible' && mailboxRefreshPending) { - mailboxRefreshPending = false; + if (document.visibilityState === 'visible' && mailFeatureState.refreshPending) { + mailFeatureState.refreshPending = false; syncMailbox(false, { offset: 0 }); } }); window.addEventListener('focus', () => { - if (connectedMailAccount) syncMailbox(false); + if (mailFeatureState.connectedAccount) syncMailbox(false); }); window.addEventListener('online', () => { - if (connectedMailAccount) syncMailbox(false, { offset: 0 }); + if (mailFeatureState.connectedAccount) syncMailbox(false, { offset: 0 }); }); setInterval(() => { - if (connectedMailAccount && document.visibilityState === 'visible' && activeView === 'mail') { + if (mailFeatureState.connectedAccount && document.visibilityState === 'visible' && rendererState.activeView === 'mail') { syncMailbox(false); } }, 60 * 1000); @@ -707,27 +708,27 @@ if (window.daybreakMail) { $$('.folder').forEach(button => button.addEventListener('click', () => { if ($('#filter-folder').value) { $('#filter-folder').value = ''; - folderBeforeSearch = null; + mailFeatureState.folderBeforeSearch = null; } if (['Inbox', 'Sent', 'Archive', 'Trash', 'Starred', 'Drafts'].includes(button.dataset.folder)) { - mailPageOffset = 0; + mailFeatureState.pageOffset = 0; syncMailbox(false, { offset: 0 }); } })); $('#previous-page').onclick = () => { - if (mailPageOffset <= 0) return; - mailPageOffset = Math.max(0, mailPageOffset - 20); - syncMailbox(false, { offset: mailPageOffset }); + if (mailFeatureState.pageOffset <= 0) return; + mailFeatureState.pageOffset = Math.max(0, mailFeatureState.pageOffset - 20); + syncMailbox(false, { offset: mailFeatureState.pageOffset }); }; $('#next-page').onclick = () => { - if (mailPageOffset + 20 >= mailTotal) return; - mailPageOffset += 20; - syncMailbox(false, { offset: mailPageOffset }); + if (mailFeatureState.pageOffset + 20 >= mailFeatureState.total) return; + mailFeatureState.pageOffset += 20; + syncMailbox(false, { offset: mailFeatureState.pageOffset }); }; $('#load-more').onclick = () => syncMailbox(false, { append: true }); document.addEventListener('click', async event => { const sendButton = event.target.closest('#send'); - if (!sendButton || !connectedMailAccount) return; + if (!sendButton || !mailFeatureState.connectedAccount) return; event.preventDefault(); event.stopImmediatePropagation(); const recipient = $('#compose-to').value.trim(); @@ -749,7 +750,7 @@ if (window.daybreakMail) { subject: $('#compose-subject').value.trim(), text: $('#compose-body').value, attachments: $('#modal-root .compose-modal')?._composeAttachments || [], - displayName: connectedMailAccount.displayName || window.epMailFeatures.productivity?.profileName || '', + displayName: mailFeatureState.connectedAccount.displayName || window.epMailFeatures.productivity?.profileName || '', ...(pgp ? { pgp } : {}) }); if (result.failed) { @@ -763,15 +764,15 @@ if (window.daybreakMail) { if (draftId) await window.daybreakMail.deleteDraft(draftId); $('#modal-root').innerHTML = ''; toast('Offline: message queued and will send when connected'); - if (activeFolder === 'Drafts') void syncMailbox(false); + if (rendererState.activeFolder === 'Drafts') void syncMailbox(false); return; } const draftId = $('#modal-root .compose-modal')?.dataset.draftId; if (draftId) await window.daybreakMail.deleteDraft(draftId); $('#modal-root').innerHTML = ''; toast(result.savedToSent ? 'Message sent and saved in Sent' : 'Message sent, but its Sent copy could not be saved'); - if (activeFolder === 'Sent') syncMailbox(false, { offset: 0 }); - if (activeFolder === 'Drafts') void syncMailbox(false); + if (rendererState.activeFolder === 'Sent') syncMailbox(false, { offset: 0 }); + if (rendererState.activeFolder === 'Drafts') void syncMailbox(false); } catch (error) { sendButton.disabled = false; sendButton.textContent = 'Send ↗'; @@ -781,7 +782,7 @@ if (window.daybreakMail) { window.daybreakMail.getAccount().then(account => { if (!account) return; - connectedMailAccount = account; + mailFeatureState.connectedAccount = account; updateAccountCard(account); syncMailbox(false); }).catch(() => {}); @@ -789,9 +790,9 @@ if (window.daybreakMail) { const mailUiApi = window.epMailUiModules.createMailUiApi({ state: window.epMailState, - getConnectedAccount: () => connectedMailAccount, - setConnectedAccount: account => { connectedMailAccount = account; }, - setPageOffset: offset => { mailPageOffset = offset; }, + getConnectedAccount: () => mailFeatureState.connectedAccount, + setConnectedAccount: account => { mailFeatureState.connectedAccount = account; }, + setPageOffset: offset => { mailFeatureState.pageOffset = offset; }, syncMailbox, updateAccountCard, getRenderList: () => renderList, diff --git a/package-lock.json b/package-lock.json index 031a354..3e6f80c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ep-mail", - "version": "0.4.20", + "version": "0.4.21", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ep-mail", - "version": "0.4.20", + "version": "0.4.21", "dependencies": { "@capacitor/android": "^8.5.2", "@capacitor/core": "^8.5.2", diff --git a/package.json b/package.json index 2bec4a8..d2f1417 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ep-mail", - "version": "0.4.20", + "version": "0.4.21", "private": true, "description": "Eternity Project mail client", "homepage": "https://git.eternityproject.fi/thuttu/ep-mail-client", diff --git a/pgp-ui.js b/pgp-ui.js index 443d464..992b237 100644 --- a/pgp-ui.js +++ b/pgp-ui.js @@ -3,7 +3,7 @@ function pgpAvailable() { return Boolean(window.daybreakMail?.pgp); } function openEncryptionKeys() { const root = $('#modal-root'); - const account = connectedMailAccount || {}; + const account = window.epMailFeatures.mail.connectedAccount || {}; root.innerHTML = `