An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Hide unavailable startup appearance setting https://github.com/siyuan-note/siyuan/issues/18972
Daniel8e3d3e5d8a7f
diff --git a/app/src/config/tabs/appearanceTab.ts b/app/src/config/tabs/appearanceTab.tsindex c31978b402..19dcbb6e2b 100644--- a/app/src/config/tabs/appearanceTab.ts+++ b/app/src/config/tabs/appearanceTab.ts@@ -35,6 +35,11 @@ import {unregisterCustomFont} from "../../util/customFont";import {showMessage} from "../../dialog/message";+import {+ shouldShowBootAppearanceSetting,+ type IBootAppearanceListItem,+ type IBootAppearanceSelection,+} from "./bootAppearanceState";/// #if MOBILEimport {genMobileBottomBarSettingHTML, mountMobileBottomBarSetting} from "../../mobile/util/mobileBottomBar";import {genMobileSidePanelSettingHTML, mountMobileSidePanelSetting} from "../../mobile/util/mobileSidePanelSetting";@@ -52,19 +57,9 @@ interface IFontItem {spacing?: string;}-interface IBootAppearanceListItem {- provider: string;- appearance: string;- displayName: string;- frontends: string[];-}-interface IBootAppearanceListData {appearances: IBootAppearanceListItem[];- current: {- provider: string;- appearance: string;- };+ current: IBootAppearanceSelection;}type FontFamiliesConfigKey = "fontFamilies" | "codeFontFamilies";@@ -569,7 +564,7 @@ const fontItemFromElement = (item: HTMLElement): IFontItem => ({spacing: item.dataset.spacing,});-const genBootAppearanceHtml = () => `<label class="fn__flex b3-label config-item config-wrap">+const genBootAppearanceHtml = () => `<label class="fn__flex b3-label config-item config-wrap fn__none"><div class="fn__flex-1 config-item__main"><div class="config-name">${escapeHtml(window.siyuan.languages.bootAppearance)}</div><div class="b3-label__text">${escapeHtml(window.siyuan.languages.bootAppearanceTip)}</div>@@ -585,23 +580,30 @@ const mountBootAppearance = async (root: HTMLElement) => {if (!selectElement) {return;}+ const itemElement = selectElement.closest<HTMLElement>(".config-item");let response: IWebSocketData;try {response = await fetchSyncPost("/api/setting/getBootAppearances");} catch (error) {console.warn("get boot appearances failed", error);+ itemElement?.classList.remove("fn__none");return;}const data = response.data as IBootAppearanceListData;- if (!data || !Array.isArray(data.appearances)) {+ if (response.code !== 0 || !data || !Array.isArray(data.appearances)) {+ itemElement?.classList.remove("fn__none");return;}const frontend = getFrontend() === "mobile" ? "mobile" : "desktop";- selectElement.replaceChildren(new Option(window.siyuan.languages.default, ""));const configuredValue = data.current?.provider && data.current?.appearance? JSON.stringify([data.current.provider, data.current.appearance]): "";+ if (!shouldShowBootAppearanceSetting(data.appearances, data.current, frontend)) {+ return;+ }++ selectElement.replaceChildren(new Option(window.siyuan.languages.default, ""));const providerGroups = new Map<string, HTMLOptGroupElement>();data.appearances.forEach((item) => {const value = JSON.stringify([item.provider, item.appearance]);@@ -625,6 +627,7 @@ const mountBootAppearance = async (root: HTMLElement) => {: "";let savedValue = selectElement.value;selectElement.disabled = window.siyuan.config.readonly;+ itemElement?.classList.remove("fn__none");selectElement.addEventListener("change", async () => {const nextValue = selectElement.value;const [provider, appearance] = nextValue ? JSON.parse(nextValue) as [string, string] : ["", ""];diff --git a/app/src/config/tabs/bootAppearanceState.test.ts b/app/src/config/tabs/bootAppearanceState.test.tsnew file mode 100644index 0000000000..65a17924d4--- /dev/null+++ b/app/src/config/tabs/bootAppearanceState.test.ts@@ -0,0 +1,40 @@+import {describe, it} from "node:test";+import * as assert from "node:assert/strict";+import {shouldShowBootAppearanceSetting, type IBootAppearanceListItem} from "./bootAppearanceState";++const appearance = (frontends: string[]): IBootAppearanceListItem => ({+ provider: "provider",+ appearance: "appearance",+ displayName: "Appearance",+ frontends,+});++describe("boot appearance setting visibility", () => {+ it("hides when no appearance is available", () => {+ assert.equal(shouldShowBootAppearanceSetting([], {provider: "", appearance: ""}, "desktop"), false);+ });++ it("hides when appearances do not support the current frontend", () => {+ assert.equal(shouldShowBootAppearanceSetting(+ [appearance(["mobile"])],+ {provider: "", appearance: ""},+ "desktop",+ ), false);+ });++ it("shows when an appearance supports the current frontend", () => {+ assert.equal(shouldShowBootAppearanceSetting(+ [appearance(["desktop"])],+ {provider: "", appearance: ""},+ "desktop",+ ), true);+ });++ it("shows an incompatible current selection so it can be cleared", () => {+ assert.equal(shouldShowBootAppearanceSetting(+ [appearance(["mobile"])],+ {provider: "provider", appearance: "appearance"},+ "desktop",+ ), true);+ });+});diff --git a/app/src/config/tabs/bootAppearanceState.ts b/app/src/config/tabs/bootAppearanceState.tsnew file mode 100644index 0000000000..18f110f81c--- /dev/null+++ b/app/src/config/tabs/bootAppearanceState.ts@@ -0,0 +1,18 @@+export interface IBootAppearanceListItem {+ provider: string;+ appearance: string;+ displayName: string;+ frontends: string[];+}++export interface IBootAppearanceSelection {+ provider: string;+ appearance: string;+}++export const shouldShowBootAppearanceSetting = (+ appearances: IBootAppearanceListItem[],+ current: IBootAppearanceSelection | null | undefined,+ frontend: string,+) => Boolean(current?.provider && current.appearance) ||+ appearances.some((item) => item.frontends?.includes(frontend));