File tree Expand file tree Collapse file tree 4 files changed +17
-24
lines changed
Expand file tree Collapse file tree 4 files changed +17
-24
lines changed Original file line number Diff line number Diff line change @@ -158,6 +158,9 @@ app.on('activate', () => {
158158} ) ;
159159
160160app . on ( 'ready' , ( ) => {
161+ const ses = session . fromPartition ( 'persist:webviewsession' ) ;
162+ ses . setUserAgent ( `ZulipElectron/${ app . getVersion ( ) } ${ ses . getUserAgent ( ) } ` ) ;
163+
161164 AppMenu . setMenu ( {
162165 tabs : [ ]
163166 } ) ;
@@ -190,10 +193,10 @@ app.on('ready', () => {
190193 } else {
191194 mainWindow . show ( ) ;
192195 }
193- if ( ! ConfigUtil . isConfigItemExists ( 'userAgent' ) ) {
194- const userAgent = session . fromPartition ( 'webview:persistsession' ) . getUserAgent ( ) ;
195- ConfigUtil . setConfigItem ( 'userAgent ', userAgent ) ;
196- }
196+ } ) ;
197+
198+ ipcMain . on ( 'fetch-user-agent ', event => {
199+ event . returnValue = session . fromPartition ( 'persist:webviewsession' ) . getUserAgent ( ) ;
197200 } ) ;
198201
199202 page . once ( 'did-frame-finish-load' , ( ) => {
Original file line number Diff line number Diff line change @@ -149,12 +149,6 @@ export default class WebView extends BaseComponent {
149149 if ( ! isSettingPage ) {
150150 this . props . switchLoading ( true , this . props . url ) ;
151151 }
152- let userAgent = SystemUtil . getUserAgent ( ) ;
153- if ( ! userAgent ) {
154- SystemUtil . setUserAgent ( this . $el . getUserAgent ( ) ) ;
155- userAgent = SystemUtil . getUserAgent ( ) ;
156- }
157- this . $el . setUserAgent ( userAgent ) ;
158152 } ) ;
159153
160154 this . $el . addEventListener ( 'did-stop-loading' , ( ) => {
Original file line number Diff line number Diff line change @@ -140,6 +140,7 @@ class ServerManagerView {
140140 await this . loadProxy ( ) ;
141141 this . initDefaultSettings ( ) ;
142142 this . initSidebar ( ) ;
143+ this . removeUAfromDisk ( ) ;
143144 if ( EnterpriseUtil . configFile ) {
144145 this . initPresetOrgs ( ) ;
145146 }
@@ -239,6 +240,12 @@ class ServerManagerView {
239240 this . toggleSidebar ( showSidebar ) ;
240241 }
241242
243+ // Remove the stale UA string from the disk if the app is not freshly
244+ // installed. This should be removed in a further release.
245+ removeUAfromDisk ( ) : void {
246+ ConfigUtil . removeConfigItem ( 'userAgent' ) ;
247+ }
248+
242249 async queueDomain ( domain : any ) : Promise < boolean > {
243250 // allows us to start adding multiple domains to the app simultaneously
244251 // promise of addition resolves in both cases, but we consider it rejected
Original file line number Diff line number Diff line change 1- import { remote } from 'electron' ;
1+ import { ipcRenderer } from 'electron' ;
22
33import os from 'os' ;
4- import * as ConfigUtil from './config-util' ;
5-
6- const { app } = remote ;
74
85export const connectivityERR : string [ ] = [
96 'ERR_INTERNET_DISCONNECTED' ,
@@ -14,7 +11,7 @@ export const connectivityERR: string[] = [
1411 'ERR_NETWORK_CHANGED'
1512] ;
1613
17- let userAgent : string | null = null ;
14+ const userAgent = ipcRenderer . sendSync ( 'fetch-user-agent' ) ;
1815
1916export function getOS ( ) : string {
2017 const platform = os . platform ( ) ;
@@ -32,14 +29,6 @@ export function getOS(): string {
3229 return '' ;
3330 }
3431}
35-
36- export function setUserAgent ( webViewUserAgent : string ) : void {
37- userAgent = `ZulipElectron/${ app . getVersion ( ) } ${ webViewUserAgent } ` ;
38- }
39-
40- export function getUserAgent ( ) : string | null {
41- if ( ! userAgent ) {
42- setUserAgent ( ConfigUtil . getConfigItem ( 'userAgent' , null ) ) ;
43- }
32+ export function getUserAgent ( ) : string {
4433 return userAgent ;
4534}
You can’t perform that action at this time.
0 commit comments