forked from dweinber/franz-recipe-android-messages
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webview.js
52 lines (43 loc) · 1.4 KB
/
webview.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* eslint-disable global-require */
setTimeout(() => {
const elem = document.querySelector('#af-error-container');
if (elem && elem.innerText.toLowerCase().includes('the requested url was not found on this server')) {
window.location.reload();
}
}, 1000);
window.addEventListener('beforeunload', async () => {
try {
if (window.FranzAPI) {
window.FranzAPI.clearCache();
} else {
const { remote } = require('electron');
const webContents = remote.getCurrentWebContents();
const { session } = webContents;
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.error(err);
}
});
module.exports = (Franz, settings) => {
function getMessages() {
const messages = document.querySelectorAll('.text-content.unread').length;
// set Franz badge
Franz.setBadge(messages);
}
if (settings.isDarkModeEnabled) {
localStorage.setItem('dark_mode_enabled', 'true');
} else {
localStorage.setItem('dark_mode_enabled', 'false');
}
// check for new messages every second and update Franz badge
Franz.loop(getMessages);
};