From 48cd099d1eb956f8bd483b8844442cc1485022bf Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Tue, 12 Jan 2021 03:49:09 +0100 Subject: [PATCH] Using the backend API for getting the client version --- shared/js/backend/NativeClient.ts | 10 ++++++++++ shared/js/connection/HandshakeHandler.ts | 18 +++++------------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/shared/js/backend/NativeClient.ts b/shared/js/backend/NativeClient.ts index d85fc133..b4cfd2e8 100644 --- a/shared/js/backend/NativeClient.ts +++ b/shared/js/backend/NativeClient.ts @@ -1,3 +1,11 @@ +export type NativeClientVersionInfo = { + version: string, + + os_architecture: string, + os_platform: string, + os_platform_version: string +} + export interface NativeClientBackend { openChangeLog() : void; openClientUpdater() : void; @@ -6,4 +14,6 @@ export interface NativeClientBackend { showDeveloperOptions() : boolean; openDeveloperTools() : void; reloadWindow() : void; + + getVersionInfo() : NativeClientVersionInfo; } \ No newline at end of file diff --git a/shared/js/connection/HandshakeHandler.ts b/shared/js/connection/HandshakeHandler.ts index d104133a..42b55be8 100644 --- a/shared/js/connection/HandshakeHandler.ts +++ b/shared/js/connection/HandshakeHandler.ts @@ -5,6 +5,7 @@ import {DisconnectReason} from "../ConnectionHandler"; import {tr} from "../i18n/localize"; import {ConnectParameters} from "tc-shared/ui/modal/connect/Controller"; import {LogCategory, logWarn} from "tc-shared/log"; +import {getBackend} from "tc-shared/backend"; export interface HandshakeIdentityHandler { connection: AbstractServerConnection; @@ -95,30 +96,21 @@ export class HandshakeHandler { }; if(__build.target === "client") { - const _native = window["native"]; - let version; - try { - version = await _native.client_version(); - } catch (error) { - logWarn(LogCategory.GENERAL, tr("Failed to fetch native client version: %o"), error); - version = "?.?.?"; - } + const versionsInfo = getBackend("native").getVersionInfo(); + data.client_version = "TeaClient " + versionsInfo.version; - data.client_version = "TeaClient " + version; - - const os = __non_webpack_require__("os"); const arch_mapping = { "x32": "32bit", "x64": "64bit" }; - data.client_version += " " + (arch_mapping[os.arch()] || os.arch()); + data.client_version += " " + (arch_mapping[versionsInfo.os_architecture] || versionsInfo.os_architecture); const os_mapping = { "win32": "Windows", "linux": "Linux" }; - data.client_platform = (os_mapping[os.platform()] || os.platform()); + data.client_platform = (os_mapping[versionsInfo.os_platform] || versionsInfo.os_platform); } this.handshakeImpl.fillClientInitData(data);