Refractoring Stage 6.1 Started renderer modularization with shared state.
This commit is contained in:
@@ -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