mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-22 16:48:23 +01:00
23 lines
607 B
TypeScript
23 lines
607 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;
|
|
|
|
if (typeof window === "undefined") {
|
|
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);
|
|
}
|
|
}
|