Extract getAppVersion() util

Summary:
Just some simple memoisation so we limit this particular `remote`
call to one per session.

Reviewed By: mweststrate

Differential Revision: D26223274

fbshipit-source-id: 7a12764758823c52f68fb7075f46caf58affb22f
This commit is contained in:
Pascal Hartig
2021-02-03 07:59:37 -08:00
committed by Facebook GitHub Bot
parent 40abef860f
commit 642d89213d
4 changed files with 19 additions and 9 deletions

View File

@@ -8,6 +8,7 @@
*/
import os from 'os';
import {remote} from 'electron';
export type Info = {
arch: string;
@@ -35,6 +36,17 @@ export function getInfo(): Info {
};
}
let APP_VERSION: string | undefined = undefined;
// Prefer using this function over manually calling `remote.app.getVersion()`
// as calls to the remote object go over IPC and can be slow.
export function getAppVersion(): string | undefined {
if (APP_VERSION === undefined && remote) {
APP_VERSION = remote.app.getVersion();
}
return APP_VERSION;
}
export function stringifyInfo(info: Info): string {
const lines = [
`Platform: ${info.platform} ${info.arch}`,