diff options
Diffstat (limited to 'src/models/Service.js')
-rw-r--r-- | src/models/Service.js | 39 |
1 files changed, 8 insertions, 31 deletions
diff --git a/src/models/Service.js b/src/models/Service.js index b01881beb..0d1dff431 100644 --- a/src/models/Service.js +++ b/src/models/Service.js | |||
@@ -4,9 +4,9 @@ import { webContents } from '@electron/remote'; | |||
4 | import normalizeUrl from 'normalize-url'; | 4 | import normalizeUrl from 'normalize-url'; |
5 | import path from 'path'; | 5 | import path from 'path'; |
6 | 6 | ||
7 | import userAgent from '../helpers/userAgent-helpers'; | ||
8 | import { TODOS_RECIPE_ID, todosStore } from '../features/todos'; | 7 | import { TODOS_RECIPE_ID, todosStore } from '../features/todos'; |
9 | import { isValidExternalURL } from '../helpers/url-helpers'; | 8 | import { isValidExternalURL } from '../helpers/url-helpers'; |
9 | import UserAgent from './UserAgent'; | ||
10 | 10 | ||
11 | const debug = require('debug')('Ferdi:Service'); | 11 | const debug = require('debug')('Ferdi:Service'); |
12 | 12 | ||
@@ -94,7 +94,7 @@ export default class Service { | |||
94 | 94 | ||
95 | @observable lostRecipeReloadAttempt = 0; | 95 | @observable lostRecipeReloadAttempt = 0; |
96 | 96 | ||
97 | @observable chromelessUserAgent = false; | 97 | @observable userAgentModel = null; |
98 | 98 | ||
99 | constructor(data, recipe) { | 99 | constructor(data, recipe) { |
100 | if (!data) { | 100 | if (!data) { |
@@ -156,6 +156,8 @@ export default class Service { | |||
156 | this.isHibernating = true; | 156 | this.isHibernating = true; |
157 | } | 157 | } |
158 | 158 | ||
159 | this.userAgentModel = new UserAgent(recipe.overrideUserAgent); | ||
160 | |||
159 | autorun(() => { | 161 | autorun(() => { |
160 | if (!this.isEnabled) { | 162 | if (!this.isEnabled) { |
161 | this.webview = null; | 163 | this.webview = null; |
@@ -234,12 +236,7 @@ export default class Service { | |||
234 | } | 236 | } |
235 | 237 | ||
236 | @computed get userAgent() { | 238 | @computed get userAgent() { |
237 | let ua = userAgent(this.chromelessUserAgent); | 239 | return this.userAgentModel.userAgent; |
238 | if (typeof this.recipe.overrideUserAgent === 'function') { | ||
239 | ua = this.recipe.overrideUserAgent(); | ||
240 | } | ||
241 | |||
242 | return ua; | ||
243 | } | 240 | } |
244 | 241 | ||
245 | @computed get partition() { | 242 | @computed get partition() { |
@@ -250,6 +247,8 @@ export default class Service { | |||
250 | initializeWebViewEvents({ handleIPCMessage, openWindow, stores }) { | 247 | initializeWebViewEvents({ handleIPCMessage, openWindow, stores }) { |
251 | const webviewWebContents = webContents.fromId(this.webview.getWebContentsId()); | 248 | const webviewWebContents = webContents.fromId(this.webview.getWebContentsId()); |
252 | 249 | ||
250 | this.userAgentModel.setWebviewReference(this.webview); | ||
251 | |||
253 | // If the recipe has implemented modifyRequestHeaders, | 252 | // If the recipe has implemented modifyRequestHeaders, |
254 | // Send those headers to ipcMain so that it can be set in session | 253 | // Send those headers to ipcMain so that it can be set in session |
255 | if (typeof this.recipe.modifyRequestHeaders === 'function') { | 254 | if (typeof this.recipe.modifyRequestHeaders === 'function') { |
@@ -263,23 +262,6 @@ export default class Service { | |||
263 | debug(this.name, 'modifyRequestHeaders is not defined in the recipe'); | 262 | debug(this.name, 'modifyRequestHeaders is not defined in the recipe'); |
264 | } | 263 | } |
265 | 264 | ||
266 | const handleUserAgent = (url, forwardingHack = false) => { | ||
267 | if (url.startsWith('https://accounts.google.com')) { | ||
268 | if (!this.chromelessUserAgent) { | ||
269 | debug('Setting user agent to chromeless for url', url); | ||
270 | this.webview.setUserAgent(userAgent(true)); | ||
271 | if (forwardingHack) { | ||
272 | this.webview.loadURL(url); | ||
273 | } | ||
274 | this.chromelessUserAgent = true; | ||
275 | } | ||
276 | } else if (this.chromelessUserAgent) { | ||
277 | debug('Setting user agent to contain chrome'); | ||
278 | this.webview.setUserAgent(this.userAgent); | ||
279 | this.chromelessUserAgent = false; | ||
280 | } | ||
281 | }; | ||
282 | |||
283 | this.webview.addEventListener('ipc-message', e => handleIPCMessage({ | 265 | this.webview.addEventListener('ipc-message', e => handleIPCMessage({ |
284 | serviceId: this.id, | 266 | serviceId: this.id, |
285 | channel: e.channel, | 267 | channel: e.channel, |
@@ -306,8 +288,6 @@ export default class Service { | |||
306 | } | 288 | } |
307 | }); | 289 | }); |
308 | 290 | ||
309 | this.webview.addEventListener('will-navigate', event => handleUserAgent(event.url, true)); | ||
310 | |||
311 | this.webview.addEventListener('did-start-loading', (event) => { | 291 | this.webview.addEventListener('did-start-loading', (event) => { |
312 | debug('Did start load', this.name, event); | 292 | debug('Did start load', this.name, event); |
313 | 293 | ||
@@ -325,10 +305,7 @@ export default class Service { | |||
325 | }; | 305 | }; |
326 | 306 | ||
327 | this.webview.addEventListener('did-frame-finish-load', didLoad.bind(this)); | 307 | this.webview.addEventListener('did-frame-finish-load', didLoad.bind(this)); |
328 | this.webview.addEventListener('did-navigate', (event) => { | 308 | this.webview.addEventListener('did-navigate', didLoad.bind(this)); |
329 | handleUserAgent(event.url); | ||
330 | didLoad(); | ||
331 | }); | ||
332 | 309 | ||
333 | this.webview.addEventListener('did-fail-load', (event) => { | 310 | this.webview.addEventListener('did-fail-load', (event) => { |
334 | debug('Service failed to load', this.name, event); | 311 | debug('Service failed to load', this.name, event); |