Monkey-patch os.hostname on Windows 7

This commit is contained in:
Fedor Indutny 2022-06-23 12:15:27 -07:00 committed by GitHub
parent 82dad0d7f7
commit 96b864d6a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 51 additions and 17 deletions

View File

@ -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<string>('contentProxyUrl'),

View File

@ -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';

View File

@ -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';
}

View File

@ -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';

View File

@ -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';

View File

@ -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';

View File

@ -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';

View File

@ -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';

View File

@ -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';

View File

@ -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';

4
ts/windows/shims.ts Normal file
View File

@ -0,0 +1,4 @@
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import '../util/patchWindows7Hostname';