diff options
author | Vijay A <vraravam@users.noreply.github.com> | 2021-10-18 07:33:47 +0530 |
---|---|---|
committer | Vijay A <vraravam@users.noreply.github.com> | 2021-10-18 07:33:47 +0530 |
commit | 3e28975d32315444c4c535fda7ba2aa08a3a0bc2 (patch) | |
tree | ef7f7d9083b1d437b2cf68005cd6b831f526729c /src/features/todos/preload.ts | |
parent | Bumped up version to: 5.6.3-beta.1 [skip ci] (diff) | |
parent | 5.6.3-nightly.37 [skip ci] (diff) | |
download | ferdium-app-3e28975d32315444c4c535fda7ba2aa08a3a0bc2.tar.gz ferdium-app-3e28975d32315444c4c535fda7ba2aa08a3a0bc2.tar.zst ferdium-app-3e28975d32315444c4c535fda7ba2aa08a3a0bc2.zip |
Merge branch 'nightly' into release
Diffstat (limited to 'src/features/todos/preload.ts')
-rw-r--r-- | src/features/todos/preload.ts | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/features/todos/preload.ts b/src/features/todos/preload.ts new file mode 100644 index 000000000..31d473051 --- /dev/null +++ b/src/features/todos/preload.ts | |||
@@ -0,0 +1,59 @@ | |||
1 | import { ipcRenderer } from 'electron'; | ||
2 | import { IPC } from './constants'; | ||
3 | |||
4 | const debug = require('debug')('Ferdi:feature:todos:preload'); | ||
5 | |||
6 | debug('Preloading Todos Webview'); | ||
7 | |||
8 | let hostMessageListener = ({ action }) => { | ||
9 | switch (action) { | ||
10 | case 'todos:initialize-as-service': | ||
11 | ipcRenderer.sendToHost('hello'); | ||
12 | break; | ||
13 | default: | ||
14 | } | ||
15 | }; | ||
16 | |||
17 | window['ferdi'] = { | ||
18 | onInitialize(ipcHostMessageListener) { | ||
19 | hostMessageListener = ipcHostMessageListener; | ||
20 | ipcRenderer.sendToHost(IPC.TODOS_CLIENT_CHANNEL, { | ||
21 | action: 'todos:initialized', | ||
22 | }); | ||
23 | }, | ||
24 | sendToHost(message) { | ||
25 | ipcRenderer.sendToHost(IPC.TODOS_CLIENT_CHANNEL, message); | ||
26 | }, | ||
27 | }; | ||
28 | |||
29 | ipcRenderer.on(IPC.TODOS_HOST_CHANNEL, (event, message) => { | ||
30 | debug('Received host message', event, message); | ||
31 | hostMessageListener(message); | ||
32 | }); | ||
33 | |||
34 | if (window.location.href === 'https://app.franztodos.com/login/') { | ||
35 | // Insert info element informing about Franz accounts | ||
36 | const infoElement = document.createElement('p'); | ||
37 | infoElement.textContent = `You are using Franz's official Todo Service. | ||
38 | This service will only work with accounts registered with Franz - no Ferdi accounts will work here! | ||
39 | If you do not have a Franz account you can change the Todo service by going into Ferdi's settings and changing the "Todo server". | ||
40 | You can choose any service as this Todo server, e.g. Todoist or Apple Notes.`; | ||
41 | |||
42 | // Franz Todos uses React. Because of this we can't directly insert the element into the page | ||
43 | // but we have to wait for React to finish rendering the login page | ||
44 | let numChecks = 0; | ||
45 | const waitForReact = setInterval(() => { | ||
46 | const textElement = document.querySelector('p'); | ||
47 | if (textElement) { | ||
48 | clearInterval(waitForReact); | ||
49 | textElement.parentElement?.insertBefore(infoElement, textElement); | ||
50 | } else { | ||
51 | numChecks += 1; | ||
52 | |||
53 | // Stop after ~10 seconds. We are probably not on the login page | ||
54 | if (numChecks > 1000) { | ||
55 | clearInterval(waitForReact); | ||
56 | } | ||
57 | } | ||
58 | }, 10); | ||
59 | } | ||