feat(构建版本): 给WebUI和原生桌面添加版本
build.yaml / build (push) Successful in 1m38s

This commit is contained in:
xiaoqidun committed 2026-10-23 13:20:12 +08:00
1 parent 85baeda7f9
commit ac2eb2b5c7
8 files changed
+105 -3

No files matched your search

+2 -1
View File
@@ -1,5 +1,6 @@
#!/bin/bash #!/bin/bash
set -e set -e
export TZ=Asia/Shanghai export TZ=Asia/Shanghai
export Version="$(git show -s --format='%ct-%H' HEAD)"
GOOS=js GOARCH=wasm CGO_ENABLED=0 go build -o assets/webui/wasm/ofdgo.wasm -trimpath -ldflags "-s -w -buildid=" ./cmd/webui/wasm.go GOOS=js GOARCH=wasm CGO_ENABLED=0 go build -o assets/webui/wasm/ofdgo.wasm -trimpath -ldflags "-s -w -buildid=" ./cmd/webui/wasm.go
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main -trimpath -ldflags "-s -w -buildid=" ./cmd/webui/webui.go GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main -trimpath -ldflags "-s -w -buildid= -X github.com/xiaoqidun/ofdgo/internal/build.Version=$Version" ./cmd/webui/webui.go
+9 -1
View File
@@ -193,6 +193,14 @@
<button id="batchPagesButton" class="editor-group-action" type="button">页面</button> <button id="batchPagesButton" class="editor-group-action" type="button">页面</button>
</div> </div>
</div> </div>
<dialog id="aboutPanel" class="form-dialog about-dialog" aria-labelledby="aboutTitle">
<form method="dialog">
<h2 id="aboutTitle" class="form-title">OFDGo</h2>
<div class="about-row"><span>构建版本</span><span id="aboutVersion">develop</span></div>
<div class="about-row"><span>项目官网</span><a href="https://ofdgo.aite.me/" target="_blank" rel="noreferrer">https://ofdgo.aite.me/</a></div>
<div class="about-row"><span>项目仓库</span><a href="https://github.com/xiaoqidun/ofdgo" target="_blank" rel="noreferrer">https://github.com/xiaoqidun/ofdgo</a></div>
</form>
</dialog>
<dialog id="closePanel" class="form-dialog confirm-dialog" aria-labelledby="closeTitle"> <dialog id="closePanel" class="form-dialog confirm-dialog" aria-labelledby="closeTitle">
<form method="dialog"> <form method="dialog">
<h2 id="closeTitle" class="form-title">关闭文档</h2> <h2 id="closeTitle" class="form-title">关闭文档</h2>
@@ -841,7 +849,7 @@
</main> </main>
<footer class="app-footer app-bar"> <footer class="app-footer app-bar">
<a class="footer-brand" href="https://github.com/xiaoqidun/ofdgo" target="_blank" rel="noreferrer">OFDGo</a> <button id="aboutButton" class="footer-brand" type="button">OFDGo</button>
<div id="statusText" class="status-text">正在准备引擎</div> <div id="statusText" class="status-text">正在准备引擎</div>
<nav class="footer-links"> <nav class="footer-links">
<a href="https://aite.me/" target="_blank" rel="noreferrer">官方网站</a> <a href="https://aite.me/" target="_blank" rel="noreferrer">官方网站</a>
+35
View File
@@ -866,6 +866,30 @@ button:not(:disabled):hover {
padding: 12px; padding: 12px;
} }
.about-dialog {
width: 460px;
}
.about-row {
display: grid;
grid-template-columns: 4em minmax(0, 1fr);
align-items: start;
gap: 12px;
margin-bottom: 12px;
}
.about-row > span:first-child {
text-align-last: justify;
}
.about-row:last-child {
margin-bottom: 0;
}
.about-row a {
overflow-wrap: anywhere;
}
.form-title { .form-title {
margin: -12px -12px 12px; margin: -12px -12px 12px;
padding: 10px 12px; padding: 10px 12px;
@@ -4135,8 +4159,19 @@ audio.page-media {
flex: 0 0 var(--sidebar-width); flex: 0 0 var(--sidebar-width);
min-width: 0; min-width: 0;
overflow: hidden; overflow: hidden;
padding: 0;
border: 0;
background: none;
color: var(--accent-strong);
font: inherit;
text-align: left;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
cursor: pointer;
}
.footer-brand:hover {
text-decoration: underline;
} }
.status-text { .status-text {
+37 -1
View File
@@ -190,6 +190,9 @@ const el = {
documentTitleBar: document.querySelector("#documentTitleBar"), documentTitleBar: document.querySelector("#documentTitleBar"),
documentTabs: document.querySelector("#documentTabs"), documentTabs: document.querySelector("#documentTabs"),
documentNewTab: document.querySelector("#documentNewTab"), documentNewTab: document.querySelector("#documentNewTab"),
aboutButton: document.querySelector("#aboutButton"),
aboutPanel: document.querySelector("#aboutPanel"),
aboutVersion: document.querySelector("#aboutVersion"),
signButton: document.querySelector("#signButton"), signButton: document.querySelector("#signButton"),
signPanel: document.querySelector("#signPanel"), signPanel: document.querySelector("#signPanel"),
signForm: document.querySelector("#signForm"), signForm: document.querySelector("#signForm"),
@@ -1466,6 +1469,13 @@ el.pageForm.addEventListener("submit", async (event) => {
el.pagePanel.close(); el.pagePanel.close();
} }
}); });
el.aboutButton.addEventListener("click", openAboutPanel);
let aboutBackdrop = false;
el.aboutPanel.addEventListener("pointerdown", event => { aboutBackdrop = event.target === el.aboutPanel; });
el.aboutPanel.addEventListener("click", event => {
if (aboutBackdrop && event.target === el.aboutPanel) el.aboutPanel.close();
aboutBackdrop = false;
});
el.ofdButton.addEventListener("click", openOFDFile); el.ofdButton.addEventListener("click", openOFDFile);
el.closeButton.addEventListener("pointerdown", event => event.preventDefault()); el.closeButton.addEventListener("pointerdown", event => event.preventDefault());
el.closeButton.addEventListener("click", () => closeDocument().catch(error => showError(error, false))); el.closeButton.addEventListener("click", () => closeDocument().catch(error => showError(error, false)));
@@ -1966,10 +1976,36 @@ function handleKeyDown(event) {
} }
function formDialogOpen() { function formDialogOpen() {
return Boolean(sealPreview || resourceManager.pick) || el.closePanel.open || el.attachmentDialog.open || settingsElements.Panel.open || fontBindingElements.Panel.open || el.signPanel.open || el.verifyPanel.open || el.credentialsPanel.open || el.encryptionPanel.open || batchElements.Panel.open || el.exportPanel.open || el.createPanel.open || el.insertPanel.open || el.pagePanel.open || el.paragraphPanel.open || el.importPanel.open || el.infoPanel.open || el.documentPanel.open return Boolean(sealPreview || resourceManager.pick) || el.aboutPanel.open || el.closePanel.open || el.attachmentDialog.open || settingsElements.Panel.open || fontBindingElements.Panel.open || el.signPanel.open || el.verifyPanel.open || el.credentialsPanel.open || el.encryptionPanel.open || batchElements.Panel.open || el.exportPanel.open || el.createPanel.open || el.insertPanel.open || el.pagePanel.open || el.paragraphPanel.open || el.importPanel.open || el.infoPanel.open || el.documentPanel.open
|| resourceElements.Panel.open || el.structureDialog.open || el.versionPanel.open || el.batchPagesPanel.open || el.objectStylePanel.open || el.outlinePanel.open || el.objectBoundsPanel.open || el.annotationNote.open || el.annotationCreate.open || el.objectPicker.open; || resourceElements.Panel.open || el.structureDialog.open || el.versionPanel.open || el.batchPagesPanel.open || el.objectStylePanel.open || el.outlinePanel.open || el.objectBoundsPanel.open || el.annotationNote.open || el.annotationCreate.open || el.objectPicker.open;
} }
async function openAboutPanel() {
el.aboutVersion.textContent = "读取中";
documentDialogs.showApplication(el.aboutPanel);
let raw = "";
try {
const response = await fetch("./", { cache: "no-store" });
if (response.ok) raw = response.headers.get("X-OFDGo-Build-Version") || "";
} catch {
if (el.aboutPanel.open) el.aboutVersion.textContent = "版本信息不可用";
return;
}
if (!el.aboutPanel.open) return;
if (!raw) {
el.aboutVersion.textContent = "develop";
return;
}
const match = /^(\d+)-([0-9a-f]{40}|[0-9a-f]{64})$/i.exec(raw);
const seconds = Number(match?.[1]);
const date = new Date(seconds * 1000);
if (!match || !Number.isSafeInteger(seconds) || Number.isNaN(date.getTime())) {
el.aboutVersion.textContent = "版本信息异常";
return;
}
el.aboutVersion.textContent = `${date.toISOString().slice(0, 10).replaceAll("-", "")}-${match[2].slice(0, 7)}`;
}
function setObjectDimension(input, value) { function setObjectDimension(input, value) {
input.value = String(Number(value.toFixed(2))); input.value = String(Number(value.toFixed(2)));
input.defaultValue = input.value; input.defaultValue = input.value;
+3
View File
@@ -29,6 +29,7 @@ import (
"github.com/xiaoqidun/ofdgo/assets/webui" "github.com/xiaoqidun/ofdgo/assets/webui"
"github.com/xiaoqidun/ofdgo/assets/webui/wasm" "github.com/xiaoqidun/ofdgo/assets/webui/wasm"
"github.com/xiaoqidun/ofdgo/internal/build"
) )
func main() { func main() {
@@ -50,6 +51,7 @@ func serveWebUI() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-store") w.Header().Set("Cache-Control", "no-store")
w.Header().Set("X-OFDGo-Checksum", checksum) w.Header().Set("X-OFDGo-Checksum", checksum)
w.Header().Set("X-OFDGo-Build-Version", build.Version)
if r.URL.Path == "/ofdgo.wasm" { if r.URL.Path == "/ofdgo.wasm" {
wasm.ServeHTTP(w, r) wasm.ServeHTTP(w, r)
return return
@@ -73,5 +75,6 @@ func resourceChecksum() string {
hash.Write(data) hash.Write(data)
} }
} }
hash.Write([]byte(build.Version))
return hex.EncodeToString(hash.Sum(nil)) return hex.EncodeToString(hash.Sum(nil))
} }
File renamed without changes.
+17
View File
@@ -0,0 +1,17 @@
// Copyright 2025-2026 肖其顿 (XIAO QI DUN)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package build
var Version string
+2
View File
@@ -37,6 +37,7 @@ import (
"github.com/xiaoqidun/guigo" "github.com/xiaoqidun/guigo"
"github.com/xiaoqidun/ofdgo" "github.com/xiaoqidun/ofdgo"
webuiassets "github.com/xiaoqidun/ofdgo/assets/webui" webuiassets "github.com/xiaoqidun/ofdgo/assets/webui"
"github.com/xiaoqidun/ofdgo/internal/build"
"github.com/xiaoqidun/ofdgo/internal/webui" "github.com/xiaoqidun/ofdgo/internal/webui"
) )
@@ -115,6 +116,7 @@ func Run(ctx context.Context, paths []string, dataDir string) error {
return return
} }
w.Header().Set("Cache-Control", "no-store") w.Header().Set("Cache-Control", "no-store")
w.Header().Set("X-OFDGo-Build-Version", build.Version)
static.ServeHTTP(w, r) static.ServeHTTP(w, r)
}) })
options.Handler = handler options.Handler = handler