Vanessa 2025-11-23 18:47:47 +08:00
parent 3cc93f2425
commit 22565b9006
12 changed files with 84 additions and 216 deletions

View file

@ -1051,25 +1051,6 @@ app.whenReady().then(() => {
ipcMain.on("siyuan-quit", (event, port) => {
exitApp(port);
});
ipcMain.on("siyuan-reload-window", (event, port) => {
BrowserWindow.getAllWindows().forEach((item) => {
try {
const currentURL = new URL(item.getURL());
if (port.toString() === currentURL.port.toString()) {
const hasMain = workspaces.find((workspaceItem) => {
if (workspaceItem.browserWindow.id === item.id) {
return true;
}
});
if (!hasMain) {
item.reload();
}
}
} catch (e) {
// load file is not a url
}
});
});
ipcMain.on("siyuan-show-window", (event) => {
const mainWindow = getWindowByContentId(event.sender.id);
if (!mainWindow) {

View file

@ -12,7 +12,6 @@ import {resetFloatDockSize} from "../layout/dock/util";
import {confirmDialog} from "../dialog/confirmDialog";
import {useShell} from "../util/pathName";
import {Dialog} from "../dialog";
import {reloadOtherWindow} from "../dialog/processSystem";
export const appearance = {
element: undefined as Element,
@ -207,46 +206,7 @@ export const appearance = {
msgTaskAssetDatabaseIndexCommitDisabled: statusBar ? statusBar.msgTaskAssetDatabaseIndexCommitDisabled : window.siyuan.config.appearance.statusBar.msgTaskAssetDatabaseIndexCommitDisabled,
msgTaskHistoryGenerateFileDisabled: statusBar ? statusBar.msgTaskHistoryGenerateFileDisabled : window.siyuan.config.appearance.statusBar.msgTaskHistoryGenerateFileDisabled,
}
}, async response => {
if (response.data.mode !== window.siyuan.config.appearance.mode ||
(response.data.mode === window.siyuan.config.appearance.mode && (
(response.data.mode === 0 && window.siyuan.config.appearance.themeLight !== response.data.themeLight) ||
(response.data.mode === 1 && window.siyuan.config.appearance.themeDark !== response.data.themeDark))
) || response.data.lang !== window.siyuan.config.appearance.lang) {
reloadOtherWindow();
}
if (window.siyuan.config.appearance.themeJS) {
if (response.data.mode !== window.siyuan.config.appearance.mode ||
(response.data.mode === window.siyuan.config.appearance.mode && (
(response.data.mode === 0 && window.siyuan.config.appearance.themeLight !== response.data.themeLight) ||
(response.data.mode === 1 && window.siyuan.config.appearance.themeDark !== response.data.themeDark))
)
) {
if (window.destroyTheme) {
try {
await window.destroyTheme();
window.destroyTheme = undefined;
document.getElementById("themeScript").remove();
} catch (e) {
console.error("destroyTheme error: " + e);
}
} else {
exportLayout({
errorExit: false,
cb() {
window.location.reload();
},
});
return;
}
}
}
appearance.onSetAppearance(response.data);
if (response.data.hideStatusBar) {
document.getElementById("status").classList.add("fn__none");
} else {
document.getElementById("status").classList.remove("fn__none");
}
}, () => {
resetFloatDockSize();
});
},

View file

@ -16,10 +16,7 @@ import {App} from "../index";
import {escapeAttr} from "../util/escape";
import {uninstall} from "../plugin/uninstall";
import {afterLoadPlugin, loadPlugin, loadPlugins, reloadPlugin} from "../plugin/loader";
import {loadAssets} from "../util/assets";
import {addScript} from "../protyle/util/addScript";
import {useShell} from "../util/pathName";
import {reloadOtherWindow} from "../dialog/processSystem";
export const bazaar = {
element: undefined as Element,
@ -674,28 +671,7 @@ export const bazaar = {
mode: dataObj.themeMode === "dark" ? 1 : 0,
frontend: getFrontend()
}, async response => {
if (window.siyuan.config.appearance.themeJS && bazaarType === "themes") {
if (window.destroyTheme) {
try {
await window.destroyTheme();
window.destroyTheme = undefined;
document.getElementById("themeScript").remove();
} catch (e) {
console.error("destroyTheme error: " + e);
}
window.siyuan.config.appearance = response.data.appearance;
loadAssets(window.siyuan.config.appearance);
} else {
exportLayout({
cb() {
window.location.reload();
},
errorExit: false,
});
return;
}
}
bazaar._onBazaar(response, bazaarType, ["themes", "icons"].includes(bazaarType));
bazaar._onBazaar(response, bazaarType);
bazaar._genMyHTML(bazaarType, app, false);
if (bazaarType === "plugins") {
if (window.siyuan.config.bazaar.petalDisabled) {
@ -757,45 +733,14 @@ export const bazaar = {
frontend: getFrontend()
}, async response => {
this._genMyHTML(bazaarType, app);
bazaar._onBazaar(response, bazaarType, ["icons"].includes(bazaarType));
bazaar._onBazaar(response, bazaarType);
// https://github.com/siyuan-note/siyuan/issues/15177
if (bazaarType === "themes" && response.data.appearance?.themeVer) {
window.siyuan.config.appearance.themeVer = response.data.appearance.themeVer;
}
// 更新主题后不需要对该主题进行切换 https://github.com/siyuan-note/siyuan/issues/4966
// https://github.com/siyuan-note/siyuan/issues/5411
if (bazaarType === "themes" && (
(window.siyuan.config.appearance.mode === 0 && window.siyuan.config.appearance.themeLight === dataObj.name) ||
(window.siyuan.config.appearance.mode === 1 && window.siyuan.config.appearance.themeDark === dataObj.name)
)) {
const currentTheme = window.siyuan.config.appearance.mode === 1 ? window.siyuan.config.appearance.themeDark : window.siyuan.config.appearance.themeLight;
if (window.siyuan.config.appearance.themeJS) {
if (window.destroyTheme) {
try {
await window.destroyTheme();
window.destroyTheme = undefined;
document.getElementById("themeScript").remove();
addScript(`/appearance/themes/${currentTheme}/theme.js?v=${response.data.appearance.themeVer}`, "themeScript");
} catch (e) {
console.error("destroyTheme error: " + e);
}
} else {
exportLayout({
cb() {
window.location.reload();
},
errorExit: false,
});
return;
}
}
if ((window.siyuan.config.appearance.mode === 1 && currentTheme === "midnight") ||
(window.siyuan.config.appearance.mode !== 1 && currentTheme === "daylight")) {
(document.getElementById("themeDefaultStyle") as HTMLLinkElement).href = `/appearance/themes/${window.siyuan.config.appearance.mode === 1 ? "midnight" : "daylight"}/theme.css?v=${Constants.SIYUAN_VERSION}`;
} else {
(document.getElementById("themeStyle") as HTMLLinkElement).href = `/appearance/themes/${currentTheme}/theme.css?v=${response.data.appearance.themeVer}`;
}
} else if (bazaarType === "plugins") {
if (bazaarType === "plugins") {
app.plugins.find((item: Plugin) => {
if (item.name === dataObj.name) {
reloadPlugin(app, {
@ -838,7 +783,7 @@ export const bazaar = {
frontend: getFrontend()
}, response => {
this._genMyHTML(bazaarType, app);
bazaar._onBazaar(response, bazaarType, ["themes", "icons"].includes(bazaarType));
bazaar._onBazaar(response, bazaarType);
});
});
}
@ -856,9 +801,8 @@ export const bazaar = {
this._genMyHTML(bazaarType, app, false);
fetchPost("/api/bazaar/getBazaarIcon", {}, response => {
response.data.appearance = appearanceResponse.data;
bazaar._onBazaar(response, "icons", true);
bazaar._onBazaar(response, "icons");
bazaar._data.icons = response.data.packages;
reloadOtherWindow();
});
});
} else if (bazaarType === "themes") {
@ -868,35 +812,10 @@ export const bazaar = {
themeDark: mode === 1 ? packageName : window.siyuan.config.appearance.themeDark,
themeLight: mode === 0 ? packageName : window.siyuan.config.appearance.themeLight,
}), async (appearanceResponse) => {
reloadOtherWindow();
if ((mode !== window.siyuan.config.appearance.mode ||
(mode === 1 && window.siyuan.config.appearance.themeDark !== packageName) ||
(mode === 0 && window.siyuan.config.appearance.themeLight !== packageName)) &&
window.siyuan.config.appearance.themeJS) {
if (window.destroyTheme) {
try {
await window.destroyTheme();
window.destroyTheme = undefined;
document.getElementById("themeScript").remove();
} catch (e) {
console.error("destroyTheme error: " + e);
}
window.siyuan.config.appearance = appearanceResponse.data;
loadAssets(window.siyuan.config.appearance);
} else {
exportLayout({
cb() {
window.location.reload();
},
errorExit: false,
});
return;
}
}
this._genMyHTML("themes", app, false);
fetchPost("/api/bazaar/getBazaarTheme", {}, response => {
response.data.appearance = appearanceResponse.data;
bazaar._onBazaar(response, "themes", true);
bazaar._onBazaar(response, "themes");
bazaar._data.themes = response.data.packages;
});
});
@ -993,29 +912,29 @@ export const bazaar = {
if (!item.getAttribute("data-init")) {
if (type === "template") {
fetchPost("/api/bazaar/getBazaarTemplate", {}, response => {
bazaar._onBazaar(response, "templates", false);
bazaar._onBazaar(response, "templates");
bazaar._data.templates = response.data.packages;
});
} else if (type === "icon") {
fetchPost("/api/bazaar/getBazaarIcon", {}, response => {
bazaar._onBazaar(response, "icons", false);
bazaar._onBazaar(response, "icons");
bazaar._data.icons = response.data.packages;
});
} else if (type === "widget") {
fetchPost("/api/bazaar/getBazaarWidget", {}, response => {
bazaar._onBazaar(response, "widgets", false);
bazaar._onBazaar(response, "widgets");
bazaar._data.widgets = response.data.packages;
});
} else if (type === "theme") {
fetchPost("/api/bazaar/getBazaarTheme", {}, response => {
bazaar._onBazaar(response, "themes", false);
bazaar._onBazaar(response, "themes");
bazaar._data.themes = response.data.packages;
});
} else if (type === "plugin") {
fetchPost("/api/bazaar/getBazaarPlugin", {
frontend: getFrontend()
}, response => {
bazaar._onBazaar(response, "plugins", false);
bazaar._onBazaar(response, "plugins");
bazaar._data.plugins = response.data.packages;
});
}
@ -1048,22 +967,22 @@ export const bazaar = {
const type = (hasClosestByClassName(inputElement, "config-bazaar__panel") as HTMLElement).getAttribute("data-type");
if (type === "template") {
fetchPost("/api/bazaar/getBazaarTemplate", {keyword}, response => {
bazaar._onBazaar(response, "templates", false);
bazaar._onBazaar(response, "templates");
bazaar._data.templates = response.data.packages;
});
} else if (type === "icon") {
fetchPost("/api/bazaar/getBazaarIcon", {keyword}, response => {
bazaar._onBazaar(response, "icons", false);
bazaar._onBazaar(response, "icons");
bazaar._data.icons = response.data.packages;
});
} else if (type === "widget") {
fetchPost("/api/bazaar/getBazaarWidget", {keyword}, response => {
bazaar._onBazaar(response, "widgets", false);
bazaar._onBazaar(response, "widgets");
bazaar._data.widgets = response.data.packages;
});
} else if (type === "theme") {
fetchPost("/api/bazaar/getBazaarTheme", {keyword}, response => {
bazaar._onBazaar(response, "themes", false);
bazaar._onBazaar(response, "themes");
bazaar._data.themes = response.data.packages;
});
} else if (type === "plugin") {
@ -1071,7 +990,7 @@ export const bazaar = {
frontend: getFrontend(),
keyword
}, response => {
bazaar._onBazaar(response, "plugins", false);
bazaar._onBazaar(response, "plugins");
bazaar._data.plugins = response.data.packages;
});
} else if (type === "downloaded") {
@ -1148,7 +1067,7 @@ export const bazaar = {
});
});
},
_onBazaar(response: IWebSocketData, bazaarType: TBazaarType, reload: boolean) {
_onBazaar(response: IWebSocketData, bazaarType: TBazaarType) {
if (bazaar.element.querySelector("#configBazaarReadme").classList.contains("config-bazaar__readme--show")) {
const dataObj = JSON.parse(bazaar.element.querySelector("#configBazaarReadme > .item__side").getAttribute("data-obj"));
bazaar._renderReadme((dataObj.bazaarType) as TBazaarType,
@ -1206,8 +1125,5 @@ export const bazaar = {
html += '<div class="fn__flex-1" style="margin-left: 15px;min-width: 342px;"></div><div class="fn__flex-1" style="margin-left: 15px;min-width: 342px;"></div>';
}
element.innerHTML = `<div class="b3-cards">${html}</div>`;
if (reload) {
appearance.onSetAppearance(response.data.appearance);
}
}
};

View file

@ -3,7 +3,6 @@ import {Dialog} from "../../dialog";
import {objEquals} from "../../util/functions";
import {confirmDialog} from "../../dialog/confirmDialog";
import {Constants} from "../../constants";
import {reloadOtherWindow} from "../../dialog/processSystem";
export const renderSnippet = () => {
fetchPost("/api/snippet/getSnippet", {type: "all", enabled: 2}, (response) => {
@ -225,10 +224,7 @@ const setSnippetPost = (dialog: Dialog, snippets: ISnippet[], removeIds: string[
});
window.siyuan.config.snippet.enabledCSS = (dialog.element.querySelector('.b3-switch[data-action="toggleCSS"]') as HTMLInputElement).checked;
window.siyuan.config.snippet.enabledJS = (dialog.element.querySelector('.b3-switch[data-action="toggleJS"]') as HTMLInputElement).checked;
fetchPost("/api/setting/setSnippet", window.siyuan.config.snippet, () => {
reloadOtherWindow();
});
renderSnippet();
fetchPost("/api/setting/setSnippet", window.siyuan.config.snippet);
dialog.destroy({cancel: "true"});
});
};

View file

@ -0,0 +1,40 @@
import IAppearance = Config.IAppearance;
import {exportLayout} from "../../layout/util";
import {appearance} from "../appearance";
export const updateAppearance = async (data:IAppearance) => {
if (window.siyuan.config.appearance.themeJS) {
if (data.mode !== window.siyuan.config.appearance.mode ||
(data.mode === window.siyuan.config.appearance.mode && (
(data.mode === 0 && window.siyuan.config.appearance.themeLight !== data.themeLight) ||
(data.mode === 1 && window.siyuan.config.appearance.themeDark !== data.themeDark))
)
) {
if (window.destroyTheme) {
try {
await window.destroyTheme();
window.destroyTheme = undefined;
document.getElementById("themeScript").remove();
} catch (e) {
console.error("destroyTheme error: " + e);
}
} else {
exportLayout({
errorExit: false,
cb() {
window.location.reload();
},
});
return;
}
}
}
if (data.hideStatusBar !== window.siyuan.config.appearance.hideStatusBar) {
if (data.hideStatusBar) {
document.getElementById("status").classList.add("fn__none");
} else {
document.getElementById("status").classList.remove("fn__none");
}
}
appearance.onSetAppearance(data);
}

View file

@ -57,7 +57,6 @@ export abstract class Constants {
public static readonly SIYUAN_CONTEXT_MENU: string = "siyuan-context-menu";
public static readonly SIYUAN_SHOW_WINDOW: string = "siyuan-show-window";
public static readonly SIYUAN_RELOAD_WINDOW: string = "siyuan-reload-window";
// custom
public static readonly CUSTOM_SY_READONLY: string = "custom-sy-readonly";

View file

@ -280,12 +280,6 @@ export const kernelError = () => {
}
};
export const reloadOtherWindow = () => {
/// #if !BROWSER
ipcRenderer.send(Constants.SIYUAN_RELOAD_WINDOW, location.port);
/// #endif
};
export const exitSiYuan = async () => {
hideAllElements(["util"]);
/// #if MOBILE

View file

@ -38,6 +38,8 @@ import {setLocalShorthandCount} from "./util/noRelyPCFunction";
import {getDockByType} from "./layout/tabUtil";
import {Tag} from "./layout/dock/Tag";
import {updateControlAlt} from "./protyle/util/hotKey";
import {updateAppearance} from "./config/util/updateAppearance";
import {renderSnippet} from "./config/util/snippets";
export class App {
public plugins: import("./plugin").Plugin[] = [];
@ -69,6 +71,12 @@ export class App {
});
if (data) {
switch (data.cmd) {
case "setAppearance":
updateAppearance(data.data);
break;
case "setSnippet":
renderSnippet();
break;
case "setDefRefCount":
setDefRefCount(data.data);
break;

View file

@ -1,7 +1,6 @@
import {fetchPost} from "../../util/fetch";
import {genLangOptions, genOptions} from "../../util/genOptions";
import {openModel} from "../menu/model";
import {reloadOtherWindow} from "../../dialog/processSystem";
export const initAppearance = () => {
openModel({
@ -55,10 +54,7 @@ export const initAppearance = () => {
themeDark: (modelMainElement.querySelector("#themeDark") as HTMLSelectElement).value,
themeLight: (modelMainElement.querySelector("#themeLight") as HTMLSelectElement).value,
lang: (modelMainElement.querySelector("#lang") as HTMLSelectElement).value,
}), () => {
reloadOtherWindow();
window.location.reload();
});
}));
});
});
}

View file

@ -11,10 +11,17 @@ import {reloadPlugin} from "../../plugin/loader";
import {reloadEmoji} from "../../emoji";
import {setLocalShorthandCount} from "../../util/noRelyPCFunction";
import {updateControlAlt} from "../../protyle/util/hotKey";
import {renderSnippet} from "../../config/util/snippets";
export const onMessage = (app: App, data: IWebSocketData) => {
if (data) {
switch (data.cmd) {
case "setAppearance":
window.location.reload();
break;
case "setSnippet":
renderSnippet();
break;
case "setDefRefCount":
setDefRefCount(data.data);
break;

View file

@ -6,9 +6,7 @@ import {getAllModels} from "../layout/getAll";
import {exportLayout} from "../layout/util";
/// #endif
import {fetchPost} from "./fetch";
import {appearance} from "../config/appearance";
import {isInAndroid, isInHarmony, isInIOS, isIPad, isIPhone, isMac, isWin11} from "../protyle/util/compatibility";
import {reloadOtherWindow} from "../dialog/processSystem";
export const loadAssets = (data: Config.IAppearance) => {
const htmlElement = document.getElementsByTagName("html")[0];
@ -357,42 +355,7 @@ export const setMode = (modeElementValue: number) => {
fetchPost("/api/setting/setAppearance", Object.assign({}, window.siyuan.config.appearance, {
mode,
modeOS: modeElementValue === 2,
}), async response => {
if (response.data.mode !== window.siyuan.config.appearance.mode ||
(response.data.mode === window.siyuan.config.appearance.mode && (
(response.data.mode === 0 && window.siyuan.config.appearance.themeLight !== response.data.themeLight) ||
(response.data.mode === 1 && window.siyuan.config.appearance.themeDark !== response.data.themeDark))
)) {
reloadOtherWindow();
}
if (window.siyuan.config.appearance.themeJS) {
if (response.data.mode !== window.siyuan.config.appearance.mode ||
(response.data.mode === window.siyuan.config.appearance.mode && (
(response.data.mode === 0 && window.siyuan.config.appearance.themeLight !== response.data.themeLight) ||
(response.data.mode === 1 && window.siyuan.config.appearance.themeDark !== response.data.themeDark))
)
) {
if (window.destroyTheme) {
try {
await window.destroyTheme();
window.destroyTheme = undefined;
document.getElementById("themeScript").remove();
} catch (e) {
console.error("destroyTheme error: " + e);
}
} else {
exportLayout({
errorExit: false,
cb() {
window.location.reload();
},
});
return;
}
}
}
appearance.onSetAppearance(response.data);
});
}));
/// #endif
};

View file

@ -27,6 +27,8 @@ import {loadPlugins, reloadPlugin} from "../plugin/loader";
import {hideAllElements} from "../protyle/ui/hideElements";
import {reloadEmoji} from "../emoji";
import {updateControlAlt} from "../protyle/util/hotKey";
import {updateAppearance} from "../config/util/updateAppearance";
import {renderSnippet} from "../config/util/snippets";
class App {
public plugins: import("../plugin").Plugin[] = [];
@ -56,6 +58,12 @@ class App {
});
if (data) {
switch (data.cmd) {
case "setAppearance":
updateAppearance(data.data);
break;
case "setSnippet":
renderSnippet();
break;
case "setDefRefCount":
setDefRefCount(data.data);
break;