mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
21 lines
548 B
TypeScript
21 lines
548 B
TypeScript
|
// Copyright 2024, Command Line Inc.
|
||
|
// SPDX-License-Identifier: Apache-2.0
|
||
|
|
||
|
// Utility to abstract the fetch function so the Electron net module can be used when available.
|
||
|
|
||
|
let net: Electron.Net;
|
||
|
|
||
|
try {
|
||
|
import("electron").then(({ net: electronNet }) => (net = electronNet));
|
||
|
} catch (e) {
|
||
|
// do nothing
|
||
|
}
|
||
|
|
||
|
export function fetch(input: string | GlobalRequest | URL, init?: RequestInit): Promise<Response> {
|
||
|
if (net) {
|
||
|
return net.fetch(input.toString(), init);
|
||
|
} else {
|
||
|
return globalThis.fetch(input, init);
|
||
|
}
|
||
|
}
|