mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 08:30:12 +01:00
This commit is contained in:
parent
02b62eba65
commit
953920e4de
3 changed files with 34 additions and 6 deletions
|
|
@ -9,7 +9,7 @@ import {Constants} from "../constants";
|
||||||
import {shell} from "electron";
|
import {shell} from "electron";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {isBrowser} from "../util/functions";
|
import {getFrontend, isBrowser} from "../util/functions";
|
||||||
import {setStorageVal} from "../protyle/util/compatibility";
|
import {setStorageVal} from "../protyle/util/compatibility";
|
||||||
import {hasClosestByAttribute} from "../protyle/util/hasClosest";
|
import {hasClosestByAttribute} from "../protyle/util/hasClosest";
|
||||||
import {Plugin} from "../plugin";
|
import {Plugin} from "../plugin";
|
||||||
|
|
@ -278,7 +278,9 @@ export const bazaar = {
|
||||||
} else if (bazaarType === "plugins") {
|
} else if (bazaarType === "plugins") {
|
||||||
url = "/api/bazaar/getInstalledPlugin";
|
url = "/api/bazaar/getInstalledPlugin";
|
||||||
}
|
}
|
||||||
fetchPost(url, {}, response => {
|
fetchPost(url, {
|
||||||
|
frontend: getFrontend()
|
||||||
|
}, response => {
|
||||||
contentElement.removeAttribute("data-loading");
|
contentElement.removeAttribute("data-loading");
|
||||||
let html = "";
|
let html = "";
|
||||||
let showSwitch = false;
|
let showSwitch = false;
|
||||||
|
|
@ -548,6 +550,7 @@ export const bazaar = {
|
||||||
packageName: dataObj.name,
|
packageName: dataObj.name,
|
||||||
repoHash: dataObj.repoHash,
|
repoHash: dataObj.repoHash,
|
||||||
mode: dataObj.themeMode === "dark" ? 1 : 0,
|
mode: dataObj.themeMode === "dark" ? 1 : 0,
|
||||||
|
frontend: getFrontend()
|
||||||
}, response => {
|
}, response => {
|
||||||
if (window.siyuan.config.appearance.themeJS && bazaarType === "themes") {
|
if (window.siyuan.config.appearance.themeJS && bazaarType === "themes") {
|
||||||
exportLayout({
|
exportLayout({
|
||||||
|
|
@ -564,6 +567,7 @@ export const bazaar = {
|
||||||
fetchPost("/api/petal/setPetalEnabled", {
|
fetchPost("/api/petal/setPetalEnabled", {
|
||||||
packageName: dataObj.name,
|
packageName: dataObj.name,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
frontend: getFrontend()
|
||||||
}, (response) => {
|
}, (response) => {
|
||||||
loadPlugin(app, response.data);
|
loadPlugin(app, response.data);
|
||||||
bazaar._genMyHTML(bazaarType, app);
|
bazaar._genMyHTML(bazaarType, app);
|
||||||
|
|
@ -598,6 +602,7 @@ export const bazaar = {
|
||||||
repoHash: dataObj.repoHash,
|
repoHash: dataObj.repoHash,
|
||||||
mode: dataObj.themeMode === "dark" ? 1 : 0,
|
mode: dataObj.themeMode === "dark" ? 1 : 0,
|
||||||
update: true,
|
update: true,
|
||||||
|
frontend: getFrontend()
|
||||||
}, response => {
|
}, response => {
|
||||||
// 更新主题后不需要对该主题进行切换 https://github.com/siyuan-note/siyuan/issues/4966
|
// 更新主题后不需要对该主题进行切换 https://github.com/siyuan-note/siyuan/issues/4966
|
||||||
this._genMyHTML(bazaarType, app);
|
this._genMyHTML(bazaarType, app);
|
||||||
|
|
@ -645,7 +650,8 @@ export const bazaar = {
|
||||||
} else {
|
} else {
|
||||||
confirmDialog(window.siyuan.languages.uninstall, window.siyuan.languages.confirmUninstall.replace("${name}", packageName), () => {
|
confirmDialog(window.siyuan.languages.uninstall, window.siyuan.languages.confirmUninstall.replace("${name}", packageName), () => {
|
||||||
fetchPost(url, {
|
fetchPost(url, {
|
||||||
packageName
|
packageName,
|
||||||
|
frontend: getFrontend()
|
||||||
}, response => {
|
}, response => {
|
||||||
this._genMyHTML(bazaarType, app);
|
this._genMyHTML(bazaarType, app);
|
||||||
bazaar._onBazaar(response, bazaarType, ["themes", "icons"].includes(bazaarType));
|
bazaar._onBazaar(response, bazaarType, ["themes", "icons"].includes(bazaarType));
|
||||||
|
|
@ -719,6 +725,7 @@ export const bazaar = {
|
||||||
fetchPost("/api/petal/setPetalEnabled", {
|
fetchPost("/api/petal/setPetalEnabled", {
|
||||||
packageName: dataObj.name,
|
packageName: dataObj.name,
|
||||||
enabled,
|
enabled,
|
||||||
|
frontend: getFrontend()
|
||||||
}, (response) => {
|
}, (response) => {
|
||||||
target.removeAttribute("disabled");
|
target.removeAttribute("disabled");
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
|
|
@ -764,7 +771,9 @@ export const bazaar = {
|
||||||
bazaar._data.themes = response.data.packages;
|
bazaar._data.themes = response.data.packages;
|
||||||
});
|
});
|
||||||
} else if (type === "plugin") {
|
} else if (type === "plugin") {
|
||||||
fetchPost("/api/bazaar/getBazaarPlugin", {}, response => {
|
fetchPost("/api/bazaar/getBazaarPlugin", {
|
||||||
|
frontend: getFrontend()
|
||||||
|
}, response => {
|
||||||
bazaar._onBazaar(response, "plugins", false);
|
bazaar._onBazaar(response, "plugins", false);
|
||||||
bazaar._data.plugins = response.data.packages;
|
bazaar._data.plugins = response.data.packages;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import {Plugin} from "./index";
|
||||||
import {exportLayout} from "../layout/util";
|
import {exportLayout} from "../layout/util";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {API} from "./API";
|
import {API} from "./API";
|
||||||
import {isMobile, isWindow} from "../util/functions";
|
import {getFrontend, isMobile, isWindow} from "../util/functions";
|
||||||
|
|
||||||
const getObject = (key: string) => {
|
const getObject = (key: string) => {
|
||||||
const api = {
|
const api = {
|
||||||
|
|
@ -20,7 +20,7 @@ const runCode = (code: string, sourceURL: string) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const loadPlugins = async (app: App) => {
|
export const loadPlugins = async (app: App) => {
|
||||||
const response = await fetchSyncPost("/api/petal/loadPetals");
|
const response = await fetchSyncPost("/api/petal/loadPetals", {frontend: getFrontend()});
|
||||||
let css = "";
|
let css = "";
|
||||||
// 为加快启动速度,不进行 await
|
// 为加快启动速度,不进行 await
|
||||||
response.data.forEach((item: IPluginData) => {
|
response.data.forEach((item: IPluginData) => {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,25 @@ export const isMobile = () => {
|
||||||
return document.getElementById("sidebar") ? true : false;
|
return document.getElementById("sidebar") ? true : false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getFrontend = () => {
|
||||||
|
/// #if MOBILE
|
||||||
|
if (window.navigator.userAgent.startsWith("SiYuan/")) {
|
||||||
|
return "mobile";
|
||||||
|
} else {
|
||||||
|
return "browser-mobile";
|
||||||
|
}
|
||||||
|
/// #else
|
||||||
|
if (window.navigator.userAgent.startsWith("SiYuan/")) {
|
||||||
|
if (isWindow()) {
|
||||||
|
return "desktop-window";
|
||||||
|
}
|
||||||
|
return "desktop";
|
||||||
|
} else {
|
||||||
|
return "browser-desktop";
|
||||||
|
}
|
||||||
|
/// #endif
|
||||||
|
};
|
||||||
|
|
||||||
export const isWindow = () => {
|
export const isWindow = () => {
|
||||||
return document.getElementById("toolbar") ? false : true;
|
return document.getElementById("toolbar") ? false : true;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue