feat(文件关联): 新增Windows文件关联管理
build.yaml / build (push) Successful in 45s

This commit is contained in:
xiaoqidun committed 2026-10-25 15:48:46 +08:00
1 parent df81d41d95
commit f0c0b9db94
6 files changed
+189 -4

No files matched your search

+6
View File
@@ -202,6 +202,12 @@
<div class="about-row"><span>桌面软件</span><a href="https://ofdgo.aite.me/releases/" target="_blank" rel="noreferrer">https://ofdgo.aite.me/releases/</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>
<section id="associationSection" class="about-associations" hidden>
<div class="association-heading"><span>文件关联</span><span id="associationPermission" hidden>所有用户需管理员权限</span></div>
<div class="association-row" data-scope="user"><span>当前用户</span><span class="association-state"></span><div class="association-actions"><button class="small-button" type="button" data-action="register">注册</button><button class="small-button" type="button" data-action="remove">撤销</button></div></div>
<div class="association-row" data-scope="machine"><span>所有用户</span><span class="association-state"></span><div class="association-actions"><button class="small-button" type="button" data-action="register">注册</button><button class="small-button" type="button" data-action="remove">撤销</button></div></div>
<div id="associationMessage" class="form-status" hidden></div>
</section>
</dialog>
<dialog id="closePanel" class="form-dialog confirm-dialog">
<form method="dialog">
+48
View File
@@ -964,6 +964,54 @@ button:not(:disabled):hover {
overflow-wrap: anywhere;
}
.about-associations {
padding: 12px;
border-top: 1px solid var(--line);
}
.association-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
font-weight: 600;
white-space: nowrap;
}
#associationPermission {
color: var(--text-muted);
font-size: 12px;
font-weight: normal;
}
.association-row {
display: grid;
grid-template-columns: 4em minmax(0, 1fr) auto;
align-items: center;
gap: 12px;
white-space: nowrap;
}
.association-row + .association-row {
margin-top: 12px;
}
.association-state {
color: var(--text-muted);
}
.association-actions {
display: flex;
gap: 8px;
}
#associationMessage {
margin-top: 12px;
white-space: nowrap;
overflow-x: auto;
}
.form-title {
margin: -12px -12px 12px;
padding: 10px 12px;
+56
View File
@@ -196,6 +196,9 @@ const el = {
aboutButton: document.querySelector("#aboutButton"),
aboutPanel: document.querySelector("#aboutPanel"),
aboutVersion: document.querySelector("#aboutVersion"),
associationSection: document.querySelector("#associationSection"),
associationPermission: document.querySelector("#associationPermission"),
associationMessage: document.querySelector("#associationMessage"),
signButton: document.querySelector("#signButton"),
signPanel: document.querySelector("#signPanel"),
signForm: document.querySelector("#signForm"),
@@ -1499,6 +1502,7 @@ el.pageForm.addEventListener("submit", async (event) => {
}
});
el.aboutButton.addEventListener("click", openAboutPanel);
el.associationSection.addEventListener("click", changeFileAssociation);
let aboutBackdrop = false;
el.aboutPanel.addEventListener("pointerdown", event => { aboutBackdrop = event.target === el.aboutPanel; });
el.aboutPanel.addEventListener("click", event => {
@@ -2017,7 +2021,9 @@ function formDialogOpen() {
async function openAboutPanel() {
el.aboutVersion.textContent = "读取中";
el.associationMessage.hidden = true;
documentDialogs.showApplication(el.aboutPanel);
if (nativeHost) void refreshFileAssociations();
let raw = "";
try {
const response = await fetch("./", { cache: "no-store" });
@@ -2041,6 +2047,56 @@ async function openAboutPanel() {
el.aboutVersion.textContent = `${date.toISOString().slice(0, 10).replaceAll("-", "")}-${match[2].slice(0, 7)}`;
}
async function refreshFileAssociations() {
if (!nativeHost || el.associationSection.dataset.busy) return;
el.associationSection.dataset.busy = "true";
for (const control of el.associationSection.querySelectorAll("button")) control.disabled = true;
for (const label of el.associationSection.querySelectorAll(".association-state")) {
label.textContent = "查询中";
label.title = "";
}
try {
const states = await nativeHost.call("association.query", {});
el.associationSection.hidden = !states.user.supported;
el.associationPermission.hidden = !states.machine.supported || states.machine.writable;
for (const row of el.associationSection.querySelectorAll(".association-row")) {
const state = states[row.dataset.scope];
const label = row.querySelector(".association-state");
label.textContent = state.error ? "不可用" : state.complete ? "已注册" : state.registered ? "待更新" : "未注册";
label.title = state.error || "";
row.querySelector('[data-action="register"]').disabled = !state.writable || !!state.error || state.complete;
row.querySelector('[data-action="remove"]').disabled = !state.writable || !!state.error || !state.registered;
}
} catch (error) {
el.associationSection.hidden = false;
el.associationPermission.hidden = true;
for (const label of el.associationSection.querySelectorAll(".association-state")) label.textContent = "不可用";
el.associationMessage.textContent = `查询失败:${error.message}`;
el.associationMessage.hidden = false;
} finally {
delete el.associationSection.dataset.busy;
}
}
async function changeFileAssociation(event) {
const button = event.target.closest("button[data-action]");
if (!nativeHost || !button || button.disabled || el.associationSection.dataset.busy) return;
const row = button.closest(".association-row");
el.associationSection.dataset.busy = "true";
for (const control of el.associationSection.querySelectorAll("button")) control.disabled = true;
el.associationMessage.hidden = true;
row.querySelector(".association-state").textContent = button.dataset.action === "register" ? "注册中" : "撤销中";
try {
await nativeHost.call(`association.${button.dataset.action}`, {scope:row.dataset.scope});
} catch (error) {
el.associationMessage.textContent = `${row.firstElementChild.textContent}:${error.message}`;
el.associationMessage.hidden = false;
} finally {
delete el.associationSection.dataset.busy;
await refreshFileAssociations();
}
}
function setObjectDimension(input, value) {
input.value = String(Number(value.toFixed(2)));
input.defaultValue = input.value;