mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-10-24 16:43:38 +00:00
* Sets user-agent config item when the app's DOM is ready. * App sends the right User-Agent to the server-settings API. Fixes #817.
65 lines
1.2 KiB
TypeScript
65 lines
1.2 KiB
TypeScript
'use strict';
|
|
import { remote } from 'electron';
|
|
|
|
import os = require('os');
|
|
import ConfigUtil = require('./config-util');
|
|
|
|
const { app } = remote;
|
|
let instance: null | SystemUtil = null;
|
|
|
|
class SystemUtil {
|
|
connectivityERR: string[];
|
|
|
|
userAgent: string | null;
|
|
|
|
constructor() {
|
|
if (instance) {
|
|
return instance;
|
|
} else {
|
|
instance = this;
|
|
}
|
|
|
|
this.connectivityERR = [
|
|
'ERR_INTERNET_DISCONNECTED',
|
|
'ERR_PROXY_CONNECTION_FAILED',
|
|
'ERR_CONNECTION_RESET',
|
|
'ERR_NOT_CONNECTED',
|
|
'ERR_NAME_NOT_RESOLVED',
|
|
'ERR_NETWORK_CHANGED'
|
|
];
|
|
this.userAgent = null;
|
|
|
|
return instance;
|
|
}
|
|
|
|
getOS(): string {
|
|
const platform = os.platform();
|
|
if (platform === 'darwin') {
|
|
return 'Mac';
|
|
} else if (platform === 'linux') {
|
|
return 'Linux';
|
|
} else if (platform === 'win32') {
|
|
if (parseFloat(os.release()) < 6.2) {
|
|
return 'Windows 7';
|
|
} else {
|
|
return 'Windows 10';
|
|
}
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
setUserAgent(webViewUserAgent: string): void {
|
|
this.userAgent = `ZulipElectron/${app.getVersion()} ${webViewUserAgent}`;
|
|
}
|
|
|
|
getUserAgent(): string | null {
|
|
if (!this.userAgent) {
|
|
this.setUserAgent(ConfigUtil.getConfigItem('userAgent', null));
|
|
}
|
|
return this.userAgent;
|
|
}
|
|
}
|
|
|
|
export = new SystemUtil();
|