Fix UA string

This commit is contained in:
Fedor Indutny 2022-06-20 17:31:32 -07:00 committed by GitHub
parent 35e5eb847a
commit 8b87fe23e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 10 deletions

View file

@ -1,6 +1,8 @@
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import os from 'os';
import { getOwn } from './getOwn';
const PLATFORM_STRINGS: { [platform: string]: string } = {
@ -9,12 +11,19 @@ const PLATFORM_STRINGS: { [platform: string]: string } = {
linux: 'Linux',
};
export function getUserAgent(appVersion: string): string {
export function getUserAgent(
appVersion: string,
release = os.release()
): string {
// `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);
const platformStringWithSpace = platformString ? ` ${platformString}` : '';
return `Signal-Desktop/${appVersion}${platformStringWithSpace}`;
let result = `Signal-Desktop/${appVersion}`;
if (platformString) {
result += ` ${platformString} ${release}`;
}
return result;
}