Skip to content

Reload when 400 Error and unregister service worker #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions webview.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
module.exports = (Franz) => {
"use strict";

const { remote } = require('electron');
const webContents = remote.getCurrentWebContents();
const { session } = webContents;

window.addEventListener('beforeunload', async () => {
try {
session.flushStorageData();
session.clearStorageData({
storages: ['appcache', 'serviceworkers', 'cachestorage', 'websql', 'indexdb']
});
const registrations = await window.navigator.serviceWorker.getRegistrations();
registrations.forEach(r => {
r.unregister();
console.log('ServiceWorker unregistered');
});
} catch (err) {
console.err(err);
}
});

module.exports = Franz => {
function getMessages() {
Franz.setBadge(document.querySelectorAll('mws-conversation-list-item div.text-content.unread').length);
// Reload on error
const el = document.getElementById('af-error-container');

if(el) {
window.location.reload();
}

// Get message count
const messages = document.querySelectorAll('.text-content.unread').length;
Franz.setBadge(messages);
}

// check for new messages every second and update Franz badge
Franz.loop(getMessages);
};