waveterm/emain/docsite.ts
Evan Simkowitz 74cda378f8
Embed static copy of docsite for help view (#949)
This will take the latest artifact from the waveterm-docs repo and embed
it in the app binary. When the help view is launched, it will be served
from our backend. If the embedded copy doesn't exist, such as in
unpackaged versions of the app or in locally packaged versions, it will
use the hosted site instead.

There is a sibling PR in the docs repository to build the embedded
version of the app (strips out some external links, removes Algolia
DocSearch, updates the baseUrl)
https://github.com/wavetermdev/waveterm-docs/pull/46
2024-10-03 20:28:05 -07:00

28 lines
966 B
TypeScript

import { getWebServerEndpoint } from "@/util/endpoints";
import { fetch } from "@/util/fetchutil";
import { ipcMain } from "electron";
const docsiteWebUrl = "https://docs.waveterm.dev/";
let docsiteUrl: string;
ipcMain.on("get-docsite-url", (event) => {
event.returnValue = docsiteUrl;
});
export async function initDocsite() {
const docsiteEmbeddedUrl = getWebServerEndpoint() + "/docsite/";
try {
const response = await fetch(docsiteEmbeddedUrl);
if (response.ok) {
console.log("Embedded docsite is running, using embedded version for help view");
docsiteUrl = docsiteEmbeddedUrl;
} else {
console.log("Embedded docsite is not running, using web version for help view", response);
docsiteUrl = docsiteWebUrl;
}
} catch (error) {
console.log("Failed to fetch docsite url, using web version for help view", error);
docsiteUrl = docsiteWebUrl;
}
}