diff options
author | Kristóf Marussy <kristof@marussy.com> | 2021-06-03 19:01:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-03 19:01:01 +0200 |
commit | 2ad39ffb1cb0d0e5f79d6948f798ca79ed73c76c (patch) | |
tree | dcb679119cf4963126a3520b7c62ae4b032e0225 /src/features | |
parent | Upgraded electron to '13.1.0'. (diff) | |
download | ferdium-app-2ad39ffb1cb0d0e5f79d6948f798ca79ed73c76c.tar.gz ferdium-app-2ad39ffb1cb0d0e5f79d6948f798ca79ed73c76c.tar.zst ferdium-app-2ad39ffb1cb0d0e5f79d6948f798ca79ed73c76c.zip |
* Expose Chrome version to todos webview (fix #1211)
The TickTick todo service fails to load if the Chrome version number
does not appear in the User-Agent string. However, login to Google Tasks
is prevented by the same.
We adopt the "chromeless" User-Agent logic from the service webview,
which selectively exposes the Chrome version everywhere except the
Google login screen. The common logic was moved into the
userAgent-helpers module.
* Refactor user agent switching
* "Chromeless" user agent switching is extracted into a separate model
* Both the service and the todos webview uses the same model
Diffstat (limited to 'src/features')
-rw-r--r-- | src/features/todos/components/TodosWebview.js | 10 | ||||
-rw-r--r-- | src/features/todos/containers/TodosScreen.js | 1 | ||||
-rw-r--r-- | src/features/todos/store.js | 13 |
3 files changed, 16 insertions, 8 deletions
diff --git a/src/features/todos/components/TodosWebview.js b/src/features/todos/components/TodosWebview.js index 18a900e8a..634ec4caa 100644 --- a/src/features/todos/components/TodosWebview.js +++ b/src/features/todos/components/TodosWebview.js | |||
@@ -14,8 +14,6 @@ import Appear from '../../../components/ui/effects/Appear'; | |||
14 | import UpgradeButton from '../../../components/ui/UpgradeButton'; | 14 | import UpgradeButton from '../../../components/ui/UpgradeButton'; |
15 | import { TODOS_PARTITION_ID } from '..'; | 15 | import { TODOS_PARTITION_ID } from '..'; |
16 | 16 | ||
17 | import userAgent from '../../../helpers/userAgent-helpers'; | ||
18 | |||
19 | // NOTE: https://stackoverflow.com/questions/5717093/check-if-a-javascript-string-is-a-url | 17 | // NOTE: https://stackoverflow.com/questions/5717093/check-if-a-javascript-string-is-a-url |
20 | function validURL(str) { | 18 | function validURL(str) { |
21 | let url; | 19 | let url; |
@@ -112,6 +110,7 @@ class TodosWebview extends Component { | |||
112 | resize: PropTypes.func.isRequired, | 110 | resize: PropTypes.func.isRequired, |
113 | width: PropTypes.number.isRequired, | 111 | width: PropTypes.number.isRequired, |
114 | minWidth: PropTypes.number.isRequired, | 112 | minWidth: PropTypes.number.isRequired, |
113 | userAgent: PropTypes.string.isRequired, | ||
115 | isTodosIncludedInCurrentPlan: PropTypes.bool.isRequired, | 114 | isTodosIncludedInCurrentPlan: PropTypes.bool.isRequired, |
116 | stores: PropTypes.shape({ | 115 | stores: PropTypes.shape({ |
117 | settings: PropTypes.instanceOf(SettingsStore).isRequired, | 116 | settings: PropTypes.instanceOf(SettingsStore).isRequired, |
@@ -139,11 +138,6 @@ class TodosWebview extends Component { | |||
139 | this.node.addEventListener('mousemove', this.resizePanel.bind(this)); | 138 | this.node.addEventListener('mousemove', this.resizePanel.bind(this)); |
140 | this.node.addEventListener('mouseup', this.stopResize.bind(this)); | 139 | this.node.addEventListener('mouseup', this.stopResize.bind(this)); |
141 | this.node.addEventListener('mouseleave', this.stopResize.bind(this)); | 140 | this.node.addEventListener('mouseleave', this.stopResize.bind(this)); |
142 | |||
143 | const webViewInstance = this; | ||
144 | this.webview.addEventListener('dom-ready', () => { | ||
145 | webViewInstance.webview.setUserAgent(userAgent(true)); | ||
146 | }); | ||
147 | } | 141 | } |
148 | 142 | ||
149 | startResize = (event) => { | 143 | startResize = (event) => { |
@@ -214,6 +208,7 @@ class TodosWebview extends Component { | |||
214 | classes, | 208 | classes, |
215 | isTodosServiceActive, | 209 | isTodosServiceActive, |
216 | isVisible, | 210 | isVisible, |
211 | userAgent, | ||
217 | isTodosIncludedInCurrentPlan, | 212 | isTodosIncludedInCurrentPlan, |
218 | stores, | 213 | stores, |
219 | } = this.props; | 214 | } = this.props; |
@@ -275,6 +270,7 @@ class TodosWebview extends Component { | |||
275 | partition={TODOS_PARTITION_ID} | 270 | partition={TODOS_PARTITION_ID} |
276 | preload="./features/todos/preload.js" | 271 | preload="./features/todos/preload.js" |
277 | ref={(webview) => { this.webview = webview ? webview.view : null; }} | 272 | ref={(webview) => { this.webview = webview ? webview.view : null; }} |
273 | useragent={userAgent} | ||
278 | src={todoUrl} | 274 | src={todoUrl} |
279 | /> | 275 | /> |
280 | ) | 276 | ) |
diff --git a/src/features/todos/containers/TodosScreen.js b/src/features/todos/containers/TodosScreen.js index 884925be6..631893f93 100644 --- a/src/features/todos/containers/TodosScreen.js +++ b/src/features/todos/containers/TodosScreen.js | |||
@@ -27,6 +27,7 @@ class TodosScreen extends Component { | |||
27 | width={todosStore.width} | 27 | width={todosStore.width} |
28 | minWidth={TODOS_MIN_WIDTH} | 28 | minWidth={TODOS_MIN_WIDTH} |
29 | resize={width => todoActions.resize({ width })} | 29 | resize={width => todoActions.resize({ width })} |
30 | userAgent={todosStore.userAgent} | ||
30 | isTodosIncludedInCurrentPlan | 31 | isTodosIncludedInCurrentPlan |
31 | /> | 32 | /> |
32 | </ErrorBoundary> | 33 | </ErrorBoundary> |
diff --git a/src/features/todos/store.js b/src/features/todos/store.js index c1d6a9049..af8519d9c 100644 --- a/src/features/todos/store.js +++ b/src/features/todos/store.js | |||
@@ -16,6 +16,8 @@ import { | |||
16 | import { IPC } from './constants'; | 16 | import { IPC } from './constants'; |
17 | import { state as delayAppState } from '../delayApp'; | 17 | import { state as delayAppState } from '../delayApp'; |
18 | 18 | ||
19 | import UserAgent from '../../models/UserAgent'; | ||
20 | |||
19 | const debug = require('debug')('Ferdi:feature:todos:store'); | 21 | const debug = require('debug')('Ferdi:feature:todos:store'); |
20 | 22 | ||
21 | export default class TodoStore extends FeatureStore { | 23 | export default class TodoStore extends FeatureStore { |
@@ -25,6 +27,8 @@ export default class TodoStore extends FeatureStore { | |||
25 | 27 | ||
26 | @observable webview = null; | 28 | @observable webview = null; |
27 | 29 | ||
30 | @observable userAgentModel = new UserAgent(); | ||
31 | |||
28 | isInitialized = false; | 32 | isInitialized = false; |
29 | 33 | ||
30 | @computed get width() { | 34 | @computed get width() { |
@@ -51,6 +55,10 @@ export default class TodoStore extends FeatureStore { | |||
51 | return localStorage.getItem('todos') || {}; | 55 | return localStorage.getItem('todos') || {}; |
52 | } | 56 | } |
53 | 57 | ||
58 | @computed get userAgent() { | ||
59 | return this.userAgentModel.userAgent; | ||
60 | } | ||
61 | |||
54 | // ========== PUBLIC API ========= // | 62 | // ========== PUBLIC API ========= // |
55 | 63 | ||
56 | @action start(stores, actions) { | 64 | @action start(stores, actions) { |
@@ -123,7 +131,10 @@ export default class TodoStore extends FeatureStore { | |||
123 | 131 | ||
124 | @action _setTodosWebview = ({ webview }) => { | 132 | @action _setTodosWebview = ({ webview }) => { |
125 | debug('_setTodosWebview', webview); | 133 | debug('_setTodosWebview', webview); |
126 | this.webview = webview; | 134 | if (this.webview !== webview) { |
135 | this.webview = webview; | ||
136 | this.userAgentModel.setWebviewReference(webview); | ||
137 | } | ||
127 | }; | 138 | }; |
128 | 139 | ||
129 | @action _handleHostMessage = (message) => { | 140 | @action _handleHostMessage = (message) => { |