mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 17:10:12 +01:00
This commit is contained in:
parent
585e11b329
commit
1456f34cba
3 changed files with 44 additions and 5 deletions
|
|
@ -32,6 +32,11 @@
|
||||||
background-color: var(--b3-theme-primary-lightest)
|
background-color: var(--b3-theme-primary-lightest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&--disabled {
|
||||||
|
opacity: .68;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
&__img {
|
&__img {
|
||||||
margin: 16px 0 16px 16px;
|
margin: 16px 0 16px 16px;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import {Plugin} from "../plugin";
|
||||||
import {App} from "../index";
|
import {App} from "../index";
|
||||||
import {escapeAttr} from "../util/escape";
|
import {escapeAttr} from "../util/escape";
|
||||||
import {uninstall} from "../plugin/uninstall";
|
import {uninstall} from "../plugin/uninstall";
|
||||||
import {loadPlugin} from "../plugin/loader";
|
import {afterLoadPlugin, loadPlugin, loadPlugins} from "../plugin/loader";
|
||||||
|
|
||||||
export const bazaar = {
|
export const bazaar = {
|
||||||
element: undefined as Element,
|
element: undefined as Element,
|
||||||
|
|
@ -307,7 +307,7 @@ export const bazaar = {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
html += `<div data-obj='${JSON.stringify(dataObj)}' class="b3-card${item.current ? " b3-card--current" : ""}">
|
html += `<div data-obj='${JSON.stringify(dataObj)}' class="b3-card${item.current ? " b3-card--current" : ""}${window.siyuan.config.bazaar.petalDisabled ? " b3-card--disabled" : ""}">
|
||||||
<div class="b3-card__img"><img src="${item.iconURL}" onerror="this.src='${item.previewURLThumb}'"/></div>
|
<div class="b3-card__img"><img src="${item.iconURL}" onerror="this.src='${item.previewURLThumb}'"/></div>
|
||||||
<div class="fn__flex-1 fn__flex-column">
|
<div class="fn__flex-1 fn__flex-column">
|
||||||
<div class="b3-card__info b3-card__info--left fn__flex-1">
|
<div class="b3-card__info b3-card__info--left fn__flex-1">
|
||||||
|
|
@ -340,6 +340,12 @@ export const bazaar = {
|
||||||
</div>`;
|
</div>`;
|
||||||
});
|
});
|
||||||
bazaar._data.downloaded = response.data.packages;
|
bazaar._data.downloaded = response.data.packages;
|
||||||
|
if (bazaarType === "plugins") {
|
||||||
|
html = `<div class="fn__flex">
|
||||||
|
<div class="fn__flex-1"></div>
|
||||||
|
<input ${window.siyuan.config.bazaar.petalDisabled ? "" : " checked"} data-type="plugins-enable" type="checkbox" class="b3-switch" style="margin: 8px 32px">
|
||||||
|
</div>${html}`;
|
||||||
|
}
|
||||||
contentElement.innerHTML = html ? html : `<div class="fn__hr"></div><ul class="b3-list b3-list--background"><li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li></ul>`;
|
contentElement.innerHTML = html ? html : `<div class="fn__hr"></div><ul class="b3-list b3-list--background"><li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li></ul>`;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
@ -478,7 +484,10 @@ export const bazaar = {
|
||||||
bindEvent(app: App) {
|
bindEvent(app: App) {
|
||||||
if (!window.siyuan.config.bazaar.trust) {
|
if (!window.siyuan.config.bazaar.trust) {
|
||||||
bazaar.element.querySelector("button").addEventListener("click", () => {
|
bazaar.element.querySelector("button").addEventListener("click", () => {
|
||||||
fetchPost("/api/setting/setBazaar", {trust: true}, () => {
|
fetchPost("/api/setting/setBazaar", {
|
||||||
|
trust: true,
|
||||||
|
petalDisabled: window.siyuan.config.bazaar.petalDisabled
|
||||||
|
}, () => {
|
||||||
window.siyuan.config.bazaar.trust = true;
|
window.siyuan.config.bazaar.trust = true;
|
||||||
bazaar.element.innerHTML = bazaar.genHTML();
|
bazaar.element.innerHTML = bazaar.genHTML();
|
||||||
bazaar.bindEvent(app);
|
bazaar.bindEvent(app);
|
||||||
|
|
@ -511,9 +520,8 @@ export const bazaar = {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
} else if (["myTheme", "myTemplate", "myIcon", "myWidget", "myPlugin"].includes(type)) {
|
} else if (["myTheme", "myTemplate", "myIcon", "myWidget", "myPlugin"].includes(type)) {
|
||||||
const contentElement = bazaar.element.querySelector("#configBazaarDownloaded");
|
|
||||||
if (target.classList.contains("b3-button--outline") &&
|
if (target.classList.contains("b3-button--outline") &&
|
||||||
!contentElement.getAttribute("data-loading")) {
|
!bazaar.element.querySelector("#configBazaarDownloaded").getAttribute("data-loading")) {
|
||||||
target.parentElement.childNodes.forEach((item: HTMLElement) => {
|
target.parentElement.childNodes.forEach((item: HTMLElement) => {
|
||||||
if (item.nodeType !== 3 && item.classList.contains("b3-button")) {
|
if (item.nodeType !== 3 && item.classList.contains("b3-button")) {
|
||||||
item.classList.add("b3-button--outline");
|
item.classList.add("b3-button--outline");
|
||||||
|
|
@ -716,6 +724,31 @@ export const bazaar = {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
|
} else if (type === "plugins-enable") {
|
||||||
|
if (!target.getAttribute("disabled")) {
|
||||||
|
target.setAttribute("disabled", "disabled");
|
||||||
|
window.siyuan.config.bazaar.petalDisabled = !(target as HTMLInputElement).checked;
|
||||||
|
fetchPost("/api/setting/setBazaar", window.siyuan.config.bazaar, (response) => {
|
||||||
|
target.removeAttribute("disabled");
|
||||||
|
if (window.siyuan.config.bazaar.petalDisabled) {
|
||||||
|
bazaar.element.querySelectorAll("#configBazaarDownloaded .b3-card").forEach(item => {
|
||||||
|
item.classList.add("b3-card--disabled");
|
||||||
|
uninstall(app, JSON.parse(item.getAttribute("data-obj")).name);
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
bazaar.element.querySelectorAll("#configBazaarDownloaded .b3-card").forEach(item => {
|
||||||
|
item.classList.remove("b3-card--disabled");
|
||||||
|
})
|
||||||
|
loadPlugins(app).then(() => {
|
||||||
|
app.plugins.forEach(item => {
|
||||||
|
afterLoadPlugin(item);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
event.stopPropagation();
|
||||||
|
break;
|
||||||
} else if (type === "plugin-enable") {
|
} else if (type === "plugin-enable") {
|
||||||
if (!target.getAttribute("disabled")) {
|
if (!target.getAttribute("disabled")) {
|
||||||
target.setAttribute("disabled", "disabled");
|
target.setAttribute("disabled", "disabled");
|
||||||
|
|
|
||||||
1
app/src/types/index.d.ts
vendored
1
app/src/types/index.d.ts
vendored
|
|
@ -497,6 +497,7 @@ interface IConfig {
|
||||||
cloudRegion: number
|
cloudRegion: number
|
||||||
bazaar: {
|
bazaar: {
|
||||||
trust: boolean
|
trust: boolean
|
||||||
|
petalDisabled: boolean
|
||||||
}
|
}
|
||||||
repo: {
|
repo: {
|
||||||
key: string
|
key: string
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue