diff options
Diffstat (limited to 'src/features/todos/store.js')
-rw-r--r-- | src/features/todos/store.js | 50 |
1 files changed, 41 insertions, 9 deletions
diff --git a/src/features/todos/store.js b/src/features/todos/store.js index a05203a04..c1d6a9049 100644 --- a/src/features/todos/store.js +++ b/src/features/todos/store.js | |||
@@ -23,7 +23,9 @@ export default class TodoStore extends FeatureStore { | |||
23 | 23 | ||
24 | @observable isFeatureActive = false; | 24 | @observable isFeatureActive = false; |
25 | 25 | ||
26 | webview = null; | 26 | @observable webview = null; |
27 | |||
28 | isInitialized = false; | ||
27 | 29 | ||
28 | @computed get width() { | 30 | @computed get width() { |
29 | const width = this.settings.width || DEFAULT_TODOS_WIDTH; | 31 | const width = this.settings.width || DEFAULT_TODOS_WIDTH; |
@@ -65,6 +67,8 @@ export default class TodoStore extends FeatureStore { | |||
65 | [todoActions.handleHostMessage, this._handleHostMessage], | 67 | [todoActions.handleHostMessage, this._handleHostMessage], |
66 | [todoActions.handleClientMessage, this._handleClientMessage], | 68 | [todoActions.handleClientMessage, this._handleClientMessage], |
67 | [todoActions.toggleTodosFeatureVisibility, this._toggleTodosFeatureVisibility], | 69 | [todoActions.toggleTodosFeatureVisibility, this._toggleTodosFeatureVisibility], |
70 | [todoActions.openDevTools, this._openDevTools], | ||
71 | [todoActions.reload, this._reload], | ||
68 | ])); | 72 | ])); |
69 | 73 | ||
70 | // REACTIONS | 74 | // REACTIONS |
@@ -129,16 +133,28 @@ export default class TodoStore extends FeatureStore { | |||
129 | } | 133 | } |
130 | }; | 134 | }; |
131 | 135 | ||
132 | @action _handleClientMessage = (message) => { | 136 | @action _handleClientMessage = ({ channel, message = {} }) => { |
133 | debug('_handleClientMessage', message); | 137 | debug('_handleClientMessage', channel, message); |
134 | switch (message.action) { | 138 | switch (message.action) { |
135 | case 'todos:initialized': this._onTodosClientInitialized(); break; | 139 | case 'todos:initialized': this._onTodosClientInitialized(); break; |
136 | case 'todos:goToService': this._goToService(message.data); break; | 140 | case 'todos:goToService': this._goToService(message.data); break; |
137 | default: | 141 | default: |
138 | debug('Unknown client message reiceived', message); | 142 | debug('Other message received', channel, message); |
143 | console.log('this.stores.services.isTodosServiceAdded', this.stores.services.isTodosServiceAdded); | ||
144 | if (this.stores.services.isTodosServiceAdded) { | ||
145 | this.actions.service.handleIPCMessage({ | ||
146 | serviceId: this.stores.services.isTodosServiceAdded.id, | ||
147 | channel, | ||
148 | args: message, | ||
149 | }); | ||
150 | } | ||
139 | } | 151 | } |
140 | }; | 152 | }; |
141 | 153 | ||
154 | _handleNewWindowEvent = ({ url }) => { | ||
155 | this.actions.app.openExternalUrl({ url }); | ||
156 | } | ||
157 | |||
142 | @action _toggleTodosFeatureVisibility = () => { | 158 | @action _toggleTodosFeatureVisibility = () => { |
143 | debug('_toggleTodosFeatureVisibility'); | 159 | debug('_toggleTodosFeatureVisibility'); |
144 | 160 | ||
@@ -147,14 +163,28 @@ export default class TodoStore extends FeatureStore { | |||
147 | }); | 163 | }); |
148 | }; | 164 | }; |
149 | 165 | ||
166 | _openDevTools = () => { | ||
167 | debug('_openDevTools'); | ||
168 | |||
169 | const webview = document.querySelector('#todos-panel webview'); | ||
170 | if (webview) webview.openDevTools(); | ||
171 | } | ||
172 | |||
173 | _reload = () => { | ||
174 | debug('_reload'); | ||
175 | |||
176 | const webview = document.querySelector('#todos-panel webview'); | ||
177 | if (webview) webview.reload(); | ||
178 | } | ||
179 | |||
150 | // Todos client message handlers | 180 | // Todos client message handlers |
151 | 181 | ||
152 | _onTodosClientInitialized = () => { | 182 | _onTodosClientInitialized = async () => { |
153 | const { authToken } = this.stores.user; | 183 | const { authToken } = this.stores.user; |
154 | const { isDarkThemeActive } = this.stores.ui; | 184 | const { isDarkThemeActive } = this.stores.ui; |
155 | const { locale } = this.stores.app; | 185 | const { locale } = this.stores.app; |
156 | if (!this.webview) return; | 186 | if (!this.webview) return; |
157 | this.webview.send(IPC.TODOS_HOST_CHANNEL, { | 187 | await this.webview.send(IPC.TODOS_HOST_CHANNEL, { |
158 | action: 'todos:configure', | 188 | action: 'todos:configure', |
159 | data: { | 189 | data: { |
160 | authToken, | 190 | authToken, |
@@ -163,9 +193,11 @@ export default class TodoStore extends FeatureStore { | |||
163 | }, | 193 | }, |
164 | }); | 194 | }); |
165 | 195 | ||
166 | this.webview.addEventListener('new-window', ({ url }) => { | 196 | if (!this.isInitialized) { |
167 | this.actions.app.openExternalUrl({ url }); | 197 | this.webview.addEventListener('new-window', this._handleNewWindowEvent); |
168 | }); | 198 | |
199 | this.isInitialized = true; | ||
200 | } | ||
169 | }; | 201 | }; |
170 | 202 | ||
171 | _goToService = ({ url, serviceId }) => { | 203 | _goToService = ({ url, serviceId }) => { |