diff --git a/app/src/config/bazaar.ts b/app/src/config/bazaar.ts index 00b5ec3be..d1dd37773 100644 --- a/app/src/config/bazaar.ts +++ b/app/src/config/bazaar.ts @@ -6,6 +6,11 @@ import {confirmDialog} from "../dialog/confirmDialog"; import {highlightRender} from "../protyle/markdown/highlightRender"; import {exportLayout} from "../layout/util"; import {Constants} from "../constants"; +/// #if !BROWSER +import {shell} from "electron"; +import * as path from "path"; +/// #endif +import {isBrowser} from "../util/functions"; export const bazaar = { element: undefined as Element, @@ -26,14 +31,31 @@ export const bazaar = { const loadingHTML = `
`; return `
-
${window.siyuan.languages.theme}
+
${window.siyuan.languages.downloaded}
+
${window.siyuan.languages.theme}
${window.siyuan.languages.template}
${window.siyuan.languages.icon}
${window.siyuan.languages.widget}
-
${window.siyuan.languages.downloaded}
-
+
+
+
+
+
+ +
+ +
+ +
+ +
+
+ ${loadingHTML} +
+
+
@@ -113,23 +135,6 @@ export const bazaar = { ${loadingHTML}
-
-
-
-
-
- -
- -
- -
- -
-
- ${loadingHTML} -
-
`; @@ -172,16 +177,16 @@ export const bazaar = { _genMyHTML(bazaarType: TBazaarType) { let url = "/api/bazaar/getInstalledTheme"; if (bazaarType === "icons") { - url = "/api/bazaar/getInstalledTheme"; + url = "/api/bazaar/getInstalledIcon"; } else if (bazaarType === "widgets") { - url = "/api/bazaar/getInstalledWidgets"; - }else if (bazaarType === "templates") { - url = "/api/bazaar/getInstalledTemplates"; + url = "/api/bazaar/getInstalledWidget"; + } else if (bazaarType === "templates") { + url = "/api/bazaar/getInstalledTemplate"; } fetchPost(url, {}, response => { let html = ""; response.data.packages.forEach((item: IBazaarItem) => { - html += `
+ html += `
${item.name} @@ -191,17 +196,17 @@ export const bazaar = { ${item.downloads}
-
+
- + - - + + - +
@@ -219,7 +224,7 @@ export const bazaar = { downloaded: [] as IBazaarItem[], }, renderReadme(cardElement: HTMLElement, bazaarType: TBazaarType) { - const isDownloaded = cardElement.getAttribute("data-type") === "downloaded"; + const isDownloaded = cardElement.getAttribute("data-downloaded") === "true"; const repoURL = cardElement.querySelector(".b3-card__actions").getAttribute("data-url"); let data: IBazaarItem; (isDownloaded ? bazaar.data.downloaded : bazaar.data[bazaarType]).find((item: IBazaarItem) => { @@ -262,7 +267,7 @@ export const bazaar = {
${window.siyuan.languages.pkgSize}
${data.hSize}
-
+
@@ -312,22 +317,28 @@ export const bazaar = { readmeElement.style.right = "0"; }, bindEvent() { - fetchPost("/api/bazaar/getBazaarTheme", {}, response => { - bazaar.onBazaar(response, "themes", false); - bazaar.data.themes = response.data.packages; - }); + this._genMyHTML("themes"); bazaar.element.addEventListener("click", (event) => { let target = event.target as HTMLElement; while (target && !target.isEqualNode(bazaar.element)) { const type = target.getAttribute("data-type"); - if (type === "myTheme" || type === "myTemplate" || type === "myIcon" || type === "myWidget") { - target.parentElement.childNodes.forEach((item: HTMLElement) => { - if (item.nodeType !== 3 && item.classList.contains("b3-button")) { - item.classList.add("b3-button--outline"); - } - }) - target.classList.remove("b3-button--outline"); - this._genMyHTML(type.replace("my", "").toLowerCase() + "s" as TBazaarType); + if (type === "open") { + /// #if !BROWSER + shell.openPath(path.join(window.siyuan.config.system.confDir, "appearance", "themes", target.parentElement.getAttribute("data-name"))); + /// #endif + event.preventDefault(); + event.stopPropagation(); + break; + } else if (type === "myTheme" || type === "myTemplate" || type === "myIcon" || type === "myWidget") { + if (target.classList.contains("b3-button--outline")) { + target.parentElement.childNodes.forEach((item: HTMLElement) => { + if (item.nodeType !== 3 && item.classList.contains("b3-button")) { + item.classList.add("b3-button--outline"); + } + }) + target.classList.remove("b3-button--outline"); + this._genMyHTML(type.replace("my", "").toLowerCase() + "s" as TBazaarType); + } event.preventDefault(); event.stopPropagation(); break; @@ -389,7 +400,11 @@ export const bazaar = { update: true, }, response => { // 更新主题后不需要对该主题进行切换 https://github.com/siyuan-note/siyuan/issues/4966 - bazaar.onBazaar(response, bazaarType, ["icons"].includes(bazaarType)); + if (cardElement && cardElement.getAttribute("data-downloaded") === "true") { + this._genMyHTML(bazaarType); + } else { + bazaar.onBazaar(response, bazaarType, ["icons"].includes(bazaarType)); + } // https://github.com/siyuan-note/siyuan/issues/5411 if (bazaarType === "themes" && ( (window.siyuan.config.appearance.mode === 0 && window.siyuan.config.appearance.themeLight === name) || @@ -431,7 +446,7 @@ export const bazaar = { fetchPost(url, { packageName }, response => { - if (cardElement && cardElement.getAttribute("data-type") === "downloaded") { + if (cardElement && cardElement.getAttribute("data-downloaded") === "true") { this._genMyHTML(bazaarType); } else { bazaar.onBazaar(response, bazaarType, ["themes", "icons"].includes(bazaarType)); @@ -527,8 +542,11 @@ export const bazaar = { bazaar.onBazaar(response, "widgets", false); bazaar.data.widgets = response.data.packages; }); - } else if (type === "downloaded") { - this._genMyHTML("themes"); + } else if (type === "theme") { + fetchPost("/api/bazaar/getBazaarTheme", {}, response => { + bazaar.onBazaar(response, "themes", false); + bazaar.data.themes = response.data.packages; + }); } item.setAttribute("data-init", "true"); }