Skip to content

Commit

Permalink
Remove storing of User-Agent on disk.
Browse files Browse the repository at this point in the history
Fixes: #921.

Co-authored-by: Anders Kaseorg <[email protected]>
  • Loading branch information
manavmehta and andersk committed Apr 26, 2020
1 parent bb6d906 commit 16f0af8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
11 changes: 7 additions & 4 deletions app/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ app.on('activate', () => {
});

app.on('ready', () => {
const ses = session.fromPartition('persist:webviewsession');
ses.setUserAgent(`ZulipElectron/${app.getVersion()} ${ses.getUserAgent()}`);

AppMenu.setMenu({
tabs: []
});
Expand Down Expand Up @@ -190,10 +193,10 @@ app.on('ready', () => {
} else {
mainWindow.show();
}
if (!ConfigUtil.isConfigItemExists('userAgent')) {
const userAgent = session.fromPartition('webview:persistsession').getUserAgent();
ConfigUtil.setConfigItem('userAgent', userAgent);
}
});

ipcMain.on('fetch-user-agent', event => {
event.returnValue = session.fromPartition('persist:webviewsession').getUserAgent();
});

page.once('did-frame-finish-load', () => {
Expand Down
6 changes: 0 additions & 6 deletions app/renderer/js/components/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,6 @@ export default class WebView extends BaseComponent {
if (!isSettingPage) {
this.props.switchLoading(true, this.props.url);
}
let userAgent = SystemUtil.getUserAgent();
if (!userAgent) {
SystemUtil.setUserAgent(this.$el.getUserAgent());
userAgent = SystemUtil.getUserAgent();
}
this.$el.setUserAgent(userAgent);
});

this.$el.addEventListener('did-stop-loading', () => {
Expand Down
7 changes: 7 additions & 0 deletions app/renderer/js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class ServerManagerView {
await this.loadProxy();
this.initDefaultSettings();
this.initSidebar();
this.removeUAfromDisk();
if (EnterpriseUtil.configFile) {
this.initPresetOrgs();
}
Expand Down Expand Up @@ -239,6 +240,12 @@ class ServerManagerView {
this.toggleSidebar(showSidebar);
}

// Remove the stale UA string from the disk if the app is not freshly
// installed. This should be removed in a further release.
removeUAfromDisk(): void {
ConfigUtil.removeConfigItem('userAgent');
}

async queueDomain(domain: any): Promise<boolean> {
// allows us to start adding multiple domains to the app simultaneously
// promise of addition resolves in both cases, but we consider it rejected
Expand Down
17 changes: 3 additions & 14 deletions app/renderer/js/utils/system-util.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { remote } from 'electron';
import { ipcRenderer } from 'electron';

import os from 'os';
import * as ConfigUtil from './config-util';

const { app } = remote;

export const connectivityERR: string[] = [
'ERR_INTERNET_DISCONNECTED',
Expand All @@ -14,7 +11,7 @@ export const connectivityERR: string[] = [
'ERR_NETWORK_CHANGED'
];

let userAgent: string | null = null;
const userAgent = ipcRenderer.sendSync('fetch-user-agent');

export function getOS(): string {
const platform = os.platform();
Expand All @@ -32,14 +29,6 @@ export function getOS(): string {
return '';
}
}

export function setUserAgent(webViewUserAgent: string): void {
userAgent = `ZulipElectron/${app.getVersion()} ${webViewUserAgent}`;
}

export function getUserAgent(): string | null {
if (!userAgent) {
setUserAgent(ConfigUtil.getConfigItem('userAgent', null));
}
export function getUserAgent(): string {
return userAgent;
}

0 comments on commit 16f0af8

Please sign in to comment.