Skip to content

Commit 74cda37

Browse files
authored
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) wavetermdev/waveterm-docs#46
1 parent cee46a6 commit 74cda37

File tree

13 files changed

+120
-219
lines changed

13 files changed

+120
-219
lines changed

.github/workflows/build-helper.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
env:
1212
GO_VERSION: "1.22"
1313
NODE_VERSION: "20"
14+
STATIC_DOCSITE_PATH: docsite
1415
jobs:
1516
runbuild:
1617
permissions:
@@ -110,6 +111,15 @@ jobs:
110111
smctl windows certsync
111112
shell: cmd
112113

114+
- name: Download waveterm-docs static site
115+
uses: dawidd6/action-download-artifact@v6
116+
with:
117+
github_token: ${{secrets.GITHUB_TOKEN}}
118+
workflow: build-embedded.yml
119+
repo: wavetermdev/waveterm-docs
120+
name: static-site
121+
path: ${{env.STATIC_DOCSITE_PATH}}
122+
113123
# Build and upload packages
114124
- name: Build (not Windows)
115125
if: matrix.platform != 'windows'
@@ -121,13 +131,15 @@ jobs:
121131
APPLE_ID: ${{ matrix.platform == 'darwin' && secrets.PROD_MACOS_NOTARIZATION_APPLE_ID_2 }}
122132
APPLE_APP_SPECIFIC_PASSWORD: ${{ matrix.platform == 'darwin' && secrets.PROD_MACOS_NOTARIZATION_PWD_2 }}
123133
APPLE_TEAM_ID: ${{ matrix.platform == 'darwin' && secrets.PROD_MACOS_NOTARIZATION_TEAM_ID_2 }}
134+
STATIC_DOCSITE_PATH: ${{env.STATIC_DOCSITE_PATH}}
124135
- name: Build (Windows only)
125136
if: matrix.platform == 'windows'
126137
run: task package
127138
env:
128139
USE_SYSTEM_FPM: true # Ensure that the installed version of FPM is used rather than the bundled one.
129140
CSC_LINK: ${{ steps.variables.outputs.SM_CLIENT_CERT_FILE }}
130141
CSC_KEY_PASSWORD: ${{ secrets.SM_CLIENT_CERT_PASSWORD }}
142+
STATIC_DOCSITE_PATH: ${{env.STATIC_DOCSITE_PATH}}
131143
shell: powershell # electron-builder's Windows code signing package has some compatibility issues with pwsh, so we need to use Windows Powershell
132144
- name: Upload to S3 staging
133145
run: task artifacts:upload

