diff --git a/js/modules/web_api.js b/js/modules/web_api.js index d053742a35..5472ad2874 100644 --- a/js/modules/web_api.js +++ b/js/modules/web_api.js @@ -210,7 +210,7 @@ function _promiseAjax(providedUrl, options) { method: options.type, body: options.data || null, headers: { - 'User-Agent': 'Signal Desktop (+https://signal.org/download)', + 'User-Agent': `Signal Desktop ${options.version}`, 'X-Signal-Agent': 'OWD', ...options.headers, }, @@ -413,6 +413,7 @@ function initialize({ certificateAuthority, contentProxyUrl, proxyUrl, + version, }) { if (!is.string(url)) { throw new Error('WebAPI.initialize: Invalid server url'); @@ -426,6 +427,9 @@ function initialize({ if (!is.string(contentProxyUrl)) { throw new Error('WebAPI.initialize: Invalid contentProxyUrl'); } + if (!is.string(version)) { + throw new Error('WebAPI.initialize: Invalid version'); + } // Thanks to function-hoisting, we can put this return statement before all of the // below function definitions. @@ -489,6 +493,7 @@ function initialize({ type: param.httpType, user: username, validateResponse: param.validateResponse, + version, unauthenticated: param.unauthenticated, accessKey: param.accessKey, }).catch(e => { @@ -576,6 +581,7 @@ function initialize({ responseType: 'arraybuffer', timeout: 0, type: 'GET', + version, }); } @@ -855,6 +861,7 @@ function initialize({ responseType: 'arraybuffer', type: 'GET', redactUrl: redactStickerUrl, + version, }); } @@ -865,6 +872,7 @@ function initialize({ responseType: 'arraybuffer', type: 'GET', redactUrl: redactStickerUrl, + version, }); } @@ -942,6 +950,7 @@ function initialize({ timeout: 0, type: 'POST', processData: false, + version, }); // Upload stickers @@ -957,6 +966,7 @@ function initialize({ timeout: 0, type: 'POST', processData: false, + version, }) ); if (onProgress) { @@ -977,6 +987,7 @@ function initialize({ responseType: 'arraybuffer', timeout: 0, type: 'GET', + version, }); } @@ -999,6 +1010,7 @@ function initialize({ timeout: 0, type: 'POST', processData: false, + version, }); return attachmentIdString; @@ -1036,6 +1048,7 @@ function initialize({ redirect: 'follow', redactUrl: () => '[REDACTED_URL]', headers, + version, }); if (!returnArrayBuffer) { @@ -1071,9 +1084,10 @@ function initialize({ .replace('http://', 'ws://'); const login = encodeURIComponent(username); const pass = encodeURIComponent(password); + const clientVersion = encodeURIComponent(version); return _createSocket( - `${fixedScheme}/v1/websocket/?login=${login}&password=${pass}&agent=OWD`, + `${fixedScheme}/v1/websocket/?login=${login}&password=${pass}&agent=OWD&version=${clientVersion}`, { certificateAuthority, proxyUrl } ); } @@ -1083,9 +1097,10 @@ function initialize({ const fixedScheme = url .replace('https://', 'wss://') .replace('http://', 'ws://'); + const clientVersion = encodeURIComponent(version); return _createSocket( - `${fixedScheme}/v1/websocket/provisioning/?agent=OWD`, + `${fixedScheme}/v1/websocket/provisioning/?agent=OWD&version=${clientVersion}`, { certificateAuthority, proxyUrl } ); } diff --git a/preload.js b/preload.js index b449901cc3..15e1d6a951 100644 --- a/preload.js +++ b/preload.js @@ -246,6 +246,7 @@ window.WebAPI = initializeWebAPI({ certificateAuthority: config.certificateAuthority, contentProxyUrl: config.contentProxyUrl, proxyUrl: config.proxyUrl, + version: config.version, }); // Linux seems to periodically let the event loop stop, so this is a global workaround diff --git a/ts/updater/common.ts b/ts/updater/common.ts index 1b0e63311e..2e1a6760e0 100644 --- a/ts/updater/common.ts +++ b/ts/updater/common.ts @@ -273,7 +273,7 @@ function getGotOptions(): GotOptions { ca, headers: { 'Cache-Control': 'no-cache', - 'User-Agent': 'Signal Desktop (+https://signal.org/download)', + 'User-Agent': `Signal Desktop ${packageJson.version}`, }, useElectronNet: false, };