Skip to content

Commit

Permalink
fix(Experimental): Fix Google signin
Browse files Browse the repository at this point in the history
  • Loading branch information
adlk committed Mar 30, 2020
1 parent d7be68b commit d7840ba
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
34 changes: 30 additions & 4 deletions src/models/Service.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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,
Expand All @@ -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);

Expand All @@ -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);
Expand Down

0 comments on commit d7840ba

Please sign in to comment.