signal-desktop/ts/util/getUserAgent.ts

30 lines
753 B
TypeScript
Raw Normal View History

2020-10-30 20:34:04 +00:00
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2022-06-21 00:31:32 +00:00
import os from 'os';
2020-11-12 23:29:54 +00:00
import { getOwn } from './getOwn';
const PLATFORM_STRINGS: { [platform: string]: string } = {
win32: 'Windows',
darwin: 'macOS',
linux: 'Linux',
};
2022-06-21 00:31:32 +00:00
export function getUserAgent(
appVersion: string,
release = os.release()
): string {
2020-11-12 23:29:54 +00:00
// `process.platform` could be missing if someone figures out how to compile Signal on
// an unsupported OS and forgets to update this file. We'd rather send nothing than
// crash.
const platformString = getOwn(PLATFORM_STRINGS, process.platform);
2022-06-21 00:31:32 +00:00
let result = `Signal-Desktop/${appVersion}`;
if (platformString) {
result += ` ${platformString} ${release}`;
}
return result;
}