From c3711a2b577a10584bac0fbddfb7bde108eb706c Mon Sep 17 00:00:00 2001 From: Vijay A Date: Thu, 15 Jul 2021 23:10:08 +0530 Subject: Minor perf tweaks to evaluate capturing of env-specific values only once in the application. --- src/api/server/ServerApi.js | 5 ++--- src/environment.js | 5 +++++ src/helpers/userAgent-helpers.js | 16 +++++++--------- src/i18n/locales/defaultMessages.json | 28 ++++++++++++++-------------- src/lib/TouchBar.js | 5 ++--- src/stores/AppStore.js | 5 ++--- 6 files changed, 32 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js index 24d095556..c63aa7dda 100644 --- a/src/api/server/ServerApi.js +++ b/src/api/server/ServerApi.js @@ -1,4 +1,3 @@ -import os from 'os'; import path from 'path'; import tar from 'tar'; import fs from 'fs-extra'; @@ -15,7 +14,7 @@ import OrderModel from '../../models/Order'; import { sleep } from '../../helpers/async-helpers'; import { SERVER_NOT_LOADED } from '../../config'; -import { RECIPES_PATH } from '../../environment'; +import { osArch, osPlatform, RECIPES_PATH } from '../../environment'; import apiBase from '../apiBase'; import { prepareAuthRequest, sendAuthRequest } from '../utils/auth'; @@ -456,7 +455,7 @@ export default class ServerApi { // News async getLatestNews() { - const url = `${apiBase(true)}/news?platform=${os.platform()}&arch=${os.arch()}&version=${app.getVersion()}`; + const url = `${apiBase(true)}/news?platform=${osPlatform}&arch=${osArch}&version=${app.getVersion()}`; const request = await sendAuthRequest(url); if (!request.ok) throw request; const data = await request.json(); diff --git a/src/environment.js b/src/environment.js index be6dc7176..758a33380 100644 --- a/src/environment.js +++ b/src/environment.js @@ -1,3 +1,4 @@ +import os from 'os'; import path from 'path'; import { is, api as electronApi } from 'electron-util'; @@ -60,6 +61,10 @@ export const useLiveAPI = process.env.LIVE_API; export const isMac = is.macos; export const isWindows = is.windows; export const isLinux = is.linux; +export const osPlatform = os.platform(); +export const osArch = os.arch(); +export const osRelease = os.release(); +export const is64Bit = osArch.match(/64/); export const ctrlKey = isMac ? '⌘' : 'Ctrl'; export const cmdKey = isMac ? 'Cmd' : 'Ctrl'; diff --git a/src/helpers/userAgent-helpers.js b/src/helpers/userAgent-helpers.js index 4aa6f92d0..9c9c8f132 100644 --- a/src/helpers/userAgent-helpers.js +++ b/src/helpers/userAgent-helpers.js @@ -1,13 +1,11 @@ import os from 'os'; import macosVersion from 'macos-version'; -import { chromeVersion, isMac, isWindows } from '../environment'; +import { + chromeVersion, isMac, isWindows, is64Bit, osArch, osRelease, +} from '../environment'; const uaGenerator = require('useragent-generator'); -function is64Bit() { - return os.arch().match(/64/); -} - function macOS() { const version = macosVersion(); let cpuName = os.cpus()[0].model.split(' ')[0]; @@ -18,14 +16,14 @@ function macOS() { } function windows() { - const version = os.release(); + const version = osRelease; const [majorVersion, minorVersion] = version.split('.'); - const archString = is64Bit() ? 'Win64' : 'Win32'; - return `Windows NT ${majorVersion}.${minorVersion}; ${archString}; ${os.arch()}`; + const archString = is64Bit ? 'Win64' : 'Win32'; + return `Windows NT ${majorVersion}.${minorVersion}; ${archString}; ${osArch}`; } function linux() { - const archString = is64Bit() ? 'x86_64' : os.arch(); + const archString = is64Bit ? 'x86_64' : osArch; return `X11; Ubuntu; Linux ${archString}`; } diff --git a/src/i18n/locales/defaultMessages.json b/src/i18n/locales/defaultMessages.json index 4da9390a5..370a6fb92 100644 --- a/src/i18n/locales/defaultMessages.json +++ b/src/i18n/locales/defaultMessages.json @@ -6142,91 +6142,91 @@ "defaultMessage": "!!!Publish debug information", "end": { "column": 3, - "line": 20 + "line": 22 }, "file": "src/features/publishDebugInfo/Component.js", "id": "feature.publishDebugInfo.title", "start": { "column": 9, - "line": 17 + "line": 19 } }, { "defaultMessage": "!!!Publishing your debug information helps us find issues and errors in Ferdi. By publishing your debug information you accept Ferdi Debugger's privacy policy and terms of service", "end": { "column": 3, - "line": 24 + "line": 26 }, "file": "src/features/publishDebugInfo/Component.js", "id": "feature.publishDebugInfo.info", "start": { "column": 8, - "line": 21 + "line": 23 } }, { "defaultMessage": "!!!There was an error while trying to publish the debug information. Please try again later or view the console for more information.", "end": { "column": 3, - "line": 28 + "line": 30 }, "file": "src/features/publishDebugInfo/Component.js", "id": "feature.publishDebugInfo.error", "start": { "column": 9, - "line": 25 + "line": 27 } }, { "defaultMessage": "!!!Privacy policy", "end": { "column": 3, - "line": 32 + "line": 34 }, "file": "src/features/publishDebugInfo/Component.js", "id": "feature.publishDebugInfo.privacy", "start": { "column": 11, - "line": 29 + "line": 31 } }, { "defaultMessage": "!!!Terms of service", "end": { "column": 3, - "line": 36 + "line": 38 }, "file": "src/features/publishDebugInfo/Component.js", "id": "feature.publishDebugInfo.terms", "start": { "column": 9, - "line": 33 + "line": 35 } }, { "defaultMessage": "!!!Accept and publish", "end": { "column": 3, - "line": 40 + "line": 42 }, "file": "src/features/publishDebugInfo/Component.js", "id": "feature.publishDebugInfo.publish", "start": { "column": 11, - "line": 37 + "line": 39 } }, { "defaultMessage": "!!!Your debug log was published and is now availible at", "end": { "column": 3, - "line": 44 + "line": 46 }, "file": "src/features/publishDebugInfo/Component.js", "id": "feature.publishDebugInfo.published", "start": { "column": 13, - "line": 41 + "line": 43 } } ], diff --git a/src/lib/TouchBar.js b/src/lib/TouchBar.js index 11eaec306..781cd0895 100644 --- a/src/lib/TouchBar.js +++ b/src/lib/TouchBar.js @@ -1,9 +1,8 @@ -import os from 'os'; import semver from 'semver'; import { TouchBar, getCurrentWindow } from '@electron/remote'; import { autorun } from 'mobx'; -import { isMac } from '../environment'; +import { isMac, osRelease } from '../environment'; export default class FranzTouchBar { constructor(stores, actions) { @@ -13,7 +12,7 @@ export default class FranzTouchBar { // Temporary fix for https://github.com/electron/electron/issues/10442 // TODO: remove when we upgrade to electron 1.8.2 or later try { - if (isMac && semver.gt(os.release(), '16.6.0')) { + if (isMac && semver.gt(osRelease, '16.6.0')) { this.build = autorun(this._build.bind(this)); } } catch (err) { diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index bbcf78a43..ac6ca6d2d 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js @@ -7,7 +7,6 @@ import moment from 'moment'; import AutoLaunch from 'auto-launch'; import ms from 'ms'; import { URL } from 'url'; -import os from 'os'; import path from 'path'; import { readJsonSync } from 'fs-extra'; @@ -15,7 +14,7 @@ import Store from './lib/Store'; import Request from './lib/Request'; import { CHECK_INTERVAL } from '../config'; import { - DEFAULT_APP_SETTINGS, isMac, ferdiVersion, electronVersion, + DEFAULT_APP_SETTINGS, isMac, ferdiVersion, electronVersion, osRelease, } from '../environment'; import locales from '../i18n/translations'; import { onVisibilityChange } from '../helpers/visibility-helper'; @@ -261,7 +260,7 @@ export default class AppStore extends Store { return { host: { platform: process.platform, - release: os.release(), + release: osRelease, screens: screen.getAllDisplays(), }, ferdi: { -- cgit v1.2.3-70-g09d2