Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:recycle: https://github.com/siyuan-note/siyuan/pull/15123

Vanessa00542d09894f
diff --git a/app/src/util/assets.ts b/app/src/util/assets.ts
index 89cee66835..2a2e8fb983 100644
--- a/app/src/util/assets.ts
+++ b/app/src/util/assets.ts
@@ -9,57 +9,10 @@ import {fetchPost} from "./fetch";
import {appearance} from "../config/appearance";
import {isInAndroid, isInHarmony, isInIOS, isIPad, isIPhone, isMac, isWin11} from "../protyle/util/compatibility";
-const loadIcons = (data: Config.IAppearance) => {
- const isBuiltInIcon = ["ant", "material"].includes(data.icon);
- const iconDefaultName = isBuiltInIcon ? data.icon : "material";
- // 不能使用 data.iconVer,因为其他主题也需要加载默认图标,此时 data.iconVer 为其他图标的版本号
- const iconDefaultURL = `/appearance/icons/${iconDefaultName}/icon.js?v=${Constants.SIYUAN_VERSION}`;
- const iconDefaultScriptElement = document.getElementById("iconDefaultScript");
- const isDefaultIconUnchanged = iconDefaultScriptElement && iconDefaultScriptElement.getAttribute("src").startsWith(iconDefaultURL);
-
- const iconURL = `/appearance/icons/${data.icon}/icon.js?v=${data.iconVer}`;
- const iconScriptElement = document.getElementById("iconScript");
-
- if (
- // 使用的内置图标不变
- isDefaultIconUnchanged &&
- // 使用的第三方图标不变
- iconScriptElement && iconScriptElement.getAttribute("src").startsWith(iconURL)
- ) {
- return;
- }
-
- if (!isDefaultIconUnchanged) {
- iconDefaultScriptElement?.remove();
- }
- iconScriptElement?.remove();
-
- const oldSVGElements = Array.from(document.body.children).filter(child => {
- if (
- child.tagName !== "svg" ||
- // 使用的内置图标不变就不需要移除
- (isDefaultIconUnchanged && child.id === ("icons-" + iconDefaultName)) ||
- // 插件添加的图标 data-name="icons-plugin"
- child.getAttribute("data-name")
- ) {
- return false;
- }
- return true;
+const removeOldSvgElements = (oldSVGElements: Element[]) => {
+ oldSVGElements.forEach(svgElement => {
+ svgElement.remove();
});
-
- addScript(iconDefaultURL, "iconDefaultScript").then(() => {
- if (!isBuiltInIcon) {
- addScript(iconURL, "iconScript").then(removeOldSvgElements);
- } else {
- removeOldSvgElements();
- }
- });
-
- function removeOldSvgElements() {
- oldSVGElements.forEach(svgElement => {
- svgElement.remove();
- });
- }
};
export const loadAssets = (data: Config.IAppearance) => {
@@ -139,7 +92,51 @@ export const loadAssets = (data: Config.IAppearance) => {
addScript(themeScriptAddress, "themeScript");
}
- loadIcons(data);
+ // load icons
+ const isBuiltInIcon = ["ant", "material"].includes(data.icon);
+ const iconDefaultName = isBuiltInIcon ? data.icon : "material";
+ // 不能使用 data.iconVer,因为其他主题也需要加载默认图标,此时 data.iconVer 为其他图标的版本号
+ const iconDefaultURL = `/appearance/icons/${iconDefaultName}/icon.js?v=${Constants.SIYUAN_VERSION}`;
+ const iconDefaultScriptElement = document.getElementById("iconDefaultScript");
+ const isDefaultIconUnchanged = iconDefaultScriptElement && iconDefaultScriptElement.getAttribute("src").startsWith(iconDefaultURL);
+
+ const iconURL = `/appearance/icons/${data.icon}/icon.js?v=${data.iconVer}`;
+ const iconScriptElement = document.getElementById("iconScript");
+
+ if (
+ // 使用的内置图标不变
+ isDefaultIconUnchanged &&
+ // 使用的第三方图标不变
+ iconScriptElement && iconScriptElement.getAttribute("src").startsWith(iconURL)
+ ) {
+ return;
+ }
+
+ if (!isDefaultIconUnchanged) {
+ iconDefaultScriptElement?.remove();
+ }
+ iconScriptElement?.remove();
+ addScript(iconDefaultURL, "iconDefaultScript").then(() => {
+ const oldSVGElements = Array.from(document.body.children).filter(child => {
+ if (
+ child.tagName !== "svg" ||
+ // 使用的内置图标不变就不需要移除
+ (isDefaultIconUnchanged && child.id === ("icons-" + iconDefaultName)) ||
+ // 插件添加的图标 data-name="icons-plugin"
+ child.getAttribute("data-name")
+ ) {
+ return false;
+ }
+ return true;
+ });
+ if (!isBuiltInIcon) {
+ addScript(iconURL, "iconScript").then(() => {
+ removeOldSvgElements(oldSVGElements);
+ });
+ } else {
+ removeOldSvgElements(oldSVGElements);
+ }
+ });
};
export const initAssets = () => {