diff --git a/app/main.ts b/app/main.ts index 503b5d91ba4c..91cdd19aa865 100644 --- a/app/main.ts +++ b/app/main.ts @@ -1,6 +1,9 @@ // Copyright 2017-2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only +// This has to be the first import because it patches "os" module +import '../ts/util/patchWindows7Hostname'; + import { join, normalize } from 'path'; import { pathToFileURL } from 'url'; import * as os from 'os'; @@ -396,16 +399,6 @@ async function prepareUrl( ); } - let hostname: string; - - try { - // os.hostname() doesn't work on Windows 7 anymore - // See: https://github.com/electron/electron/issues/34404 - hostname = os.hostname(); - } catch { - hostname = 'Desktop'; - } - const urlParams: RendererConfigType = { name: packageJson.productName, locale: getLocale().name, @@ -421,7 +414,7 @@ async function prepareUrl( environment: enableCI ? Environment.Production : getEnvironment(), enableCI, nodeVersion: process.versions.node, - hostname, + hostname: os.hostname(), appInstance: process.env.NODE_APP_INSTANCE || undefined, proxyUrl: process.env.HTTPS_PROXY || process.env.https_proxy || undefined, contentProxyUrl: config.get('contentProxyUrl'), diff --git a/sticker-creator/preload.ts b/sticker-creator/preload.ts index 61f756a43190..515c370b8dd6 100644 --- a/sticker-creator/preload.ts +++ b/sticker-creator/preload.ts @@ -1,6 +1,9 @@ // Copyright 2019-2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only +// This has to be the first import because of monkey-patching +import '../ts/windows/shims'; + import './window/phase1-dependencies'; import './window/phase2-signal'; import './window/phase3-sticker-functions'; diff --git a/ts/util/patchWindows7Hostname.ts b/ts/util/patchWindows7Hostname.ts new file mode 100644 index 000000000000..fae77f3ca646 --- /dev/null +++ b/ts/util/patchWindows7Hostname.ts @@ -0,0 +1,13 @@ +// Copyright 2022 Signal Messenger, LLC +// SPDX-License-Identifier: AGPL-3.0-only + +import semver from 'semver'; + +// eslint-disable-next-line @typescript-eslint/no-var-requires +const os = require('os'); + +// os.hostname() doesn't work on Windows 7 anymore +// See: https://github.com/electron/electron/issues/34404 +if (process.platform === 'win32' && semver.satisfies(os.release(), '6.1.x')) { + os.hostname = () => 'Desktop'; +} diff --git a/ts/windows/about/preload.ts b/ts/windows/about/preload.ts index a8af3c330daf..8ca4793fc9f9 100644 --- a/ts/windows/about/preload.ts +++ b/ts/windows/about/preload.ts @@ -1,6 +1,9 @@ -// Copyright 2018-2021 Signal Messenger, LLC +// Copyright 2018-2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only +// This has to be the first import because of monkey-patching +import '../shims'; + import React from 'react'; import ReactDOM from 'react-dom'; import { contextBridge } from 'electron'; diff --git a/ts/windows/debuglog/preload.ts b/ts/windows/debuglog/preload.ts index 1877d1cf7794..ace528af075b 100644 --- a/ts/windows/debuglog/preload.ts +++ b/ts/windows/debuglog/preload.ts @@ -1,6 +1,9 @@ -// Copyright 2021 Signal Messenger, LLC +// Copyright 2021-2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only +// This has to be the first import because of monkey-patching +import '../shims'; + import React from 'react'; import ReactDOM from 'react-dom'; import { contextBridge, ipcRenderer } from 'electron'; diff --git a/ts/windows/loading/preload.ts b/ts/windows/loading/preload.ts index e41b60c5eda9..ec5da35cc1ce 100644 --- a/ts/windows/loading/preload.ts +++ b/ts/windows/loading/preload.ts @@ -1,6 +1,9 @@ -// Copyright 2020-2021 Signal Messenger, LLC +// Copyright 2020-2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only +// This has to be the first import because of monkey-patching +import '../shims'; + import { contextBridge } from 'electron'; import { SignalContext } from '../context'; diff --git a/ts/windows/main/preload.ts b/ts/windows/main/preload.ts index 54cd76cd98bf..9dc9424e1e99 100644 --- a/ts/windows/main/preload.ts +++ b/ts/windows/main/preload.ts @@ -1,6 +1,9 @@ // Copyright 2017-2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only +// This has to be the first import because of monkey-patching +import '../shims'; + /* eslint-disable global-require */ import * as log from '../../logging/log'; diff --git a/ts/windows/permissions/preload.ts b/ts/windows/permissions/preload.ts index 640ce321b883..3f98f09c48a9 100644 --- a/ts/windows/permissions/preload.ts +++ b/ts/windows/permissions/preload.ts @@ -1,6 +1,9 @@ -// Copyright 2021 Signal Messenger, LLC +// Copyright 2021-2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only +// This has to be the first import because of monkey-patching +import '../shims'; + import React from 'react'; import ReactDOM from 'react-dom'; import { contextBridge } from 'electron'; diff --git a/ts/windows/screenShare/preload.ts b/ts/windows/screenShare/preload.ts index 2b8e22d8a93b..a1a4ae03ca19 100644 --- a/ts/windows/screenShare/preload.ts +++ b/ts/windows/screenShare/preload.ts @@ -1,6 +1,9 @@ -// Copyright 2021 Signal Messenger, LLC +// Copyright 2021-2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only +// This has to be the first import because of monkey-patching +import '../shims'; + import React from 'react'; import ReactDOM from 'react-dom'; import { contextBridge, ipcRenderer } from 'electron'; diff --git a/ts/windows/settings/preload.ts b/ts/windows/settings/preload.ts index 0508e4839112..481eab41104f 100644 --- a/ts/windows/settings/preload.ts +++ b/ts/windows/settings/preload.ts @@ -1,6 +1,9 @@ -// Copyright 2021 Signal Messenger, LLC +// Copyright 2021-2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only +// This has to be the first import because of monkey-patching +import '../shims'; + import React from 'react'; import ReactDOM from 'react-dom'; import { contextBridge, ipcRenderer } from 'electron'; diff --git a/ts/windows/shims.ts b/ts/windows/shims.ts new file mode 100644 index 000000000000..0e9453be42c9 --- /dev/null +++ b/ts/windows/shims.ts @@ -0,0 +1,4 @@ +// Copyright 2022 Signal Messenger, LLC +// SPDX-License-Identifier: AGPL-3.0-only + +import '../util/patchWindows7Hostname';