An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Support the marketplace on mobile https://github.com/siyuan-note/siyuan/issues/17151
Daniel1fc77325f757
diff --git a/app/guide/20210808180117-6v0mkxr/20240113110040-7sgw8kl.sy b/app/guide/20210808180117-6v0mkxr/20240113110040-7sgw8kl.syindex 27469c17ca..b1602ea6b3 100644--- a/app/guide/20210808180117-6v0mkxr/20240113110040-7sgw8kl.sy+++ b/app/guide/20210808180117-6v0mkxr/20240113110040-7sgw8kl.sy@@ -7,7 +7,7 @@"id": "20240113110040-7sgw8kl","title": "Mobile App","type": "doc",- "updated": "20260803171606"+ "updated": "20260819122705"},"Children": [{@@ -347,7 +347,7 @@"HeadingLevel": 2,"Properties": {"id": "20240113110114-ekanw3f",- "updated": "20260803165036"+ "updated": "20260819122705"},"Children": [{@@ -361,12 +361,12 @@"Type": "NodeParagraph","Properties": {"id": "20240113110114-54bc1f8",- "updated": "20240113110224"+ "updated": "20260819122705"},"Children": [{"Type": "NodeText",- "Data": "Due to App Store review reasons, the marketplace cannot be provided directly on the App at present."+ "Data": "Some app store versions may not provide the marketplace in the app due to review requirements. Themes are not available in the initial in-app mobile marketplace release."}]},@@ -375,12 +375,12 @@"Type": "NodeParagraph","Properties": {"id": "20240113110114-5cymxj6",- "updated": "20260803165036"+ "updated": "20260819114702"},"Children": [{"Type": "NodeText",- "Data": "To use the marketplace, enable "+ "Data": "If your version is restricted, you can still use the marketplace: enable "},{"Type": "NodeTextMark",@@ -389,7 +389,7 @@},{"Type": "NodeText",- "Data": " - "+ "Data": " - "},{"Type": "NodeTextMark",@@ -398,7 +398,7 @@},{"Type": "NodeText",- "Data": " and access the configuration on your desktop browser."+ "Data": ", then access SiYuan from a desktop browser."}]},@@ -1373,4 +1373,4 @@}}]-}\ No newline at end of file+}diff --git a/app/guide/20210808180117-czj9bvb/20240113102857-c63dmo5.sy b/app/guide/20210808180117-czj9bvb/20240113102857-c63dmo5.syindex 23334f651f..a692a887bd 100644--- a/app/guide/20210808180117-czj9bvb/20240113102857-c63dmo5.sy+++ b/app/guide/20210808180117-czj9bvb/20240113102857-c63dmo5.sy@@ -7,7 +7,7 @@"id": "20240113102857-c63dmo5","title": "移动端 App","type": "doc",- "updated": "20260803171606"+ "updated": "20260819122705"},"Children": [{@@ -347,7 +347,7 @@"HeadingLevel": 2,"Properties": {"id": "20240113104101-rz1z8en",- "updated": "20260803171606"+ "updated": "20260819122705"},"Children": [{@@ -361,12 +361,12 @@"Type": "NodeParagraph","Properties": {"id": "20240113104141-5jvccmj",- "updated": "20240113104506"+ "updated": "20260819122705"},"Children": [{"Type": "NodeText",- "Data": "因为应用商店审核原因,目前无法直接在 App 上提供集市。"+ "Data": "部分应用商店版本可能因审核要求不在 App 内提供集市;App 内移动端集市首版暂不提供主题。"}]},@@ -375,12 +375,12 @@"Type": "NodeParagraph","Properties": {"id": "20240113104506-ko5m727",- "updated": "20260803171606"+ "updated": "20260819114702"},"Children": [{"Type": "NodeText",- "Data": "如需使用集市,请启用 "+ "Data": "受限版本仍可使用集市,请启用 "},{"Type": "NodeTextMark",@@ -389,7 +389,7 @@},{"Type": "NodeText",- "Data": " - "+ "Data": " - "},{"Type": "NodeTextMark",@@ -398,7 +398,7 @@},{"Type": "NodeText",- "Data": ",然后在桌面端浏览器上访问配置。"+ "Data": ",然后使用桌面端浏览器访问思源。"}]},@@ -1376,4 +1376,4 @@}}]-}\ No newline at end of file+}diff --git a/app/guide/20211226090932-5lcq56f/20240113110500-dz2ae4n.sy b/app/guide/20211226090932-5lcq56f/20240113110500-dz2ae4n.syindex 20582761bc..229923634b 100644--- a/app/guide/20211226090932-5lcq56f/20240113110500-dz2ae4n.sy+++ b/app/guide/20211226090932-5lcq56f/20240113110500-dz2ae4n.sy@@ -7,7 +7,7 @@"id": "20240113110500-dz2ae4n","title": "行動端 App","type": "doc",- "updated": "20260803171606"+ "updated": "20260819122705"},"Children": [{@@ -347,7 +347,7 @@"HeadingLevel": 2,"Properties": {"id": "20240113110513-f0ouee1",- "updated": "20260803171606"+ "updated": "20260819122705"},"Children": [{@@ -361,12 +361,12 @@"Type": "NodeParagraph","Properties": {"id": "20240113110513-1zlx78j",- "updated": "20240113110513"+ "updated": "20260819122705"},"Children": [{"Type": "NodeText",- "Data": "因為應用程式商店審核原因,目前無法直接在 App 上提供市集。"+ "Data": "部分應用程式商店版本可能因審核要求不在 App 內提供集市;App 內行動端集市首版暫不提供主題。"}]},@@ -375,12 +375,12 @@"Type": "NodeParagraph","Properties": {"id": "20240113110513-bta55b6",- "updated": "20260803171606"+ "updated": "20260819114702"},"Children": [{"Type": "NodeText",- "Data": "如需使用集市,請啟用 "+ "Data": "受限版本仍可使用集市,請啟用 "},{"Type": "NodeTextMark",@@ -389,7 +389,7 @@},{"Type": "NodeText",- "Data": " - "+ "Data": " - "},{"Type": "NodeTextMark",@@ -398,7 +398,7 @@},{"Type": "NodeText",- "Data": ",然後在桌面端瀏覽器上存取配置。"+ "Data": ",然後使用桌面端瀏覽器存取思源。"}]},@@ -1377,4 +1377,4 @@}}]-}\ No newline at end of file+}diff --git a/app/guide/20240530133126-axarxgx/20240530101000-e6z5okf.sy b/app/guide/20240530133126-axarxgx/20240530101000-e6z5okf.syindex f99adcee04..4288515581 100644--- a/app/guide/20240530133126-axarxgx/20240530101000-e6z5okf.sy+++ b/app/guide/20240530133126-axarxgx/20240530101000-e6z5okf.sy@@ -8,7 +8,7 @@"id": "20240530101000-e6z5okf","title": "モバイルアプリ","type": "doc",- "updated": "20260803170332"+ "updated": "20260819132654"},"Children": [{@@ -48,7 +48,7 @@"Properties": {"ID": "20240530101000-2lg2mb6","id": "20240530101000-tylg3qg",- "updated": "20260803170332"+ "updated": "20260819132654"},"Children": [{@@ -63,12 +63,12 @@"Properties": {"ID": "20240530101000-stdxnih","id": "20240530101000-vma8ggh",- "updated": "20240530101000"+ "updated": "20260819132654"},"Children": [{"Type": "NodeText",- "Data": "アプリストアの審査の都合上、現在マーケットプレイスをアプリ上で直接提供することはできません。"+ "Data": "一部のアプリストア版では、審査要件によりアプリ内でマーケットプレイスを提供しない場合があります。アプリ内モバイルマーケットプレイスの初期リリースでは、テーマは利用できません。"}]},@@ -78,21 +78,12 @@"Properties": {"ID": "20240530101000-4ppspg1","id": "20240530101000-2ydz6oj",- "updated": "20260803170332"+ "updated": "20260819132654"},"Children": [{"Type": "NodeText",- "Data": "マーケットプレイスを利用するには、"- },- {- "Type": "NodeTextMark",- "TextMarkType": "kbd",- "TextMarkTextContent": "設定"- },- {- "Type": "NodeText",- "Data": " - "+ "Data": "制限されているバージョンでもマーケットプレイスを利用するには、"},{"Type": "NodeTextMark",@@ -101,7 +92,7 @@},{"Type": "NodeText",- "Data": " - "+ "Data": " - "},{"Type": "NodeTextMark",@@ -110,7 +101,7 @@},{"Type": "NodeText",- "Data": " を有効にして、デスクトップブラウザから設定にアクセスしてください。"+ "Data": " を有効にして、デスクトップブラウザから SiYuan にアクセスしてください。"}]},@@ -1086,4 +1077,4 @@}}]-}\ No newline at end of file+}diff --git a/app/src/assets/scss/main/_mobile.scss b/app/src/assets/scss/main/_mobile.scssindex 9c01cef028..6e9b925bb8 100644--- a/app/src/assets/scss/main/_mobile.scss+++ b/app/src/assets/scss/main/_mobile.scss@@ -366,6 +366,11 @@flex: 1;height: auto;min-height: 0;++ &--bazaar {+ overflow: hidden;+ padding: 0;+ }}}@@ -378,6 +383,267 @@background-color: var(--b3-theme-surface);padding: 8px 16px max(16px, env(safe-area-inset-bottom));}++ > .config-bazaar,+ > .config-bazaar__trust {+ height: 100%;+ min-height: 0;+ }++ > .config-bazaar__trust {+ box-sizing: border-box;+ margin: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)) !important;+ overflow-y: auto;+ padding: 8px 0 max(16px, env(safe-area-inset-bottom));+ -webkit-overflow-scrolling: touch;++ > .fn__flex-1 {+ display: none;+ }+ }++ .config-bazaar {+ min-width: 0;+ overflow: hidden;++ &__main {+ min-height: 0;++ > .layout-tab-bar {+ flex-shrink: 0;+ overflow-x: auto;+ overscroll-behavior-x: contain;+ padding-left: max(12px, env(safe-area-inset-left));+ padding-right: max(12px, env(safe-area-inset-right));+ scroll-padding-left: max(12px, env(safe-area-inset-left));+ scroll-padding-right: max(12px, env(safe-area-inset-right));+ scroll-snap-type: x proximity;+ -webkit-overflow-scrolling: touch;++ .item {+ flex: 0 0 auto;+ scroll-snap-align: start;++ > .fn__flex-1 {+ display: none;+ }+ }+ }++ > .fn__flex-1 {+ min-height: 0;+ overflow: hidden;+ }+ }++ &__panel {+ overscroll-behavior: contain;+ padding-bottom: max(16px, env(safe-area-inset-bottom));+ -webkit-overflow-scrolling: touch;+ }++ &__title {+ padding: 12px max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left));+ }++ &__title--downloaded {+ display: block;++ .config-bazaar__tabs {+ flex-wrap: nowrap;+ overflow-x: auto;+ overscroll-behavior-x: contain;+ padding: 8px 0 12px;+ -webkit-overflow-scrolling: touch;++ > .b3-button {+ flex: 0 0 auto;+ }+ }++ .config-bazaar__tools {+ display: grid;+ gap: 8px;+ grid-template-columns: minmax(0, 1fr) auto;+ width: 100%;+ }++ .config-bazaar__sort {+ grid-column: 1 / -1;+ min-width: 0;++ .b3-select {+ min-width: 0;+ width: 100%;+ }+ }++ .config-bazaar__filter {+ box-sizing: border-box;+ grid-column: 1;+ grid-row: 2;+ min-width: 0;+ width: 100%;+ }++ .config-bazaar__actions {+ flex-wrap: nowrap;+ gap: 4px;+ grid-column: 2;+ grid-row: 2;+ margin-left: 0;+ min-width: 0;++ > .counter {+ margin-left: 0;+ order: -1;+ }+ }+ }++ &__panel:not([data-type="downloaded"]) > .config-bazaar__title {+ align-items: center;+ gap: 8px;++ > .fn__space,+ > .fn__flex-1 {+ display: none;+ }++ > .b3-select {+ flex: 1 1 132px;+ min-width: 0;+ }++ > .b3-text-field {+ box-sizing: border-box;+ flex: 1 1 0;+ min-width: 0;+ order: 2;+ }++ > .counter {+ flex-shrink: 0;+ margin-left: auto;+ order: 2;+ }+ }++ &__content {+ margin: 1px max(12px, env(safe-area-inset-right)) 1px max(12px, env(safe-area-inset-left));++ .b3-card {+ min-width: 0;++ &__img {+ margin: 12px 0 12px 12px;++ img,+ span {+ height: 56px;+ width: 56px;+ }+ }++ &__info {+ min-width: 0;+ padding: 12px 8px 0;++ &--left {+ padding-bottom: 12px;+ }+ }++ &__actions--right {+ flex: 0 1 auto;+ flex-wrap: wrap;+ justify-content: flex-end;+ max-width: 120px;+ padding-right: 8px;+ row-gap: 4px;+ }+ }+ }++ &__readme {+ border-radius: 0;+ flex-direction: column;+ overflow-y: auto;+ overscroll-behavior: contain;+ padding: 0;+ -webkit-overflow-scrolling: touch;++ .item {+ &__header {+ background-color: var(--b3-theme-background);+ box-sizing: border-box;+ flex-shrink: 0;+ height: auto;+ margin: 0;+ min-height: 44px;+ padding: max(8px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));+ position: sticky;+ top: 0;+ width: 100%;+ z-index: 2;+ }++ &__side {+ box-sizing: border-box;+ flex: none;+ height: auto;+ overflow: visible;+ padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));+ width: 100%;++ > .fn__flex-1 {+ flex: none;+ padding: 0;+ }+ }++ &__img {+ margin-top: 16px;+ }++ &__actions {+ padding: 8px 0 16px;+ }++ &__main {+ box-sizing: border-box;+ flex: none;+ margin-left: 0;+ overflow: visible;+ padding: 0 max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));+ width: 100%;+ }++ &__preview {+ height: min(50vw, 180px);+ margin-bottom: 16px;++ &.item__preview--fullscreen {+ border-radius: 0;+ height: 100%;+ inset: 0;+ margin: 0;+ position: fixed;+ width: 100%;+ z-index: 8;+ }+ }++ &__readme {+ margin-top: 16px;++ table {+ overflow-x: auto;+ }+ }+ }+ }+ }}.config-group {diff --git a/app/src/config/bazaar.ts b/app/src/config/bazaar.tsindex 65ffa63cc3..12042d8ac2 100644--- a/app/src/config/bazaar.ts+++ b/app/src/config/bazaar.ts@@ -2,7 +2,9 @@ import {showMessage} from "../dialog/message";import {fetchPost} from "../util/fetch";import {confirmDialog} from "../dialog/confirmDialog";import {highlightRender} from "../protyle/render/highlightRender";+/// #if !MOBILEimport {saveLayout} from "../layout/util";+/// #endifimport {Constants} from "../constants";/// #if !BROWSERimport * as path from "path";@@ -45,29 +47,26 @@ import {sortBazaarPackagesByRating,} from "../util/bazaarPackage";import {Dialog} from "../dialog";+import {isBazaarPackageTypeAvailable} from "../util/bazaarAvailability";-/** 集市 Tab 侧栏 / 全局搜索索引文案 */-export const collectBazaarTabSearchStrings = (): string[] => [- window.siyuan.languages.bazaar,- window.siyuan.languages.downloaded,- window.siyuan.languages.update,- window.siyuan.languages.plugin,- window.siyuan.languages.theme,- window.siyuan.languages.icon,- window.siyuan.languages.template,- window.siyuan.languages.widget,-];+interface IBazaarMountSnapshot {+ element: HTMLElement;+ generation: number;+ requestID?: number;+}/** 集市 Tab 挂载(面板页,不走注册表渲染) */export const mountBazaarTab = (root: HTMLElement, keywords?: string, app?: App) => {- if (root.innerHTML === "") {- bazaar.element = root;+ if (isMobile()) {+ root.classList.add("config--mobile");+ }+ const isEmpty = root.innerHTML === "";+ bazaar._activateMount(root, isEmpty);+ if (isEmpty) {root.innerHTML = bazaar.genHTML();if (app) {bazaar.bindEvent(app);}- } else {- bazaar.element = root;}if (bazaar._syncRatingUser()) {bazaar._refreshVisibleRatingUI();@@ -76,7 +75,8 @@ export const mountBazaarTab = (root: HTMLElement, keywords?: string, app?: App)switchSettingPanelSubTab(root, keywords, [{type: "downloaded", label: window.siyuan.languages.downloaded},{type: "plugin", label: window.siyuan.languages.plugin},- {type: "theme", label: window.siyuan.languages.theme},+ ...(isBazaarPackageTypeAvailable("themes") ?+ [{type: "theme", label: window.siyuan.languages.theme}] : []),{type: "icon", label: window.siyuan.languages.icon},{type: "template", label: window.siyuan.languages.template},{type: "widget", label: window.siyuan.languages.widget},@@ -84,6 +84,13 @@ export const mountBazaarTab = (root: HTMLElement, keywords?: string, app?: App)}};+/** 释放集市 Tab 挂载状态 */+export const unmountBazaarTab = (root: HTMLElement) => {+ if (bazaar.element === root) {+ bazaar._invalidateMount();+ }+};+/*** 渲染集市 README*/@@ -93,15 +100,56 @@ export const renderReadme = (bazaarType: TBazaarType, from: "downloaded" | "upda};export const bazaar = {- element: undefined as Element,+ element: undefined as HTMLElement,+ _mountGeneration: 0,+ _bazaarRequestIDs: new Map<TBazaarType, number>(),_updateState: "idle" as "idle" | "loading" | "loaded" | "error",_updateRequestID: 0,_localPackageUploading: false,_ratingUserID: "",_ratingUserChangeHandler: undefined as (() => void) | undefined,+ _activateMount(element: HTMLElement, force = false) {+ if (!force && this.element === element) {+ return;+ }+ this._invalidateMount();+ this.element = element;+ },+ _invalidateMount() {+ this._mountGeneration++;+ this._updateRequestID++;+ if (this._ratingUserChangeHandler) {+ window.removeEventListener("siyuan-login-success", this._ratingUserChangeHandler);+ this._ratingUserChangeHandler = undefined;+ }+ },+ _captureMount(): IBazaarMountSnapshot {+ return {+ element: this.element,+ generation: this._mountGeneration,+ };+ },+ _beginBazaarRequest(bazaarType: TBazaarType, mount = this._captureMount()): IBazaarMountSnapshot {+ if (!this._isMountCurrent(mount)) {+ return mount;+ }+ const requestID = (this._bazaarRequestIDs.get(bazaarType) || 0) + 1;+ this._bazaarRequestIDs.set(bazaarType, requestID);+ return {+ ...mount,+ requestID,+ };+ },+ _isMountCurrent(mount: IBazaarMountSnapshot) {+ return mount.element === this.element && mount.generation === this._mountGeneration;+ },+ _isBazaarRequestCurrent(bazaarType: TBazaarType, mount: IBazaarMountSnapshot) {+ return this._isMountCurrent(mount) && (mount.requestID === undefined ||+ this._bazaarRequestIDs.get(bazaarType) === mount.requestID);+ },genHTML() {if (!window.siyuan.config.bazaar.trust) {- return `<div class="fn__flex-column" style="margin: 0 48px;">+ return `<div class="config-bazaar__trust fn__flex-column" style="margin: 0 48px;"><div class="fn__flex-1"></div><div class="b3-label"><div>${window.siyuan.languages.bazaarTrust}</div>@@ -139,7 +187,7 @@ export const bazaar = {<div class="b3-label b3-label--noborder"><div>${window.siyuan.languages.bazaarTrust1}</div><div class="fn__hr--b"></div>- <diiv>${window.siyuan.languages.bazaarTrust2}</diiv>+ <div>${window.siyuan.languages.bazaarTrust2}</div></div><div class="ft__center b3-label b3-label--noborder"><button class="b3-button fn__size200">${window.siyuan.languages.trust}</button>@@ -148,6 +196,8 @@ export const bazaar = {</div>`;}const localSort = window.siyuan.storage[Constants.LOCAL_BAZAAR];+ const themeAvailable = isBazaarPackageTypeAvailable("themes");+ const localPackageAvailable = getFrontend() !== "mobile";const loadingHTML = `<div style="height: ${bazaar.element.clientHeight - 160}px;display: flex;align-items: center;justify-content: center;"><img src="/stage/loading-pure.svg"></div>`;return `<div class="config-bazaar fn__flex-column" style="height: 100%"><div class="config-bazaar__main fn__flex-column fn__flex-1">@@ -158,7 +208,7 @@ export const bazaar = {<div class="layout-tab-bar fn__flex"><div data-type="downloaded" class="item item--full item--focus"><span class="fn__flex-1"></span><span class="item__text">${window.siyuan.languages.downloaded}</span><span class="fn__flex-1"></span></div><div data-type="plugin" class="item item--full"><span class="fn__flex-1"></span><span class="item__text">${window.siyuan.languages.plugin}</span><span class="fn__flex-1"></span></div>- <div data-type="theme" class="item item--full"><span class="fn__flex-1"></span><span class="item__text">${window.siyuan.languages.theme}</span><span class="fn__flex-1"></span></div>+ <div data-type="theme" class="item item--full${themeAvailable ? "" : " fn__none"}"><span class="fn__flex-1"></span><span class="item__text">${window.siyuan.languages.theme}</span><span class="fn__flex-1"></span></div><div data-type="icon" class="item item--full"><span class="fn__flex-1"></span><span class="item__text">${window.siyuan.languages.icon}</span><span class="fn__flex-1"></span></div><div data-type="template" class="item item--full"><span class="fn__flex-1"></span><span class="item__text">${window.siyuan.languages.template}</span><span class="fn__flex-1"></span></div><div data-type="widget" class="item item--full"><span class="fn__flex-1"></span><span class="item__text">${window.siyuan.languages.widget}</span><span class="fn__flex-1"></span></div>@@ -169,7 +219,7 @@ export const bazaar = {<div class="fn__flex config-bazaar__tabs"><button data-type="myUpdate" class="b3-button b3-button--outline config-bazaar__update-tab">${window.siyuan.languages.update}<span data-type="update-tab-count" class="config-bazaar__update-count fn__none"></span></button><button data-type="myPlugin" class="b3-button">${window.siyuan.languages.plugin}</button>- <button data-type="myTheme" class="b3-button b3-button--outline">${window.siyuan.languages.theme}</button>+ <button data-type="myTheme" class="b3-button b3-button--outline${themeAvailable ? "" : " fn__none"}">${window.siyuan.languages.theme}</button><button data-type="myIcon" class="b3-button b3-button--outline">${window.siyuan.languages.icon}</button><button data-type="myTemplate" class="b3-button b3-button--outline">${window.siyuan.languages.template}</button><button data-type="myWidget" class="b3-button b3-button--outline">${window.siyuan.languages.widget}</button>@@ -189,7 +239,7 @@ export const bazaar = {</div><input data-type="downloaded-filter" class="b3-text-field config-bazaar__filter" placeholder="${window.siyuan.languages.enterKey} ${window.siyuan.languages.search}"><div class="fn__flex config-bazaar__actions">- <label class="block__icon block__icon--show config-bazaar__local-package ariaLabel" data-type="install-local-package" data-position="north" aria-label="${window.siyuan.languages.installLocalBazaarPackage}">+ <label class="block__icon block__icon--show config-bazaar__local-package ariaLabel${localPackageAvailable ? "" : " fn__none"}" data-type="install-local-package" data-position="north" aria-label="${window.siyuan.languages.installLocalBazaarPackage}"><svg class="b3-button__icon"><use xlink:href="#iconUpload"></use></svg><input class="b3-form__upload" data-type="local-package-file" type="file" accept=".zip,application/zip"></label>@@ -394,11 +444,15 @@ export const bazaar = {bazaar._data.details.set(bazaar._getDetailKey(bazaarType, packageName), detail);},_fetchPackageDetail(bazaarType: TBazaarType, packageName: string, callback: (detail: IBazaarPackageDetail) => void) {+ const mount = bazaar._captureMount();fetchPost("/api/bazaar/getBazaarPackage", {packageType: bazaarType,packageName,frontend: getFrontend(),}, response => {+ if (!bazaar._isMountCurrent(mount)) {+ return;+ }if (response.code !== 0 || !response.data) {callback(bazaar._getPackageDetail(bazaarType, packageName) || {});return;@@ -508,7 +562,11 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}if (bazaar._ratingUserChangeHandler) {window.removeEventListener("siyuan-login-success", bazaar._ratingUserChangeHandler);}+ const mount = bazaar._captureMount();bazaar._ratingUserChangeHandler = () => {+ if (!bazaar._isMountCurrent(mount)) {+ return;+ }bazaar._syncRatingUser();bazaar._refreshVisibleRatingUI();};@@ -719,6 +777,9 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}_getUpdatedItems(): Array<{type: TBazaarType, item: IUpdatedBazaarItem}> {const items: Array<{type: TBazaarType, item: IUpdatedBazaarItem}> = [];(["plugins", "themes", "icons", "templates", "widgets"] as TBazaarType[]).forEach((type) => {+ if (!isBazaarPackageTypeAvailable(type)) {+ return;+ }bazaar._data.update[type].forEach((item) => items.push({type, item}));});return items;@@ -745,11 +806,12 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}this._updateState = "loading";this._syncUpdateTabCounter();const requestID = ++this._updateRequestID;+ const mount = this._captureMount();if (this._isUpdatePanelActive()) {this._renderUpdatePanel();}fetchPost("/api/bazaar/getUpdatedPackage", {frontend: getFrontend()}, (response) => {- if (requestID !== this._updateRequestID || !this.element?.isConnected) {+ if (requestID !== this._updateRequestID || !this._isMountCurrent(mount) || !this.element?.isConnected) {return;}if (response.code !== 0 || !response.data) {@@ -796,7 +858,8 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}}counterElement.classList.remove("fn__none");counterElement.textContent = items.length.toString();- installAllElement?.classList.toggle("fn__none", !items.some(({item}) => !item.available.disallowUpdate));+ installAllElement?.classList.toggle("fn__none", getFrontend() === "mobile" ||+ !items.some(({item}) => !item.available.disallowUpdate));contentElement.innerHTML = items.map(({type, item}) => this._genUpdateItemHTML(item, type)).join("");this._loadUpdatedRatings();},@@ -824,6 +887,9 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}}},_genMyHTML(bazaarType: TBazaarType, app: App, preserveOrder = false) {+ if (!isBazaarPackageTypeAvailable(bazaarType)) {+ return false;+ }const contentElement = bazaar.element.querySelector("#configBazaarDownloaded");const myType = bazaar._type2myType(bazaarType);const typeBtn = contentElement.previousElementSibling.querySelector(`[data-type="${myType}"]`) as HTMLElement;@@ -846,10 +912,14 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}}bazaar._updateDownloadedSortSelect(bazaarType);const initialSortValue = bazaar._getDownloadedSortValue(bazaarType);+ const mount = bazaar._captureMount();fetchPost(installedAPI[bazaarType], {frontend: getFrontend(),keyword: (contentElement.previousElementSibling.querySelector(".b3-text-field") as HTMLInputElement)?.value || "",}, response => {+ if (!bazaar._isMountCurrent(mount)) {+ return;+ }contentElement.removeAttribute("data-loading");const activeBtn = contentElement.previousElementSibling.querySelector('.b3-button[data-type^="my"]:not(.b3-button--outline)') as HTMLElement;if (activeBtn?.getAttribute("data-type") !== myType) {@@ -999,6 +1069,10 @@ type="checkbox">}},_renderReadme(bazaarType: TBazaarType, from: "downloaded" | "updated" | "bazaar", data: IBazaarItem, detail?: IBazaarPackageDetail) {+ if (!isBazaarPackageTypeAvailable(bazaarType)) {+ return;+ }+ const mount = bazaar._captureMount();const readmeElement = bazaar.element.querySelector("#configBazaarReadme") as HTMLElement;const navTitles: Record<TBazaarType, string> = {plugins: window.siyuan.languages.plugin,@@ -1090,11 +1164,12 @@ type="checkbox">${displayData.author ? bazaar._genReadmeMetaRow(window.siyuan.languages.author, `<a href="${escapeAttr(urls.join("/"))}" target="_blank" title="${escapeAttr(urls.join("/"))}">${escapeHtml(displayData.author)}</a>`, true) : ""}${fundingItems.length ? bazaar._genReadmeMetaRow(window.siyuan.languages.bazaarFunding, fundingItems.map((item) => bazaar._genReadmeFundingHTML(item)).join("<br>"), true) : ""}</section>`;- readmeElement.innerHTML = ` <div class="item__side" data-from="${from}" data-name="${escapeAttr(displayData.name)}" data-package-type="${bazaarType}" data-repourl="${escapeAttr(resourceData.repoURL)}" data-progress-id="${escapeAttr(available?.repoURL || resourceData.repoURL)}">- <div class="item__header fn__pointer" data-type="goBack">+ const backHeaderHTML = `<div class="item__header fn__pointer" data-type="goBack"><svg class="b3-list-item__graphic"><use xlink:href="#iconLeft"></use></svg><span class="b3-list-item__text ft__breakword">${navTitles[bazaarType]}</span>- </div>+ </div>`;+ readmeElement.innerHTML = `${isMobile() ? backHeaderHTML : ""}<div class="item__side" data-from="${from}" data-name="${escapeAttr(displayData.name)}" data-package-type="${bazaarType}" data-repourl="${escapeAttr(resourceData.repoURL)}" data-progress-id="${escapeAttr(available?.repoURL || resourceData.repoURL)}">+ ${isMobile() ? "" : backHeaderHTML}<div class="fn__flex-1"><img class="item__img" src="${displayData.iconURL}" loading="lazy" onerror="this.src='/stage/images/icon.png'"><div>@@ -1147,6 +1222,9 @@ type="checkbox">repoHash: displayData.repoHash,packageType: bazaarType}, response => {+ if (!bazaar._isMountCurrent(mount)) {+ return;+ }const sideElement = readmeElement.querySelector(".item__side");if (response.code !== 0 ||sideElement?.getAttribute("data-package-type") !== bazaarType ||@@ -1164,6 +1242,9 @@ type="checkbox">packageType: bazaarType,packageName: installed.name,}, response => {+ if (!bazaar._isMountCurrent(mount)) {+ return;+ }const sideElement = readmeElement.querySelector(".item__side");if (sideElement?.getAttribute("data-package-type") !== bazaarType ||sideElement.getAttribute("data-name") !== installed.name) {@@ -1179,6 +1260,9 @@ type="checkbox">bazaar._loadReadmeRating(bazaarType, displayData.name, from);if (needsPackageDetail) {bazaar._fetchPackageDetail(bazaarType, data.name, (packageDetail) => {+ if (!readmeElement.classList.contains("config__view--show")) {+ return;+ }const sideElement = readmeElement.querySelector(".item__side");if (sideElement?.getAttribute("data-from") !== from ||sideElement.getAttribute("data-package-type") !== bazaarType ||@@ -1306,7 +1390,7 @@ type="checkbox">contentElement.append(fragment);bazaar._data.downloaded = packages;},- _applyPackageRating(bazaarType: TBazaarType, packageName: string, rating?: IBazaarRating) {+ _applyPackageRating(bazaarType: TBazaarType, packageName: string, rating?: IBazaarRating, refreshUI = true) {const key = bazaar._getRatingKey(bazaarType, packageName);if (rating) {bazaar._data.ratings.set(key, rating);@@ -1328,20 +1412,24 @@ type="checkbox">const detail = bazaar._getPackageDetail(bazaarType, packageName);updateItem(detail?.installed);updateItem(detail?.available);- bazaar._refreshRatingUI(bazaarType, packageName);+ if (refreshUI) {+ bazaar._refreshRatingUI(bazaarType, packageName);+ }},_applyPackageRatingResponse(bazaarType: TBazaarType, packageName: string, data: {ratingAvailable?: unknown;rating?: Partial<IBazaarRating> | null;- }) {+ }, refreshUI = true) {const key = bazaar._getRatingKey(bazaarType, packageName);const publicRating = normalizeBazaarPackageRatingResponse(data);if (publicRating.loaded) {bazaar._data.downloadedRatingKeys.add(key);- bazaar._applyPackageRating(bazaarType, packageName, publicRating.rating);+ bazaar._applyPackageRating(bazaarType, packageName, publicRating.rating, refreshUI);} else {bazaar._data.downloadedRatingKeys.delete(key);- bazaar._refreshRatingUI(bazaarType, packageName);+ if (refreshUI) {+ bazaar._refreshRatingUI(bazaarType, packageName);+ }}return publicRating.loaded;},@@ -1414,12 +1502,13 @@ type="checkbox">const key = bazaar._getRatingKey(bazaarType, packageName);return [packageName, getBazaarRatingMutationVersion(bazaar._data.ratingMutationVersions, key)];}));+ const mount = bazaar._captureMount();fetchPost("/api/bazaar/getBazaarPackageRatings", {packageType: bazaarType,packageNames,}, response => {if (response.code !== 0 || bazaar._data.ratingBatchRequestIDs.get(bazaarType) !== requestID ||- !bazaar.element?.isConnected) {+ !bazaar._isMountCurrent(mount) || !bazaar.element?.isConnected) {return;}const ratings = normalizeBazaarPackageRatingsResponse(packageNames, response.data);@@ -1437,6 +1526,9 @@ type="checkbox">},_loadUpdatedRatings() {(["plugins", "themes", "icons", "templates", "widgets"] as TBazaarType[]).forEach((bazaarType) => {+ if (!isBazaarPackageTypeAvailable(bazaarType)) {+ return;+ }const items = bazaar._data.update[bazaarType];if (items.length && !items.every((item) => bazaar._data.downloadedRatingKeys.has(bazaar._getRatingKey(bazaarType, item.installed.name)))) {@@ -1450,6 +1542,7 @@ type="checkbox">const key = bazaar._getRatingKey(bazaarType, packageName);const loadingKey = `${requestedUserID}|${key}`;bazaar._data.userRatingLoadingKeys.add(loadingKey);+ const mount = bazaar._captureMount();let handled = false;fetchPost("/api/bazaar/getBazaarPackageRating", {packageType: bazaarType,@@ -1457,7 +1550,7 @@ type="checkbox">}, response => {handled = true;bazaar._syncRatingUser();- if (requestedUserID !== bazaar._ratingUserID) {+ if (requestedUserID !== bazaar._ratingUserID || !bazaar._isMountCurrent(mount)) {return;}if (response.code !== 0 || !response.data) {@@ -1497,6 +1590,7 @@ type="checkbox">},_submitPackageRating(bazaarType: TBazaarType, packageName: string, rating: number, callback: (success: boolean) => void) {bazaar._syncRatingUser();+ const mount = bazaar._captureMount();const removing = rating === 0;const failureMessage = removing ? window.siyuan.languages.bazaarRemoveRatingFailed :window.siyuan.languages.bazaarRatingFailed;@@ -1546,9 +1640,10 @@ type="checkbox">bazaar._data.userRatings.set(key, normalizeBazaarUserRating(userRating) ?? rating);bazaar._data.userRatingKeys.add(key);beginBazaarRatingRequest(bazaar._data.ratingMutationVersions, key);- bazaar._applyPackageRatingResponse(bazaarType, packageName, response.data);+ const refreshUI = bazaar._isMountCurrent(mount);+ bazaar._applyPackageRatingResponse(bazaarType, packageName, response.data, refreshUI);const sortValue = window.siyuan.storage[Constants.LOCAL_BAZAAR][bazaar._type2tabType(bazaarType)];- if (["4", "5"].includes(sortValue)) {+ if (refreshUI && ["4", "5"].includes(sortValue)) {bazaar._renderBazaarCards(bazaar.element.querySelector({plugins: "#configBazaarPlugin",@@ -1752,6 +1847,9 @@ type="checkbox">});},_reloadBazaarType(bazaarType: TBazaarType) {+ if (!isBazaarPackageTypeAvailable(bazaarType)) {+ return;+ }const bazaarAPI: Record<TBazaarType, string> = {plugins: "/api/bazaar/getBazaarPlugin",themes: "/api/bazaar/getBazaarTheme",@@ -1759,11 +1857,12 @@ type="checkbox">templates: "/api/bazaar/getBazaarTemplate",widgets: "/api/bazaar/getBazaarWidget",};+ const mount = bazaar._beginBazaarRequest(bazaarType);fetchPost(bazaarAPI[bazaarType], {frontend: getFrontend(),}, response => {if (response.code === 0) {- bazaar._onBazaar(response, bazaarType);+ bazaar._onBazaar(response, bazaarType, mount);}});},@@ -1871,40 +1970,36 @@ type="checkbox">});},_initBazaarPanel(app: App, bazaarType: TBazaarType, panel: HTMLElement) {- if (panel.getAttribute("data-init")) {+ if (!isBazaarPackageTypeAvailable(bazaarType) || panel.getAttribute("data-init")) {return;}+ const mount = bazaar._beginBazaarRequest(bazaarType);switch (bazaar._type2tabType(bazaarType)) {case "template":fetchPost("/api/bazaar/getBazaarTemplate", {}, response => {- bazaar._onBazaar(response, "templates");- bazaar._data.templates = response.data.packages;+ bazaar._onBazaar(response, "templates", mount);});break;case "icon":fetchPost("/api/bazaar/getBazaarIcon", {}, response => {- bazaar._onBazaar(response, "icons");- bazaar._data.icons = response.data.packages;+ bazaar._onBazaar(response, "icons", mount);});break;case "widget":fetchPost("/api/bazaar/getBazaarWidget", {}, response => {- bazaar._onBazaar(response, "widgets");- bazaar._data.widgets = response.data.packages;+ bazaar._onBazaar(response, "widgets", mount);});break;case "theme":fetchPost("/api/bazaar/getBazaarTheme", {frontend: getFrontend()}, response => {- bazaar._onBazaar(response, "themes");- bazaar._data.themes = response.data.packages;+ bazaar._onBazaar(response, "themes", mount);});break;case "plugin":fetchPost("/api/bazaar/getBazaarPlugin", {frontend: getFrontend()}, response => {- bazaar._onBazaar(response, "plugins");- bazaar._data.plugins = response.data.packages;+ bazaar._onBazaar(response, "plugins", mount);});break;}@@ -1912,7 +2007,7 @@ type="checkbox">},/** 切换集市顶部 Tab */switchBazaarTab(app: App, bazaarType: TBazaarType, from: "downloaded" | "updated" | "bazaar") {- if (!bazaar.element) {+ if (!bazaar.element || !isBazaarPackageTypeAvailable(bazaarType)) {return;}const layoutTabType = from === "bazaar" ? bazaar._type2tabType(bazaarType) : "downloaded";@@ -1946,20 +2041,23 @@ type="checkbox">}}},- _setLocalPackageUploading(uploading: boolean) {+ _setLocalPackageUploading(uploading: boolean, mount: IBazaarMountSnapshot) {bazaar._localPackageUploading = uploading;- const labelElement = bazaar.element.querySelector('[data-type="install-local-package"]');+ if (!bazaar._isMountCurrent(mount)) {+ return;+ }+ const labelElement = mount.element.querySelector('[data-type="install-local-package"]');const inputElement = labelElement?.querySelector('input[type="file"]') as HTMLInputElement;labelElement?.toggleAttribute("disabled", uploading);if (inputElement) {inputElement.disabled = uploading;}},- _installLocalPackage(file: File, app: App, overwrite = false) {- if (bazaar._localPackageUploading) {+ _installLocalPackage(file: File, app: App, mount: IBazaarMountSnapshot, overwrite = false) {+ if (getFrontend() === "mobile" || bazaar._localPackageUploading) {return;}- bazaar._setLocalPackageUploading(true);+ bazaar._setLocalPackageUploading(true, mount);const formData = new FormData();formData.append("file", file);formData.append("frontend", getFrontend());@@ -1976,7 +2074,7 @@ type="checkbox">if (data?.reason === "package-exists" && data.packageName) {confirmDialog("⚠️ " + window.siyuan.languages.update,window.siyuan.languages.confirmOverwriteLocalBazaarPackage.replace("${name}", escapeHtml(data.packageName)), () => {- bazaar._installLocalPackage(file, app, true);+ bazaar._installLocalPackage(file, app, mount, true);});} else if (data?.reason === "package-incompatible") {showMessage(data.minAppVersion ?@@ -1991,12 +2089,14 @@ type="checkbox">showMessage(window.siyuan.languages.uploadError);return;}- bazaar.element.querySelector("#configBazaarReadme")?.classList.remove("config__view--show");bazaar._data.details.delete(bazaar._getDetailKey(data.packageType, data.packageName));bazaar._data.update[data.packageType] = bazaar._data.update[data.packageType].filter((item) =>item.installed.name !== data.packageName);- bazaar._syncUpdateTabCounter();- bazaar.switchBazaarTab(app, data.packageType, "downloaded");+ if (bazaar._isMountCurrent(mount)) {+ mount.element.querySelector("#configBazaarReadme")?.classList.remove("config__view--show");+ bazaar._syncUpdateTabCounter();+ bazaar.switchBazaarTab(app, data.packageType, "downloaded");+ }if (data.packageType === "plugins" && !data.updated) {if (window.siyuan.config.bazaar.petalDisabled) {confirmDialog(window.siyuan.languages.confirm, window.siyuan.languages.enablePluginTip2);@@ -2008,14 +2108,17 @@ type="checkbox">app: Constants.SIYUAN_APPID,}, (enableResponse) => {loadPlugin(app, enableResponse.data).then(() => {- bazaar._genMyHTML("plugins", app, false);+ if (bazaar._isMountCurrent(mount)) {+ bazaar._genMyHTML("plugins", app, false);+ }});});});}}}).finally(() => {- bazaar._setLocalPackageUploading(false);+ const activeMount = bazaar._isMountCurrent(mount) ? mount : bazaar._captureMount();+ bazaar._setLocalPackageUploading(false, activeMount);});},_getLocalPackageFile(files: FileList | null) {@@ -2025,17 +2128,20 @@ type="checkbox">}return files[0];},- _bindLocalPackageEvent(app: App) {- const inputElement = bazaar.element.querySelector('[data-type="local-package-file"]') as HTMLInputElement;+ _bindLocalPackageEvent(app: App, mount: IBazaarMountSnapshot) {+ if (getFrontend() === "mobile") {+ return;+ }+ const inputElement = mount.element.querySelector('[data-type="local-package-file"]') as HTMLInputElement;inputElement?.addEventListener("change", () => {const file = bazaar._getLocalPackageFile(inputElement.files);inputElement.value = "";if (file) {- bazaar._installLocalPackage(file, app);+ bazaar._installLocalPackage(file, app, mount);}});- const dropTarget = bazaar.element.firstElementChild as HTMLElement;+ const dropTarget = mount.element.firstElementChild as HTMLElement;const dropElement = dropTarget.querySelector(".config-bazaar__drop");let dragDepth = 0;const isFileDrag = (event: DragEvent) => Array.from(event.dataTransfer?.types || []).includes("Files");@@ -2076,18 +2182,22 @@ type="checkbox">event.stopPropagation();const file = bazaar._getLocalPackageFile(event.dataTransfer.files);if (file) {- bazaar._installLocalPackage(file, app);+ bazaar._installLocalPackage(file, app, mount);}});},bindEvent(app: App) {if (!window.siyuan.config.bazaar.trust) {bazaar.element.querySelector("button").addEventListener("click", () => {+ const mount = bazaar._captureMount();fetchPost("/api/setting/setBazaar", {...window.siyuan.config.bazaar,trust: true,}, (response) => {window.siyuan.config.bazaar = response.data;+ if (!bazaar._isMountCurrent(mount)) {+ return;+ }bazaar.element.innerHTML = bazaar.genHTML();bazaar.bindEvent(app);});@@ -2099,12 +2209,14 @@ type="checkbox">this._data.details.clear();this._syncRatingUser();this._bindRatingUserChange();+ const mount = this._captureMount();(["plugins", "themes", "icons", "templates", "widgets"] as TBazaarType[]).forEach((type) => {this._data.update[type] = [];});this._genMyHTML("plugins", app);this._checkUpdate(true);- this._bindLocalPackageEvent(app);+ this._setLocalPackageUploading(this._localPackageUploading, mount);+ this._bindLocalPackageEvent(app, mount);bazaar.element.firstElementChild.addEventListener("click", (event) => {if (bazaar._syncRatingUser()) {bazaar._refreshVisibleRatingUI();@@ -2135,6 +2247,11 @@ type="checkbox">(packageSource === "downloaded" ? pkgItem : undefined);const availableItem = packageDetail?.available || updatedItem?.available ||(packageSource === "bazaar" ? pkgItem : undefined);+ if (pkgType && !isBazaarPackageTypeAvailable(pkgType)) {+ event.preventDefault();+ event.stopPropagation();+ return;+ }while (target && !target.isEqualNode(bazaar.element)) {const type = target.getAttribute("data-type");if (target.tagName === "A") {@@ -2221,8 +2338,9 @@ type="checkbox">};const themeAppearanceMode = pkgType === "themes" ?bazaar._resolveThemeAppearanceMode(installItem) : {};+ const request = bazaar._beginBazaarRequest(pkgType, mount);fetchPost(installAPI[pkgType], {- keyword: (bazaar.element.querySelector(`.config-bazaar__panel[data-type="${bazaar._type2tabType(pkgType)}"] .b3-text-field`) as HTMLInputElement).value,+ keyword: (mount.element.querySelector(`.config-bazaar__panel[data-type="${bazaar._type2tabType(pkgType)}"] .b3-text-field`) as HTMLInputElement).value,repoURL: installItem.repoURL,packageName: installItem.name,repoHash: installItem.repoHash,@@ -2232,9 +2350,11 @@ type="checkbox">if (response.code !== 0) {return;}- bazaar._onBazaar(response, pkgType);- bazaar._genMyHTML(pkgType, app, false);- bazaar._refreshReadmeDetail(pkgType, installItem.name);+ bazaar._onBazaar(response, pkgType, request);+ if (bazaar._isMountCurrent(mount)) {+ bazaar._genMyHTML(pkgType, app, false);+ bazaar._refreshReadmeDetail(pkgType, installItem.name);+ }if (pkgType === "plugins") {if (window.siyuan.config.bazaar.petalDisabled) {confirmDialog(window.siyuan.languages.confirm, window.siyuan.languages.enablePluginTip2);@@ -2246,8 +2366,10 @@ type="checkbox">app: Constants.SIYUAN_APPID,}, (response) => {loadPlugin(app, response.data).then(() => {- bazaar._genMyHTML(pkgType, app, false);- bazaar._refreshReadmeDetail(pkgType, installItem.name);+ if (bazaar._isMountCurrent(mount)) {+ bazaar._genMyHTML(pkgType, app, false);+ bazaar._refreshReadmeDetail(pkgType, installItem.name);+ }});});});@@ -2257,14 +2379,21 @@ type="checkbox">}break;} else if (type === "install-all") {+ if (getFrontend() === "mobile") {+ event.preventDefault();+ event.stopPropagation();+ break;+ }confirmDialog("⬆️ " + window.siyuan.languages.updateAll, window.siyuan.languages.confirmUpdateAll, () => {fetchPost("/api/bazaar/batchUpdatePackage", {frontend: getFrontend()}, (response) => {if (response.code !== 0) {showMessage(response.msg);return;}- bazaar.element.querySelector("#configBazaarReadme")?.classList.remove("config__view--show");- bazaar._checkUpdate(true);+ if (bazaar._isMountCurrent(mount)) {+ mount.element.querySelector("#configBazaarReadme")?.classList.remove("config__view--show");+ bazaar._checkUpdate(true);+ }});});event.preventDefault();@@ -2281,6 +2410,7 @@ type="checkbox">if (!target.classList.contains("b3-button")) {target.parentElement.insertAdjacentHTML("afterend", '<img data-type="img-loading" style="position: absolute;top: 0;left: 0;height: 100%;width: 100%;padding: 16px;box-sizing: border-box;" src="/stage/loading-pure.svg">');}+ const request = bazaar._beginBazaarRequest(pkgType, mount);fetchPost("/api/bazaar/updateBazaarPackage", {packageType: pkgType,packageName,@@ -2291,10 +2421,12 @@ type="checkbox">target.parentElement.parentElement.querySelector("img[data-type='img-loading']")?.remove();return;}- bazaar.element.querySelector("#configBazaarReadme")?.classList.remove("config__view--show");- this._genMyHTML(pkgType, app);- bazaar._onBazaar(response, pkgType);- bazaar._checkUpdate(true);+ bazaar._onBazaar(response, pkgType, request);+ if (bazaar._isMountCurrent(mount)) {+ mount.element.querySelector("#configBazaarReadme")?.classList.remove("config__view--show");+ this._genMyHTML(pkgType, app);+ bazaar._checkUpdate(true);+ }});});}@@ -2312,21 +2444,25 @@ type="checkbox">widgets: "/api/bazaar/uninstallBazaarWidget",};const uninstallName = installedItem.name;+ const keyword = (mount.element.querySelector(`.config-bazaar__panel[data-type="${bazaar._type2tabType(pkgType)}"] .b3-text-field`) as HTMLInputElement).value;confirmDialog("⚠️ " + window.siyuan.languages.uninstall, window.siyuan.languages.confirmUninstall.replace("${name}", escapeHtml(uninstallName)), () => {+ const request = bazaar._beginBazaarRequest(pkgType, mount);fetchPost(uninstallAPI[pkgType], {packageName: uninstallName,- keyword: (bazaar.element.querySelector(`.config-bazaar__panel[data-type="${bazaar._type2tabType(pkgType)}"] .b3-text-field`) as HTMLInputElement).value,+ keyword,frontend: getFrontend()}, response => {if (response.code !== 0) {showMessage(response.msg);return;}- bazaar.element.querySelector("#configBazaarReadme")?.classList.remove("config__view--show");bazaar._data.details.delete(bazaar._getDetailKey(pkgType, uninstallName));- this._genMyHTML(pkgType, app);- bazaar._onBazaar(response, pkgType);- bazaar._checkUpdate(true);+ bazaar._onBazaar(response, pkgType, request);+ if (bazaar._isMountCurrent(mount)) {+ mount.element.querySelector("#configBazaarReadme")?.classList.remove("config__view--show");+ this._genMyHTML(pkgType, app);+ bazaar._checkUpdate(true);+ }});});break;@@ -2339,7 +2475,9 @@ type="checkbox">const appearanceItem = installedItem || pkgItem;target.setAttribute("disabled", "disabled");bazaar._setAppearancePackage(pkgType as "themes" | "icons", appearanceItem, true, () => {- bazaar._refreshPackageUI(pkgType, appearanceItem.name, app);+ if (bazaar._isMountCurrent(mount)) {+ bazaar._refreshPackageUI(pkgType, appearanceItem.name, app);+ }});break;} else if (["package-enable", "package-disable"].includes(type) && (installedItem || pkgItem) && pkgType) {@@ -2353,11 +2491,15 @@ type="checkbox">target.setAttribute("disabled", "disabled");if (pkgType === "plugins" && installedItem) {bazaar._setPluginEnabled(app, installedItem, enabled, () => {- bazaar._refreshPackageUI(pkgType, installedItem.name, app);+ if (bazaar._isMountCurrent(mount)) {+ bazaar._refreshPackageUI(pkgType, installedItem.name, app);+ }});} else if (["icons", "themes"].includes(pkgType)) {bazaar._setAppearancePackage(pkgType as "themes" | "icons", actionItem, enabled, () => {- bazaar._refreshPackageUI(pkgType, actionItem.name, app);+ if (bazaar._isMountCurrent(mount)) {+ bazaar._refreshPackageUI(pkgType, actionItem.name, app);+ }});}break;@@ -2379,29 +2521,40 @@ type="checkbox">} else if (type === "plugins-enable") {if (!target.getAttribute("disabled")) {target.setAttribute("disabled", "disabled");+ const pluginCards = mount.element.querySelectorAll(+ "#configBazaarDownloaded .b3-card[data-name]"+ ) as NodeListOf<HTMLElement>;+ const pluginNames = Array.from(pluginCards).map((item) => item.dataset.name)+ .filter((name): name is string => Boolean(name));window.siyuan.config.bazaar.petalDisabled = !(target as HTMLInputElement).checked;fetchPost("/api/setting/setBazaar", window.siyuan.config.bazaar, () => {- target.removeAttribute("disabled");- target.setAttribute("aria-label", window.siyuan.languages[- window.siyuan.config.bazaar.petalDisabled ? "enable" : "disableAll"- ]);+ if (bazaar._isMountCurrent(mount)) {+ target.removeAttribute("disabled");+ target.setAttribute("aria-label", window.siyuan.languages[+ window.siyuan.config.bazaar.petalDisabled ? "enable" : "disableAll"+ ]);+ }if (window.siyuan.config.bazaar.petalDisabled) {- bazaar.element.querySelectorAll("#configBazaarDownloaded .b3-card").forEach(item => {- item.querySelector('[data-type="setting"]')?.classList.add("fn__none");- const packageName = item.getAttribute("data-name");- const pkg = bazaar._data.downloaded.find((p: IBazaarItem) => p.name === packageName);- if (pkg) {- uninstall(app, pkg.name, true);- }+ if (bazaar._isMountCurrent(mount)) {+ mount.element.querySelectorAll("#configBazaarDownloaded .b3-card").forEach((item: HTMLElement) => {+ item.querySelector('[data-type="setting"]')?.classList.add("fn__none");+ });+ }+ pluginNames.forEach((pluginName) => {+ uninstall(app, pluginName, true);});} else {loadPlugins(app, null, false).then(() => {app.plugins.forEach(item => {afterLoadPlugin(item);});- this._genMyHTML("plugins", app, false);+ if (bazaar._isMountCurrent(mount)) {+ this._genMyHTML("plugins", app, false);+ }});+ /// #if !MOBILEsaveLayout();+ /// #endif}});}@@ -2415,8 +2568,10 @@ type="checkbox">target.setAttribute("disabled", "disabled");const enabled = (target as HTMLInputElement).checked;bazaar._setPluginPublishEnabled(installedItem, enabled, () => {- target.removeAttribute("disabled");- this._genMyHTML("plugins", app, true);+ if (bazaar._isMountCurrent(mount)) {+ target.removeAttribute("disabled");+ this._genMyHTML("plugins", app, true);+ }});}event.stopPropagation();@@ -2427,8 +2582,10 @@ type="checkbox">const enabled = (target as HTMLInputElement).checked;const pluginItem = installedItem || pkgItem;bazaar._setPluginEnabled(app, pluginItem, enabled, () => {- target.removeAttribute("disabled");- this._genMyHTML("plugins", app, true);+ if (bazaar._isMountCurrent(mount)) {+ target.removeAttribute("disabled");+ this._genMyHTML("plugins", app, true);+ }});}event.stopPropagation();@@ -2477,32 +2634,32 @@ type="checkbox">const keyword = inputElement.value.trim();const type = (hasClosestByClassName(inputElement, "config-bazaar__panel") as HTMLElement).getAttribute("data-type");if (type === "template") {+ const request = bazaar._beginBazaarRequest("templates", mount);fetchPost("/api/bazaar/getBazaarTemplate", {keyword}, response => {- bazaar._onBazaar(response, "templates");- bazaar._data.templates = response.data.packages;+ bazaar._onBazaar(response, "templates", request);});} else if (type === "icon") {+ const request = bazaar._beginBazaarRequest("icons", mount);fetchPost("/api/bazaar/getBazaarIcon", {keyword}, response => {- bazaar._onBazaar(response, "icons");- bazaar._data.icons = response.data.packages;+ bazaar._onBazaar(response, "icons", request);});} else if (type === "widget") {+ const request = bazaar._beginBazaarRequest("widgets", mount);fetchPost("/api/bazaar/getBazaarWidget", {keyword}, response => {- bazaar._onBazaar(response, "widgets");- bazaar._data.widgets = response.data.packages;+ bazaar._onBazaar(response, "widgets", request);});- } else if (type === "theme") {+ } else if (type === "theme" && isBazaarPackageTypeAvailable("themes")) {+ const request = bazaar._beginBazaarRequest("themes", mount);fetchPost("/api/bazaar/getBazaarTheme", {frontend: getFrontend(), keyword}, response => {- bazaar._onBazaar(response, "themes");- bazaar._data.themes = response.data.packages;+ bazaar._onBazaar(response, "themes", request);});} else if (type === "plugin") {+ const request = bazaar._beginBazaarRequest("plugins", mount);fetchPost("/api/bazaar/getBazaarPlugin", {frontend: getFrontend(),keyword}, response => {- bazaar._onBazaar(response, "plugins");- bazaar._data.plugins = response.data.packages;+ bazaar._onBazaar(response, "plugins", request);});} else if (type === "downloaded") {const activeType = inputElement.closest(".config-bazaar__title")?.querySelector('.b3-button[data-type^="my"]:not(.b3-button--outline)')?.getAttribute("data-type");@@ -2595,7 +2752,10 @@ type="checkbox">container.innerHTML = `<div class="b3-cards${html ? "" : " b3-cards--nowrap"}">${html || `<ul class="b3-list b3-list--background"><li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li></ul>`}</div>`;container.parentElement.querySelector(".counter").textContent = htmlParts.length.toString();},- _onBazaar(response: IWebSocketData, bazaarType: TBazaarType) {+ _onBazaar(response: IWebSocketData, bazaarType: TBazaarType, mount: IBazaarMountSnapshot) {+ if (!isBazaarPackageTypeAvailable(bazaarType) || !bazaar._isBazaarRequestCurrent(bazaarType, mount)) {+ return;+ }const panelSelector: Record<TBazaarType, string> = {plugins: "#configBazaarPlugin",themes: "#configBazaarTheme",@@ -2604,6 +2764,9 @@ type="checkbox">widgets: "#configBazaarWidget",};const element = bazaar.element.querySelector(panelSelector[bazaarType]);+ if (!element) {+ return;+ }if (response.code === 1) {// 安装集市包 /api/bazaar/installBazaar* 失败showMessage(response.msg);diff --git a/app/src/config/bazaarTab.ts b/app/src/config/bazaarTab.tsnew file mode 100644index 0000000000..a592a44cb9--- /dev/null+++ b/app/src/config/bazaarTab.ts@@ -0,0 +1,74 @@+import type {App} from "../index";+import {isBazaarPackageTypeAvailable} from "../util/bazaarAvailability";++type BazaarModule = typeof import("./bazaar");++let bazaarModulePromise: Promise<BazaarModule> | undefined;+let activeMountState: {root: HTMLElement; token: symbol} | undefined;+let activeMountPromise: Promise<BazaarModule> | undefined;++const loadBazaarModule = () => {+ if (!bazaarModulePromise) {+ bazaarModulePromise = import("./bazaar");+ }+ return bazaarModulePromise;+};++/** 集市 Tab 侧栏 / 全局搜索索引文案 */+export const collectBazaarTabSearchStrings = (): string[] => [+ window.siyuan.languages.bazaar,+ window.siyuan.languages.downloaded,+ window.siyuan.languages.update,+ window.siyuan.languages.plugin,+ ...(isBazaarPackageTypeAvailable("themes") ? [window.siyuan.languages.theme] : []),+ window.siyuan.languages.icon,+ window.siyuan.languages.template,+ window.siyuan.languages.widget,+];++/** 延迟加载并挂载集市,避免将集市的插件运行时依赖拉入移动端启动链 */+export const mountBazaarTab = (+ root: HTMLElement,+ keywords?: string,+ app?: App,+): Promise<void> => {+ const state = {root, token: Symbol()};+ activeMountState = state;+ const mountPromise = loadBazaarModule().then((module) => {+ if (activeMountState === state) {+ module.mountBazaarTab(root, keywords, app);+ }+ return module;+ });+ activeMountPromise = mountPromise;+ return mountPromise.then(() => undefined);+};++/** 释放已挂载或正在加载的集市 */+export const unmountBazaarTab = (root: HTMLElement) => {+ if (activeMountState?.root === root) {+ activeMountState = undefined;+ }+ if (bazaarModulePromise) {+ void bazaarModulePromise.then((module) => {+ if (activeMountState?.root !== root) {+ module.unmountBazaarTab(root);+ }+ });+ }+};++/** 在最近一次集市挂载仍有效时执行回调 */+export const withMountedBazaar = async (callback: (module: BazaarModule) => void): Promise<boolean> => {+ const state = activeMountState;+ const mountPromise = activeMountPromise;+ if (!state || !mountPromise) {+ return false;+ }+ const module = await mountPromise;+ if (activeMountState !== state || module.bazaar.element !== state.root) {+ return false;+ }+ callback(module);+ return true;+};diff --git a/app/src/config/index.ts b/app/src/config/index.tsindex 32a96fa0ee..f7ea948dc3 100644--- a/app/src/config/index.ts+++ b/app/src/config/index.ts@@ -6,12 +6,13 @@ import {bindSettingSaveDelegation} from "./setting/save";import {Dialog} from "../dialog";import {Constants} from "../constants";import {focusByRange} from "../protyle/util/selection";-import {bazaar, renderReadme} from "./bazaar";+/// #endif+import {unmountBazaarTab, withMountedBazaar} from "./bazaarTab";import {fetchSyncPost} from "../util/fetch";import {getFrontend} from "../util/functions";import {showMessage} from "../dialog/message";import {escapeHtml} from "../util/escape";-/// #endif+import {isBazaarAvailable, isBazaarPackageTypeAvailable} from "../util/bazaarAvailability";import {getSettingTabDefs} from "./setting/tabs";import {clearAccessTabElement} from "./tabs/accessRuntime";import {clearSyncTabElement} from "./tabs/syncRuntime";@@ -32,6 +33,7 @@ const openSettingDialog = (app: App, initialTab: TSettingTab = "editor") => {tabListItems.push(`<li data-name="${def.id}" class="b3-list-item${isActive ? " b3-list-item--focus" : ""}${def.hidden ? " fn__none" : ""}"><svg class="b3-list-item__graphic"><use xlink:href="#${def.icon}"></use></svg><span class="b3-list-item__text">${def.title}</span></li>`);tabPanels.push(`<div class="config__tab-container${isActive ? "" : " fn__none"}" data-name="${def.id}"></div>`);}+ const settingDialogRef: {element?: HTMLElement} = {};const dialog = new Dialog({content: `<div class="fn__flex-1 fn__flex config__panel" style="overflow: hidden;position: relative"><div class="config__side b3-list b3-list--background">@@ -53,6 +55,10 @@ const openSettingDialog = (app: App, initialTab: TSettingTab = "editor") => {width: "max(70vw, min(90vw, 900px))",height: "90vh",destroyCallback() {+ const bazaarRoot = settingDialogRef.element?.querySelector('.config__tab-container[data-name="bazaar"]') as HTMLElement | null;+ if (bazaarRoot) {+ unmountBazaarTab(bazaarRoot);+ }clearSyncTabElement();clearAccessTabElement();if (range) {@@ -60,6 +66,7 @@ const openSettingDialog = (app: App, initialTab: TSettingTab = "editor") => {}},});+ settingDialogRef.element = dialog.element;dialog.element.setAttribute("data-key", Constants.DIALOG_SETTING);const tabWrap = dialog.element.querySelector(".config__tab-wrap") as HTMLElement;@@ -79,6 +86,9 @@ const openSettingDialog = (app: App, initialTab: TSettingTab = "editor") => {/// #endifexport const openSetting = (app: App, tab?: TSettingTab) => {+ if (tab === "bazaar" && !isBazaarAvailable()) {+ return;+ }/// #if MOBILEopenMobileSetting(app, tab);/// #else@@ -87,9 +97,11 @@ export const openSetting = (app: App, tab?: TSettingTab) => {};export const openBazaarReadme = async (app: App, bazaarType: TBazaarType, itemName: string, from: "bazaar" | "downloaded") => {- /// #if !MOBILE+ if (!isBazaarAvailable() || !isBazaarPackageTypeAvailable(bazaarType)) {+ return;+ }if (!window.siyuan.config.bazaar.trust) {- openSettingDialog(app, "bazaar");+ openSetting(app, "bazaar");return;}@@ -128,8 +140,9 @@ export const openBazaarReadme = async (app: App, bazaarType: TBazaarType, itemNareturn;}- openSettingDialog(app, "bazaar");- bazaar.switchBazaarTab(app, bazaarType, from);- renderReadme(bazaarType, from, resource);- /// #endif+ openSetting(app, "bazaar");+ await withMountedBazaar(({bazaar, renderReadme}) => {+ bazaar.switchBazaarTab(app, bazaarType, from);+ renderReadme(bazaarType, from, resource);+ });};diff --git a/app/src/config/setting/builder.ts b/app/src/config/setting/builder.tsindex 9843b960d4..6d9e97e433 100644--- a/app/src/config/setting/builder.ts+++ b/app/src/config/setting/builder.ts@@ -511,7 +511,7 @@ export class SettingBuilder {// panel 型 Tab 不支持 rebuild(无注册项可清),忽略该参数以对齐 SettingTab.mount 签名mount: async (root, {keywords} = {}, app, _rebuild) => {void _rebuild;- mount(root, keywords, app);+ await mount(root, keywords, app);},scanSearch: (keywords) => {if (tabSearchTitle === undefined) {diff --git a/app/src/config/setting/tabs.ts b/app/src/config/setting/tabs.tsindex d3be293415..52c3d45648 100644--- a/app/src/config/setting/tabs.ts+++ b/app/src/config/setting/tabs.ts@@ -9,11 +9,11 @@ import {appearanceConfigApi} from "../tabs/appearanceRuntime";import {mountSyncTabExtras, patchSyncConfig} from "../tabs/syncRuntime";import {mountAccessTab} from "../tabs/accessRuntime";import {collectAssetsTabSearchStrings, mountAssetsTab} from "../assets";+import {collectBazaarTabSearchStrings, mountBazaarTab} from "../bazaarTab";/// #if !MOBILE-import {collectBazaarTabSearchStrings, mountBazaarTab} from "../bazaar";import {collectKeymapTabSearchStrings, mountKeymapTab} from "../tabs/keymapUi";/// #endif-import {isHuawei, isInHarmony} from "../../protyle/util/compatibility";+import {isBazaarAvailable} from "../../util/bazaarAvailability";import {SettingBuilder, type SettingTab} from "./builder";import {registerEditorTab} from "../tabs/editorTab";import {registerFileTab} from "../tabs/fileTab";@@ -48,16 +48,14 @@ const settingTabs = {title: () => window.siyuan.languages.appearance,defaultSave: appearanceConfigApi.patch,}, registerAppearanceTab),- /// #if !MOBILEbazaar: setting.panel({id: "bazaar",icon: "iconBazaar",title: () => window.siyuan.languages.bazaar,- hidden: () => !!(isHuawei() || isInHarmony()),+ hidden: () => !isBazaarAvailable(),searchStrings: collectBazaarTabSearchStrings,mount: mountBazaarTab,}),- /// #endifflashcard: setting.tab({id: "flashcard",icon: "iconRiffCard",diff --git a/app/src/mobile/menu/index.ts b/app/src/mobile/menu/index.tsindex 0a26db2ad2..056c6dca44 100644--- a/app/src/mobile/menu/index.ts+++ b/app/src/mobile/menu/index.ts@@ -21,6 +21,7 @@ import {getCurrentEditor} from "../editor";import {openDataMigration} from "../../menus/dataMigration";import {normalizeSearchText} from "../../config/search/normalize";import type {SettingTabSearchResult} from "../../config/setting/builder";+import {unmountBazaarTab} from "../../config/bazaarTab";const getSettingTabFromMenuTarget = (target: HTMLElement): ISettingTabShell<TSettingTab> | undefined => {const item = target.closest(".b3-menu__item") as HTMLElement | null;@@ -58,16 +59,29 @@ const filterSettingTabsMenu = (element: HTMLElement, keywords: string) => {};const openSettingTab = (app: App, settingTabDef: ISettingTabShell<TSettingTab>, returnCallback?: () => void) => {+ let root: HTMLElement | undefined;openModel({title: settingTabDef.title,icon: "iconLeft",html: `<div class="config${isMobile() ? " config--mobile" : ""}"></div>`,bindEvent(modelMainElement: HTMLElement) {- const root = modelMainElement.firstElementChild as HTMLElement;+ root = modelMainElement.firstElementChild as HTMLElement;bindSettingSaveDelegation(root);void getSettingTab(settingTabDef.id).mount(root, undefined, app);},+ destroyCallback() {+ if (settingTabDef.id === "bazaar" && root) {+ unmountBazaarTab(root);+ }+ },backCallback() {+ if (settingTabDef.id === "bazaar") {+ const readmeElement = root?.querySelector("#configBazaarReadme.config__view--show");+ if (readmeElement) {+ readmeElement.classList.remove("config__view--show");+ return false;+ }+ }if (returnCallback) {returnCallback();} else {@@ -83,6 +97,7 @@ const openSettingMenu = (transition?: "back",returnCallback?: () => void,) => {+ let settingMenuElement: HTMLElement | undefined;openModel({title: window.siyuan.languages.config,icon: "iconLeft",@@ -99,9 +114,12 @@ const openSettingMenu = (</div></div>`,bindEvent(modelMainElement: HTMLElement) {+ settingMenuElement = modelMainElement;const searchElement = modelMainElement.querySelector("input") as HTMLInputElement;+ const groupsElement = modelMainElement.querySelector(".mobile-setting-menu__groups") as HTMLElement;let selectedTabId: TSettingTab | undefined;const showSearchResult = (keywords: string, tabId: TSettingTab, result: SettingTabSearchResult) => {+ groupsElement.classList.toggle("mobile-setting-menu__groups--bazaar", tabId === "bazaar");modelMainElement.querySelectorAll<HTMLElement>(".mobile-setting-menu__result").forEach((item) => {item.classList.toggle("fn__none", item.dataset.name !== tabId);});@@ -122,6 +140,7 @@ const openSettingMenu = (const matches = filterSettingTabsMenu(modelMainElement, keywords);if (!keywords || matches.size === 0) {selectedTabId = undefined;+ groupsElement.classList.remove("mobile-setting-menu__groups--bazaar");modelMainElement.querySelectorAll(".mobile-setting-menu__result").forEach((item) => {item.classList.add("fn__none");});@@ -164,6 +183,12 @@ const openSettingMenu = (});syncSearch();},+ destroyCallback() {+ const root = settingMenuElement?.querySelector('.mobile-setting-menu__result[data-name="bazaar"]') as HTMLElement | null;+ if (root) {+ unmountBazaarTab(root);+ }+ },backCallback() {if (returnCallback) {returnCallback();@@ -177,8 +202,11 @@ const openSettingMenu = (export const openMobileSetting = (app: App, tab?: TSettingTab, returnCallback?: () => void) => {activeBlur();- const settingTabDef = tab ? getSettingTabDefs().find(def => def.id === tab) : undefined;- if (settingTabDef) {+ if (tab) {+ const settingTabDef = getSettingTabDefs().find(def => def.id === tab);+ if (!settingTabDef || settingTabDef.hidden) {+ return;+ }openSettingTab(app, settingTabDef, returnCallback);return;}diff --git a/app/src/mobile/menu/model.ts b/app/src/mobile/menu/model.tsindex 3096d109d2..917c96889c 100644--- a/app/src/mobile/menu/model.ts+++ b/app/src/mobile/menu/model.ts@@ -1,20 +1,29 @@let modelDestroyCallback: (() => void) | undefined;-let modelBackCallback: (() => void) | undefined;+type TModelBackCallback = () => false | void;++let modelBackCallback: TModelBackCallback | undefined;+let modelVersion = 0;export const backModel = () => {if (!modelBackCallback) {return false;}const callback = modelBackCallback;+ const version = modelVersion;modelBackCallback = undefined;- callback();+ const keepCallback = callback() === false;+ if (keepCallback && modelVersion === version && !modelBackCallback) {+ modelBackCallback = callback;+ }return true;};export const destroyModel = () => {- modelDestroyCallback?.();+ const callback = modelDestroyCallback;modelDestroyCallback = undefined;modelBackCallback = undefined;+ modelVersion++;+ callback?.();};export const openModel = (obj: {@@ -23,7 +32,7 @@ export const openModel = (obj: {title: string,bindEvent: (element: HTMLElement) => void,destroyCallback?: () => void,- backCallback?: () => void,+ backCallback?: TModelBackCallback,transition?: "forward" | "back",}) => {destroyModel();diff --git a/app/src/mobile/util/closePanel.ts b/app/src/mobile/util/closePanel.tsindex 109b14461c..b46046968b 100644--- a/app/src/mobile/util/closePanel.ts+++ b/app/src/mobile/util/closePanel.ts@@ -1,7 +1,9 @@import {activeBlur} from "./keyboardToolbar";import {Constants} from "../../constants";+import {destroyModel} from "../menu/model";export const closePanel = () => {+ destroyModel();document.getElementById("menu").style.transform = "";document.getElementById("sidebar").style.transform = "";document.getElementById("model").style.transform = "";@@ -15,5 +17,6 @@ export const closePanel = () => {export const closeModel = () => {activeBlur();+ destroyModel();document.getElementById("model").style.transform = "";};diff --git a/app/src/plugin/openTopBarMenu.ts b/app/src/plugin/openTopBarMenu.tsindex 7b13f9682f..0cd1340a6e 100644--- a/app/src/plugin/openTopBarMenu.ts+++ b/app/src/plugin/openTopBarMenu.ts@@ -1,26 +1,27 @@import type {App} from "../index";import {Menu} from "./Menu";-import {isHuawei, setStorageVal} from "../protyle/util/compatibility";+import {setStorageVal} from "../protyle/util/compatibility";+import {isBazaarAvailable} from "../util/bazaarAvailability";/// #if !MOBILE-import {openSetting} from "../config";import {setTabPosition} from "../layout/tabUtil";/// #endifimport {Constants} from "../constants";export const openTopBarMenu = (app: App, target?: Element) => {const menu = new Menu(Constants.MENU_BAR_PLUGIN);- /// #if !MOBILE- menu.addItem({+ const manageElement = menu.addItem({id: "manage",icon: "iconSettings",label: window.siyuan.languages.manage,- ignore: isHuawei() || window.siyuan.config.readonly,+ ignore: !isBazaarAvailable() || window.siyuan.config.readonly,click() {- openSetting(app, "bazaar");+ void import("../config").then(({openSetting}) => openSetting(app, "bazaar"));}});- menu.addSeparator({id: "separator_1", ignore: isHuawei() || window.siyuan.config.readonly});- /// #endif+ const manageSeparatorElement = menu.addSeparator({+ id: "separator_1",+ ignore: !isBazaarAvailable() || window.siyuan.config.readonly,+ });let hasPlugin = false;app.plugins.forEach((plugin) => {// @ts-ignore@@ -106,9 +107,8 @@ export const openTopBarMenu = (app: App, target?: Element) => {}});if (!hasPlugin) {- if (target) {- window.siyuan.menus.menu.element.querySelector(".b3-menu__separator")?.remove();- } else {+ manageSeparatorElement?.remove();+ if (!manageElement && !target) {menu.addItem({id: "emptyContent",iconHTML: "",diff --git a/app/src/util/bazaarAvailability.test.ts b/app/src/util/bazaarAvailability.test.tsnew file mode 100644index 0000000000..a883d953af--- /dev/null+++ b/app/src/util/bazaarAvailability.test.ts@@ -0,0 +1,40 @@+import {describe, it} from "node:test";+import * as assert from "node:assert/strict";+import {+ isBazaarAvailableForFrontend,+ isBazaarPackageTypeAvailableForFrontend,+} from "./bazaarAvailability";++describe("bazaar frontend availability", () => {+ it("disables the marketplace only for disabled native mobile builds", () => {+ assert.equal(isBazaarAvailableForFrontend("mobile", ["bazaar"]), false);+ assert.equal(isBazaarAvailableForFrontend("mobile", ["ai", "bazaar"]), false);+ });++ it("keeps native mobile builds enabled when the feature is not disabled", () => {+ assert.equal(isBazaarAvailableForFrontend("mobile", undefined), true);+ assert.equal(isBazaarAvailableForFrontend("mobile", []), true);+ assert.equal(isBazaarAvailableForFrontend("mobile", ["ai"]), true);+ });++ it("does not apply native channel restrictions to browser frontends", () => {+ assert.equal(isBazaarAvailableForFrontend("browser-mobile", ["bazaar"]), true);+ assert.equal(isBazaarAvailableForFrontend("browser-desktop", ["bazaar"]), true);+ assert.equal(isBazaarAvailableForFrontend("desktop", ["bazaar"]), true);+ assert.equal(isBazaarAvailableForFrontend("desktop-window", ["bazaar"]), true);+ });++ it("keeps themes out of the first native mobile release", () => {+ assert.equal(isBazaarPackageTypeAvailableForFrontend("themes", "mobile"), false);+ assert.equal(isBazaarPackageTypeAvailableForFrontend("plugins", "mobile"), true);+ assert.equal(isBazaarPackageTypeAvailableForFrontend("icons", "mobile"), true);+ assert.equal(isBazaarPackageTypeAvailableForFrontend("templates", "mobile"), true);+ assert.equal(isBazaarPackageTypeAvailableForFrontend("widgets", "mobile"), true);+ });++ it("keeps themes available through browser and desktop frontends", () => {+ assert.equal(isBazaarPackageTypeAvailableForFrontend("themes", "browser-mobile"), true);+ assert.equal(isBazaarPackageTypeAvailableForFrontend("themes", "browser-desktop"), true);+ assert.equal(isBazaarPackageTypeAvailableForFrontend("themes", "desktop"), true);+ });+});diff --git a/app/src/util/bazaarAvailability.ts b/app/src/util/bazaarAvailability.tsnew file mode 100644index 0000000000..7bce6f1d01--- /dev/null+++ b/app/src/util/bazaarAvailability.ts@@ -0,0 +1,19 @@+import {getFrontend} from "./functions";++export const isBazaarAvailableForFrontend = (+ frontend: string,+ disabledFeatures: readonly string[] | undefined,+): boolean => frontend !== "mobile" || !disabledFeatures?.includes("bazaar");++export const isBazaarPackageTypeAvailableForFrontend = (+ bazaarType: TBazaarType,+ frontend: string,+): boolean => frontend !== "mobile" || bazaarType !== "themes";++export const isBazaarAvailable = (): boolean => isBazaarAvailableForFrontend(+ getFrontend(),+ window.siyuan.config.system.disabledFeatures,+);++export const isBazaarPackageTypeAvailable = (bazaarType: TBazaarType): boolean =>+ isBazaarPackageTypeAvailableForFrontend(bazaarType, getFrontend());diff --git a/app/src/util/uri.ts b/app/src/util/uri.tsindex c04f6bba86..fb4dd83b9d 100644--- a/app/src/util/uri.ts+++ b/app/src/util/uri.ts@@ -10,10 +10,13 @@ import {fetchPost} from "./fetch";import {checkFold} from "./noRelyPCFunction";import {openMobileFileById} from "../mobile/editor";import {isValidBazaarPackageName} from "./bazaarPackage";+import {isBazaarAvailable, isBazaarPackageTypeAvailable} from "./bazaarAvailability";import type {App} from "../index";import {activateQueuedAVLocate, queueAVLocateRequest} from "../protyle/render/av/locate";+const bazaarTypes = new Set<TBazaarType>(["plugins", "themes", "icons", "templates", "widgets"]);+const processSiYuanUriBlocks = (app: App, uriObj: URL): boolean => {const blockInfo = parseSiYuanUriInfo(uriObj);if (blockInfo != null) {@@ -122,10 +125,18 @@ const processSiYuanUriPlugins = (app: App, uriObj: URL): boolean => {};const processSiYuanUriBazaar = (app: App, uriObj: URL): boolean => {- /// #if !MOBILE+ if (!isBazaarAvailable()) {+ return false;+ }const [, _type, _name, target] = uriObj.pathname.split("/");if (!_type || !_name) return false;+ if (!bazaarTypes.has(_type as TBazaarType)) {+ return false;+ }const resourceType = _type as TBazaarType;+ if (!isBazaarPackageTypeAvailable(resourceType)) {+ return false;+ }let resourceName: string;try {resourceName = decodeURIComponent(_name);@@ -150,7 +161,6 @@ const processSiYuanUriBazaar = (app: App, uriObj: URL): boolean => {default:break;}- /// #endifreturn false;};diff --git a/kernel/model/plugin.go b/kernel/model/plugin.goindex df388fd8d0..6ab02073ec 100644--- a/kernel/model/plugin.go+++ b/kernel/model/plugin.go@@ -168,7 +168,7 @@ func IsPetalsEnabled() bool {}if !Conf.Bazaar.Trust {- // 移动端没有集市模块,所以要默认开启,桌面端和 Docker 容器需要用户手动确认过信任后才能开启+ // 移动端为了兼容通过同步获得的已有插件,不要求先确认集市信任;桌面端和 Docker 容器仍需用户手动确认if util.Container == util.ContainerStd || util.Container == util.ContainerDocker {return false}