mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-02 00:14:23 +00:00
fix: keep the sign-in page from creating the offline database again #523
This commit is contained in:
@@ -220,3 +220,15 @@ describe('signing out with unsent mail', () => {
|
||||
expect(await passSignOutGates('all')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('after a sign-out', () => {
|
||||
it('starting offline mode on the sign-in page doesn\'t create the database again', async () => {
|
||||
const stop = startOfflineMode();
|
||||
await new Promise((r) => setTimeout(r, 50));
|
||||
const { refreshQueueState, refreshUsage } = await import('../offline-mode');
|
||||
await refreshQueueState();
|
||||
await refreshUsage();
|
||||
stop();
|
||||
expect((await indexedDB.databases()).map((d) => d.name)).not.toContain('bulwark-offline');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -403,6 +403,12 @@ function decodeMimeWords(value: string): string {
|
||||
/** Reads the queue into the store, for the outbox view and the banner. */
|
||||
export async function refreshQueueState(): Promise<void> {
|
||||
if (!offlineSupported()) return;
|
||||
// Nothing is kept for an account that hasn't it on; and opening the
|
||||
// database would create it (on the sign-in page, after a sign-out).
|
||||
if (useOfflineStore.getState().enabled.length === 0) {
|
||||
useOfflineStore.setState({ outbox: [], pendingChanges: 0 });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const { patches, outbox: entries } = await readQueue();
|
||||
const rows: OutboxRow[] = entries.map((entry) => ({
|
||||
@@ -421,7 +427,7 @@ export async function refreshQueueState(): Promise<void> {
|
||||
}
|
||||
|
||||
export async function refreshUsage(): Promise<void> {
|
||||
if (!offlineSupported()) return;
|
||||
if (!offlineSupported() || useOfflineStore.getState().enabled.length === 0) return;
|
||||
try {
|
||||
useOfflineStore.setState({ usageBytes: (await cacheUsage()).total });
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user