Skip to content
Permalink
Browse files
fix(Experimental): Fix Google signin
  • Loading branch information
adlk committed Mar 30, 2020
1 parent d7be68b commit d7840ba75146e709deb8a37b1d8f362d89c4b3dd
Showing 3 changed files with 34 additions and 7 deletions.
@@ -19,7 +19,7 @@ function linux() {
return 'X11; Ubuntu; Linux x86_64';
}

export default function userAgent() {
export default function userAgent(removeChromeVersion = false) {
let platformString = '';

if (isMac) {
@@ -31,5 +31,6 @@ export default function userAgent() {
}

// TODO: Update AppleWebKit and Safari version after electron update
return `Mozilla/5.0 (${platformString}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${process.versions.chrome} Safari/537.36`;
return `Mozilla/5.0 (${platformString}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome${!removeChromeVersion ? `/${process.versions.chrome}` : ''} Safari/537.36`;
// Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) old-airport-include/1.0.0 Chrome Electron/7.1.7 Safari/537.36
}
@@ -44,7 +44,7 @@ import {
} from './config';
import { asarPath } from './helpers/asar-helpers';
import { isValidExternalURL } from './helpers/url-helpers';
import userAgent from './electron/userAgent';
import userAgent from './helpers/userAgent-helpers';

/* eslint-enable import/first */
const debug = require('debug')('Franz:App');
@@ -1,6 +1,7 @@
import { computed, observable, autorun } from 'mobx';
import path from 'path';
import normalizeUrl from 'normalize-url';
import userAgent from '../helpers/userAgent-helpers';

const debug = require('debug')('Franz:Service');

@@ -76,6 +77,8 @@ export default class Service {
@observable lastUsed = Date.now(); // timestamp
@observable chromelessUserAgent = false;
constructor(data, recipe) {
if (!data) {
console.error('Service config not valid');
@@ -188,17 +191,34 @@ export default class Service {
}
@computed get userAgent() {
let userAgent = window.navigator.userAgent;
let ua = window.navigator.userAgent;
if (typeof this.recipe.overrideUserAgent === 'function') {
userAgent = this.recipe.overrideUserAgent();
ua = this.recipe.overrideUserAgent();
}
return userAgent;
return ua;
}
initializeWebViewEvents({ handleIPCMessage, openWindow, stores }) {
const webContents = this.webview.getWebContents();
const handleUserAgent = (url, forwardingHack = false) => {
if (url.startsWith('https://accounts.google.com')) {
if (!this.chromelessUserAgent) {
debug('Setting user agent to chromeless for url', url);
this.webview.setUserAgent(userAgent(true));
if (forwardingHack) {
this.webview.loadURL(url);
}
this.chromelessUserAgent = true;
}
} else if (this.chromelessUserAgent) {
debug('Setting user agent to contain chrome');
this.webview.setUserAgent(this.userAgent);
this.chromelessUserAgent = false;
}
};

this.webview.addEventListener('ipc-message', e => handleIPCMessage({
serviceId: this.id,
channel: e.channel,
@@ -215,6 +235,9 @@ export default class Service {
});
});


this.webview.addEventListener('will-navigate', event => handleUserAgent(event.url, true));

this.webview.addEventListener('did-start-loading', (event) => {
debug('Did start load', this.name, event);

@@ -232,7 +255,10 @@ export default class Service {
};

this.webview.addEventListener('did-frame-finish-load', didLoad.bind(this));
this.webview.addEventListener('did-navigate', didLoad.bind(this));
this.webview.addEventListener('did-navigate', (event) => {
handleUserAgent(event.url);
didLoad();
});

this.webview.addEventListener('did-fail-load', (event) => {
debug('Service failed to load', this.name, event);

0 comments on commit d7840ba

Please sign in to comment.