Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed static copy of docsite for help view #949

Merged
merged 7 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/build-helper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
env:
GO_VERSION: "1.22"
NODE_VERSION: "20"
STATIC_DOCSITE_PATH: waveterm-docs
esimkowitz marked this conversation as resolved.
Show resolved Hide resolved
jobs:
runbuild:
permissions:
Expand Down Expand Up @@ -110,6 +111,15 @@ jobs:
smctl windows certsync
shell: cmd

- name: Download waveterm-docs static site
uses: dawidd6/action-download-artifact@v6
with:
github_token: ${{secrets.GITHUB_TOKEN}}
workflow: build-static.yml
esimkowitz marked this conversation as resolved.
Show resolved Hide resolved
repo: wavetermdev/waveterm-docs
name: static-site
path: ${{env.STATIC_DOCSITE_PATH}}

# Build and upload packages
- name: Build (not Windows)
if: matrix.platform != 'windows'
Expand All @@ -121,13 +131,15 @@ jobs:
APPLE_ID: ${{ matrix.platform == 'darwin' && secrets.PROD_MACOS_NOTARIZATION_APPLE_ID_2 }}
APPLE_APP_SPECIFIC_PASSWORD: ${{ matrix.platform == 'darwin' && secrets.PROD_MACOS_NOTARIZATION_PWD_2 }}
APPLE_TEAM_ID: ${{ matrix.platform == 'darwin' && secrets.PROD_MACOS_NOTARIZATION_TEAM_ID_2 }}
STATIC_DOCSITE_PATH: ${{env.STATIC_DOCSITE_PATH}}
- name: Build (Windows only)
if: matrix.platform == 'windows'
run: task package
env:
USE_SYSTEM_FPM: true # Ensure that the installed version of FPM is used rather than the bundled one.
CSC_LINK: ${{ steps.variables.outputs.SM_CLIENT_CERT_FILE }}
CSC_KEY_PASSWORD: ${{ secrets.SM_CLIENT_CERT_PASSWORD }}
STATIC_DOCSITE_PATH: ${{env.STATIC_DOCSITE_PATH}}
shell: powershell # electron-builder's Windows code signing package has some compatibility issues with pwsh, so we need to use Windows Powershell
- name: Upload to S3 staging
run: task artifacts:upload
Expand Down
9 changes: 9 additions & 0 deletions electron-builder.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const config = {
},
asarUnpack: [
"dist/bin/**/*", // wavesrv and wsh binaries
"dist/docsite/**/*", // the static docsite
],
mac: {
target: [
Expand Down Expand Up @@ -86,6 +87,14 @@ const config = {
provider: "generic",
url: "https://dl.waveterm.dev/releases-w2",
},
beforePack: () => {
const staticSourcePath = process.env.STATIC_DOCSITE_PATH;
const staticDestPath = "dist/docsite";
if (staticSourcePath) {
console.log(`Static docsite path is specified, copying from "${staticSourcePath}" to "${staticDestPath}"`);
fs.cpSync(staticSourcePath, staticDestPath, { recursive: true });
}
},
afterPack: (context) => {
// This is a workaround to restore file permissions to the wavesrv binaries on macOS after packaging the universal binary.
if (context.electronPlatformName === "darwin" && context.arch === Arch.universal) {
Expand Down
27 changes: 27 additions & 0 deletions emain/docsite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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;
}
}
8 changes: 5 additions & 3 deletions emain/emain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import { fetch } from "../frontend/util/fetchutil";
import * as keyutil from "../frontend/util/keyutil";
import { fireAndForget } from "../frontend/util/util";
import { AuthKey, AuthKeyEnv, configureAuthKeyRequestInjection } from "./authkey";
import { initDocsite } from "./docsite";
import { ElectronWshClient, initElectronWshClient } from "./emain-wsh";
import { getLaunchSettings } from "./launchsettings";
import { getAppMenu } from "./menu";
import {
getElectronAppBasePath,
getGoAppBasePath,
getElectronAppUnpackedBasePath,
getWaveHomeDir,
getWaveSrvCwd,
getWaveSrvPath,
Expand Down Expand Up @@ -95,7 +96,7 @@ console.log(
"waveterm-app starting, WAVETERM_HOME=%s, electronpath=%s gopath=%s arch=%s/%s",
waveHome,
getElectronAppBasePath(),
getGoAppBasePath(),
getElectronAppUnpackedBasePath(),
unamePlatform,
unameArch
)
Expand Down Expand Up @@ -155,7 +156,7 @@ function runWaveSrv(): Promise<boolean> {
pReject = argReject;
});
const envCopy = { ...process.env };
envCopy[WaveAppPathVarName] = getGoAppBasePath();
envCopy[WaveAppPathVarName] = getElectronAppUnpackedBasePath();
envCopy[WaveSrvReadySignalPidVarName] = process.pid.toString();
envCopy[AuthKeyEnv] = AuthKey;
const waveSrvCmd = getWaveSrvPath();
Expand Down Expand Up @@ -871,6 +872,7 @@ async function appMain() {
await electronApp.whenReady();
configureAuthKeyRequestInjection(electron.session.defaultSession);
await relaunchBrowserWindows();
await initDocsite();
setTimeout(runActiveTimer, 5000); // start active timer, wait 5s just to be safe
try {
initElectronWshClient();
Expand Down
8 changes: 4 additions & 4 deletions emain/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function getElectronAppBasePath(): string {
return path.dirname(import.meta.dirname);
}

function getGoAppBasePath(): string {
function getElectronAppUnpackedBasePath(): string {
return getElectronAppBasePath().replace("app.asar", "app.asar.unpacked");
}

Expand All @@ -59,10 +59,10 @@ const wavesrvBinName = `wavesrv.${unameArch}`;
function getWaveSrvPath(): string {
if (process.platform === "win32") {
const winBinName = `${wavesrvBinName}.exe`;
const appPath = path.join(getGoAppBasePath(), "bin", winBinName);
const appPath = path.join(getElectronAppUnpackedBasePath(), "bin", winBinName);
return `${appPath}`;
}
return path.join(getGoAppBasePath(), "bin", wavesrvBinName);
return path.join(getElectronAppUnpackedBasePath(), "bin", wavesrvBinName);
}

function getWaveSrvCwd(): string {
Expand All @@ -71,7 +71,7 @@ function getWaveSrvCwd(): string {

export {
getElectronAppBasePath,
getGoAppBasePath,
getElectronAppUnpackedBasePath,
getWaveHomeDir,
getWaveSrvCwd,
getWaveSrvPath,
Expand Down
1 change: 1 addition & 0 deletions emain/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ contextBridge.exposeInMainWorld("api", {
getUserName: () => ipcRenderer.sendSync("get-user-name"),
getHostName: () => ipcRenderer.sendSync("get-host-name"),
getAboutModalDetails: () => ipcRenderer.sendSync("get-about-modal-details"),
getDocsiteUrl: () => ipcRenderer.sendSync("get-docsite-url"),
openNewWindow: () => ipcRenderer.send("open-new-window"),
showContextMenu: (menu, position) => ipcRenderer.send("contextmenu-show", menu, position),
onContextMenuClick: (callback) => ipcRenderer.on("contextmenu-click", (_event, id) => callback(id)),
Expand Down
15 changes: 5 additions & 10 deletions frontend/app/view/helpview/helpview.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@

.help-view {
width: 100%;
padding: 0 5px;

.title {
font-weight: bold;
}

code {
font: var(--fixed-font);
background-color: var(--highlight-bg-color);
padding: 0 5px;
height: 100%;
.docsite-iframe {
esimkowitz marked this conversation as resolved.
Show resolved Hide resolved
width: 100%;
height: 100%;
border: 0;
}
}
Loading