diff options
author | Dominik Guzei <dominik.guzei@gmail.com> | 2019-08-08 01:00:02 +0200 |
---|---|---|
committer | Dominik Guzei <dominik.guzei@gmail.com> | 2019-08-08 01:02:38 +0200 |
commit | 81d368040d84a923941732ff0a696065764f12a6 (patch) | |
tree | fc5682a3ed7ed1d52672509332fbc35f3935afd5 /src | |
parent | Update en-US.json (diff) | |
download | ferdium-app-81d368040d84a923941732ff0a696065764f12a6.tar.gz ferdium-app-81d368040d84a923941732ff0a696065764f12a6.tar.zst ferdium-app-81d368040d84a923941732ff0a696065764f12a6.zip |
send franz config to todos webview on init
Diffstat (limited to 'src')
-rw-r--r-- | src/features/todos/constants.js | 4 | ||||
-rw-r--r-- | src/features/todos/preload.js | 6 | ||||
-rw-r--r-- | src/features/todos/store.js | 36 |
3 files changed, 36 insertions, 10 deletions
diff --git a/src/features/todos/constants.js b/src/features/todos/constants.js new file mode 100644 index 000000000..2e8a431cc --- /dev/null +++ b/src/features/todos/constants.js | |||
@@ -0,0 +1,4 @@ | |||
1 | export const IPC = { | ||
2 | TODOS_HOST_CHANNEL: 'TODOS_HOST_CHANNEL', | ||
3 | TODOS_CLIENT_CHANNEL: 'TODOS_CLIENT_CHANNEL', | ||
4 | }; | ||
diff --git a/src/features/todos/preload.js b/src/features/todos/preload.js index 533c9aea3..6e38a2ef3 100644 --- a/src/features/todos/preload.js +++ b/src/features/todos/preload.js | |||
@@ -1,4 +1,5 @@ | |||
1 | import { ipcRenderer } from 'electron'; | 1 | import { ipcRenderer } from 'electron'; |
2 | import { IPC } from './constants'; | ||
2 | 3 | ||
3 | const debug = require('debug')('Franz:feature:todos:preload'); | 4 | const debug = require('debug')('Franz:feature:todos:preload'); |
4 | 5 | ||
@@ -9,13 +10,14 @@ let hostMessageListener = () => {}; | |||
9 | window.franz = { | 10 | window.franz = { |
10 | onInitialize(ipcHostMessageListener) { | 11 | onInitialize(ipcHostMessageListener) { |
11 | hostMessageListener = ipcHostMessageListener; | 12 | hostMessageListener = ipcHostMessageListener; |
13 | ipcRenderer.sendToHost(IPC.TODOS_CLIENT_CHANNEL, { action: 'todos:initialized' }); | ||
12 | }, | 14 | }, |
13 | sendToHost(message) { | 15 | sendToHost(message) { |
14 | ipcRenderer.sendToHost('clientMessage', message); | 16 | ipcRenderer.sendToHost(IPC.TODOS_CLIENT_CHANNEL, message); |
15 | }, | 17 | }, |
16 | }; | 18 | }; |
17 | 19 | ||
18 | ipcRenderer.on('hostMessage', (event, message) => { | 20 | ipcRenderer.on(IPC.TODOS_HOST_CHANNEL, (event, message) => { |
19 | debug('Received host message', event, message); | 21 | debug('Received host message', event, message); |
20 | hostMessageListener(message); | 22 | hostMessageListener(message); |
21 | }); | 23 | }); |
diff --git a/src/features/todos/store.js b/src/features/todos/store.js index 79c218b65..acf95df0d 100644 --- a/src/features/todos/store.js +++ b/src/features/todos/store.js | |||
@@ -1,3 +1,4 @@ | |||
1 | import { ThemeType } from '@meetfranz/theme'; | ||
1 | import { | 2 | import { |
2 | computed, | 3 | computed, |
3 | action, | 4 | action, |
@@ -10,6 +11,7 @@ import { FeatureStore } from '../utils/FeatureStore'; | |||
10 | import { createReactions } from '../../stores/lib/Reaction'; | 11 | import { createReactions } from '../../stores/lib/Reaction'; |
11 | import { createActionBindings } from '../utils/ActionBinding'; | 12 | import { createActionBindings } from '../utils/ActionBinding'; |
12 | import { DEFAULT_TODOS_WIDTH, TODOS_MIN_WIDTH, DEFAULT_TODOS_VISIBLE } from '.'; | 13 | import { DEFAULT_TODOS_WIDTH, TODOS_MIN_WIDTH, DEFAULT_TODOS_VISIBLE } from '.'; |
14 | import { IPC } from './constants'; | ||
13 | 15 | ||
14 | const debug = require('debug')('Franz:feature:todos:store'); | 16 | const debug = require('debug')('Franz:feature:todos:store'); |
15 | 17 | ||
@@ -101,22 +103,40 @@ export default class TodoStore extends FeatureStore { | |||
101 | 103 | ||
102 | @action _handleHostMessage = (message) => { | 104 | @action _handleHostMessage = (message) => { |
103 | debug('_handleHostMessage', message); | 105 | debug('_handleHostMessage', message); |
104 | if (message.action === 'create:todo') { | 106 | if (message.action === 'todos:create') { |
105 | this.webview.send('hostMessage', message); | 107 | this.webview.send(IPC.TODOS_HOST_CHANNEL, message); |
106 | } | 108 | } |
107 | }; | 109 | }; |
108 | 110 | ||
109 | @action _handleClientMessage = (message) => { | 111 | @action _handleClientMessage = (message) => { |
110 | debug('_handleClientMessage', message); | 112 | debug('_handleClientMessage', message); |
111 | if (message.action === 'goToService') { | 113 | switch (message.action) { |
112 | const { url, serviceId } = message.data; | 114 | case 'todos:initialized': this._onTodosClientInitialized(); break; |
113 | if (url) { | 115 | case 'todos:goToService': this._goToService(message.data); break; |
114 | this.stores.services.one(serviceId).webview.loadURL(url); | 116 | default: |
115 | } | 117 | debug('Unknown client message reiceived', message); |
116 | this.actions.service.setActive({ serviceId }); | ||
117 | } | 118 | } |
118 | }; | 119 | }; |
119 | 120 | ||
121 | // Todos client message handlers | ||
122 | |||
123 | _onTodosClientInitialized = () => { | ||
124 | this.webview.send(IPC.TODOS_HOST_CHANNEL, { | ||
125 | action: 'todos:configure', | ||
126 | data: { | ||
127 | authToken: this.stores.user.authToken, | ||
128 | theme: this.stores.ui.isDarkThemeActive ? ThemeType.dark : ThemeType.default, | ||
129 | }, | ||
130 | }); | ||
131 | }; | ||
132 | |||
133 | _goToService = ({ url, serviceId }) => { | ||
134 | if (url) { | ||
135 | this.stores.services.one(serviceId).webview.loadURL(url); | ||
136 | } | ||
137 | this.actions.service.setActive({ serviceId }); | ||
138 | }; | ||
139 | |||
120 | // Reactions | 140 | // Reactions |
121 | 141 | ||
122 | _setFeatureEnabledReaction = () => { | 142 | _setFeatureEnabledReaction = () => { |