electron-builder.config.cjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const config = {
3434
},
3535
asarUnpack: [
3636
"dist/bin/**/*", // wavesrv and wsh binaries
37+
"dist/docsite/**/*", // the static docsite
3738
],
3839
mac: {
3940
target: [
@@ -86,6 +87,14 @@ const config = {
8687
provider: "generic",
8788
url: "https://dl.waveterm.dev/releases-w2",
8889
},
90+
beforePack: () => {
91+
const staticSourcePath = process.env.STATIC_DOCSITE_PATH;
92+
const staticDestPath = "dist/docsite";
93+
if (staticSourcePath) {
94+
console.log(`Static docsite path is specified, copying from "${staticSourcePath}" to "${staticDestPath}"`);
95+
fs.cpSync(staticSourcePath, staticDestPath, { recursive: true });
96+
}
97+
},
8998
afterPack: (context) => {
9099
// This is a workaround to restore file permissions to the wavesrv binaries on macOS after packaging the universal binary.
91100
if (context.electronPlatformName === "darwin" && context.arch === Arch.universal) {

emain/docsite.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { getWebServerEndpoint } from "@/util/endpoints";
2+
import { fetch } from "@/util/fetchutil";
3+
import { ipcMain } from "electron";
4+
5+
const docsiteWebUrl = "https://docs.waveterm.dev/";
6+
let docsiteUrl: string;
7+
8+
ipcMain.on("get-docsite-url", (event) => {
9+
event.returnValue = docsiteUrl;
10+
});
11+
12+
export async function initDocsite() {
13+
const docsiteEmbeddedUrl = getWebServerEndpoint() + "/docsite/";
14+
try {
15+
const response = await fetch(docsiteEmbeddedUrl);
16+
if (response.ok) {
17+
console.log("Embedded docsite is running, using embedded version for help view");
18+
docsiteUrl = docsiteEmbeddedUrl;
19+
} else {
20+
console.log("Embedded docsite is not running, using web version for help view", response);
21+
docsiteUrl = docsiteWebUrl;
22+
}
23+
} catch (error) {
24+
console.log("Failed to fetch docsite url, using web version for help view", error);
25+
docsiteUrl = docsiteWebUrl;
26+
}
27+
}

emain/emain.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ import { fetch } from "../frontend/util/fetchutil";
2020
import * as keyutil from "../frontend/util/keyutil";
2121
import { fireAndForget } from "../frontend/util/util";
2222
import { AuthKey, AuthKeyEnv, configureAuthKeyRequestInjection } from "./authkey";
23+
import { initDocsite } from "./docsite";
2324
import { ElectronWshClient, initElectronWshClient } from "./emain-wsh";
2425
import { getLaunchSettings } from "./launchsettings";
2526
import { getAppMenu } from "./menu";
2627
import {
2728
getElectronAppBasePath,
28-
getGoAppBasePath,
29+
getElectronAppUnpackedBasePath,
2930
getWaveHomeDir,
3031
getWaveSrvCwd,
3132
getWaveSrvPath,
@@ -95,7 +96,7 @@ console.log(
9596
"waveterm-app starting, WAVETERM_HOME=%s, electronpath=%s gopath=%s arch=%s/%s",
9697
waveHome,
9798
getElectronAppBasePath(),
98-
getGoAppBasePath(),
99+
getElectronAppUnpackedBasePath(),
99100
unamePlatform,
100101
unameArch
101102
)
@@ -155,7 +156,7 @@ function runWaveSrv(): Promise<boolean> {
155156
pReject = argReject;
156157
});
157158
const envCopy = { ...process.env };
158-
envCopy[WaveAppPathVarName] = getGoAppBasePath();
159+
envCopy[WaveAppPathVarName] = getElectronAppUnpackedBasePath();
159160
envCopy[WaveSrvReadySignalPidVarName] = process.pid.toString();
160161
envCopy[AuthKeyEnv] = AuthKey;
161162
const waveSrvCmd = getWaveSrvPath();
@@ -871,6 +872,7 @@ async function appMain() {
871872
await electronApp.whenReady();
872873
configureAuthKeyRequestInjection(electron.session.defaultSession);
873874
await relaunchBrowserWindows();
875+
await initDocsite();
874876
setTimeout(runActiveTimer, 5000); // start active timer, wait 5s just to be safe
875877
try {
876878
initElectronWshClient();

emain/platform.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function getElectronAppBasePath(): string {
5050
return path.dirname(import.meta.dirname);
5151
}
5252

53-
function getGoAppBasePath(): string {
53+
function getElectronAppUnpackedBasePath(): string {
5454
return getElectronAppBasePath().replace("app.asar", "app.asar.unpacked");
5555
}
5656

@@ -59,10 +59,10 @@ const wavesrvBinName = `wavesrv.${unameArch}`;
5959
function getWaveSrvPath(): string {
6060
if (process.platform === "win32") {
6161
const winBinName = `${wavesrvBinName}.exe`;
62-
const appPath = path.join(getGoAppBasePath(), "bin", winBinName);
62+
const appPath = path.join(getElectronAppUnpackedBasePath(), "bin", winBinName);
6363
return `${appPath}`;
6464
}
65-
return path.join(getGoAppBasePath(), "bin", wavesrvBinName);
65+
return path.join(getElectronAppUnpackedBasePath(), "bin", wavesrvBinName);
6666
}
6767

6868
function getWaveSrvCwd(): string {
@@ -71,7 +71,7 @@ function getWaveSrvCwd(): string {
7171

7272
export {
7373
getElectronAppBasePath,
74-
getGoAppBasePath,
74+
getElectronAppUnpackedBasePath,
7575
getWaveHomeDir,
7676
getWaveSrvCwd,
7777
getWaveSrvPath,

emain/preload.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ contextBridge.exposeInMainWorld("api", {
1111
getUserName: () => ipcRenderer.sendSync("get-user-name"),
1212
getHostName: () => ipcRenderer.sendSync("get-host-name"),
1313
getAboutModalDetails: () => ipcRenderer.sendSync("get-about-modal-details"),
14+
getDocsiteUrl: () => ipcRenderer.sendSync("get-docsite-url"),
1415
openNewWindow: () => ipcRenderer.send("open-new-window"),
1516
showContextMenu: (menu, position) => ipcRenderer.send("contextmenu-show", menu, position),
1617
onContextMenuClick: (callback) => ipcRenderer.on("contextmenu-click", (_event, id) => callback(id)),

frontend/app/view/helpview/helpview.less

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,10 @@
33

44
.help-view {
55
width: 100%;
6-
padding: 0 5px;
7-
8-
.title {
9-
font-weight: bold;
10-
}
11-
12-
code {
13-
font: var(--fixed-font);
14-
background-color: var(--highlight-bg-color);
15-
padding: 0 5px;
6+
height: 100%;
7+
.docsite-webview {
8+
width: 100%;
9+
height: 100%;
10+
border: 0;
1611
}
1712
}

0 commit comments

Comments
 (0)