Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Unify frontend platform identification into body class names

Jeffrey Chen06d99c47d66f
diff --git a/AGENTS.md b/AGENTS.md
index 005c8922db..3c59a84bdf 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -151,7 +151,8 @@ Unambiguous mechanical edits with no behavioral or compatibility impact need no
4. **Markdown:** Do not hand-wrap; keep each line (paragraphs, table rows, list items, etc.) on a single line
5. **TypeScript/JavaScript:** Semicolons required, use double quotes, indent with spaces
- When moving or extracting a symbol into another module, update all affected imports to reference its defining module directly. Do not leave forwarding re-exports in the original module merely to avoid updating callers
-6. **CSS:** Do not use the `:has()` selector because of its performance impact
+6. **CSS:** Do not use the `:has()` selector because of its performance impact, and prefer a comma-separated selector list over `:is()`, whose extra matching layer adds measurable cost
+ - Expand selector groups instead of grouping them with `:is()` or `:where()`; use `:where()` only to drop specificity from a single selector
- Before adding or styling a basic control, inspect and reuse the existing component, markup pattern, and shared styles in `app/src/assets/scss/component/` (for example, `b3-button`, `b3-select`, and `b3-text-field`), including existing modifiers; use `block__icon` for established icon-button patterns
- Apply the same reuse-first rule to menus, dialogs, tooltips, and drag interactions: inspect existing implementations and APIs before adding a feature-specific replacement
- For single-choice enumerations in menus, use submenu items with the current option checked rather than embedding a select control. Show a right-arrow indicator on the parent item, open its submenu on hover on desktop, and support tapping on mobile. Reuse the existing menu implementation and positioning behavior
@@ -170,6 +171,12 @@ Unambiguous mechanical edits with no behavioral or compatibility impact need no
- Read preferences from `window.siyuan.storage`; when changing a preference, update its in-memory value and persist it with `setStorageVal` from `app/src/protyle/util/compatibility.ts`
- SiYuan persists these values in the workspace's `data/storage/local.json`; do not use browser `storage` events to observe changes to this store
+10. **Frontend platform identification:**
+ - Use the mutually exclusive `body` class names written by `applyPlatformClasses()` in `app/src/protyle/util/compatibility.ts`: `body--mac`, `body--windows`, `body--linux`, `body--ios`, `body--android`, and `body--harmony`
+ - `body--win32` and `body--win32-browser` are retained only for existing third-party themes; use neither in new code, and do not add consumers when changing related styles
+ - Do not derive the frontend platform from the kernel reported container or from `data-backend`: a remote kernel reports its own host, so both differ from the platform of the current frontend
+ - `data-frontend` on the root element reports the frontend form (`desktop`, `desktop-window`, `mobile`, `browser-desktop`, `browser-mobile`) and may be used by built-in styles and third-party theme CSS; `data-backend` on the root element is for third-party JavaScript only and must not appear in built-in CSS
+
---
## 4. Required toolchain
diff --git a/app/src/assets/scss/component/_select.scss b/app/src/assets/scss/component/_select.scss
index e6f473d3a4..8d5b7f8136 100644
--- a/app/src/assets/scss/component/_select.scss
+++ b/app/src/assets/scss/component/_select.scss
@@ -32,8 +32,9 @@
}
}
- // 仅 Windows 桌面端与浏览器启用 base-select 统一样式
- .body--win32 &, .body--win32-browser & {
+ // Windows 与 Linux 启用 base-select 统一样式,具体能力由 @supports 判定
+ .body--windows &,
+ .body--linux & {
@supports (appearance: base-select) {
appearance: base-select;
white-space: nowrap;
diff --git a/app/src/assets/scss/main/_main.scss b/app/src/assets/scss/main/_main.scss
index fbde396c04..ff9f1ae7cf 100644
--- a/app/src/assets/scss/main/_main.scss
+++ b/app/src/assets/scss/main/_main.scss
@@ -69,17 +69,23 @@ body {
}
html[data-frontend="browser-desktop"] {
- .fullscreen > .protyle-breadcrumb,
- .fullscreen > .block__icons {
- padding-left: calc(env(titlebar-area-x, 0px) + 8px);
- padding-right: calc(100% - env(titlebar-area-width, 100%) - env(titlebar-area-x, 0px) + 8px);
- height: calc(env(titlebar-area-height, var(--b3-ui-browser-titlebar-height, 31px)) + 1px);
+ .fullscreen {
+ > .protyle-breadcrumb,
+ > .block__icons {
+ padding-left: calc(env(titlebar-area-x, 0px) + 8px);
+ padding-right: calc(100% - env(titlebar-area-width, 100%) - env(titlebar-area-x, 0px) + 8px);
+ height: calc(env(titlebar-area-height, var(--b3-ui-browser-titlebar-height, 31px)) + 1px);
+ }
}
}
// 移动设备的桌面布局不预留 macOS 窗口按钮空间,iPad 窗口控件按原生上报的宽度避让。
-:root:is([data-backend="android"], [data-backend="ios"], [data-backend="harmony"]) .fullscreen {
- --b3-toolbar-left-mac: calc(var(--ios-window-controls-left, 0px) + 8px);
+body.body--android,
+body.body--ios,
+body.body--harmony {
+ .fullscreen {
+ --b3-toolbar-left-mac: calc(var(--ios-window-controls-left, 0px) + 8px);
+ }
}
// 仅顶部工具栏避让原生窗口控件,正文与侧栏不增加横向留白。
diff --git a/app/src/assets/scss/util/_reset.scss b/app/src/assets/scss/util/_reset.scss
index 7cbf3bd124..87f0c7848e 100644
--- a/app/src/assets/scss/util/_reset.scss
+++ b/app/src/assets/scss/util/_reset.scss
@@ -20,7 +20,7 @@ html {
// iOS 使用固定蓝色光标,改善系统与应用明暗模式不同组合下的输入法候选字对比度。
// https://github.com/siyuan-note/siyuan/issues/20005
-:root[data-ios] {
+body.body--ios {
caret-color: #3575f0;
}
@@ -83,7 +83,9 @@ body {
}
}
- &.body--win32 {
+ // 非 macOS 平台不预留 macOS 窗口按钮空间
+ &.body--windows,
+ &.body--linux {
--b3-toolbar-left-mac: 8px;
.toolbar {
padding: 0 0 0 5px;
@@ -109,7 +111,7 @@ body {
}
}
- &.body--win32 .fullscreen {
+ &:not(.body--mac) .fullscreen {
& > .protyle-breadcrumb,
& > .block__icons {
padding-right: 168px;
diff --git a/app/src/boot/onGetConfig.ts b/app/src/boot/onGetConfig.ts
index 56c7c4f5bd..b21fefa1b5 100644
--- a/app/src/boot/onGetConfig.ts
+++ b/app/src/boot/onGetConfig.ts
@@ -1,6 +1,6 @@
import {adjustLayout, exportLayout, JSONToLayout, resetLayout, resizeTopBar} from "../layout/util";
import {resizeTabs, setTabPosition} from "../layout/tabUtil";
-import {initWindowOpenOverride, isMac, isWindows, setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
+import {applyPlatformClasses, initWindowOpenOverride, isMac, setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
/// #if !BROWSER
import {initNativeDialogOverride} from "../protyle/util/compatibility";
/// #endif
@@ -71,7 +71,7 @@ export const initDesktopHost = async () => {
export const onGetConfig = async (isStart: boolean, app: App) => {
correctHotkey(app);
- document.body.classList.toggle("body--windows", isWindows());
+ applyPlatformClasses();
/// #if !BROWSER
await initDesktopHost();
webFrame.setZoomFactor(window.siyuan.storage[Constants.LOCAL_ZOOM]);
@@ -386,8 +386,6 @@ ${response.data.replace("%pages", "<span class=totalPages></span>").replace("%pa
}
if (!isMac()) {
- document.body.classList.add("body--win32");
-
const controls = isWindow() ? document.querySelector<HTMLElement>(".toolbar__window") : document.getElementById("windowControls");
if (!isWindow()) controls.replaceChildren();
initWindowControls(controls, () => {
@@ -402,8 +400,5 @@ ${response.data.replace("%pages", "<span class=totalPages></span>").replace("%pa
if (!isWindow()) {
document.querySelector(".toolbar").classList.add("toolbar--browser");
}
- if (isWindows()) {
- document.body.classList.add("body--win32-browser");
- }
/// #endif
};
diff --git a/app/src/config/setting/window.ts b/app/src/config/setting/window.ts
index daca6945d3..9367ff593f 100644
--- a/app/src/config/setting/window.ts
+++ b/app/src/config/setting/window.ts
@@ -6,7 +6,7 @@ import {Menus} from "../../menus";
import {genUUID} from "../../util/genID";
import {fetchSyncPost} from "../../util/fetch";
import {addBaseURL, redirectToCheckAuth} from "../../util/pathName";
-import {getLocalStorage, initNativeDialogOverride, initWindowOpenOverride, isMac, isWindows} from "../../protyle/util/compatibility";
+import {getLocalStorage, initNativeDialogOverride, initWindowOpenOverride, applyPlatformClasses} from "../../protyle/util/compatibility";
import {addScriptSync} from "../../protyle/util/addScript";
import {ensureLute} from "../../protyle/util/lute";
import {loadDesktopHostConnection, initDesktopHost} from "../../boot/onGetConfig";
@@ -198,8 +198,7 @@ const initialize = async () => {
if (!isActive()) return;
listen(Constants.SIYUAN_SEND_WINDOWS, (_event, data: IWebSocketData) => onWindowsMsg(data));
runtime.applyZoom();
- document.body.classList.toggle("body--windows", isWindows());
- document.body.classList.toggle("body--win32", !isMac());
+ applyPlatformClasses();
listen(Constants.SIYUAN_EVENT, (_event, command: string) => applyWindowState(command));
ipcRenderer.send(Constants.SIYUAN_EVENT);
const [fullscreen, maximized] = await Promise.all([
diff --git a/app/src/constants.ts b/app/src/constants.ts
index 93f6b39af7..8ee193fa6e 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -103,7 +103,6 @@ export abstract class Constants {
public static readonly ATTRIBUTE_MENU_KEYMAP = "data-menu-keymap";
// 界面密度标记仅用于根元素,不写入笔记内容。
public static readonly ATTRIBUTE_UI_DENSITY = "data-ui-density";
- public static readonly ATTRIBUTE_IOS = "data-ios";
// size
public static readonly SIZE_DATABASE_MAZ_SIZE: number = 102400;
diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts
index ecb4cf6b98..33df69feb7 100644
--- a/app/src/mobile/index.ts
+++ b/app/src/mobile/index.ts
@@ -40,10 +40,10 @@ import {
showKeyboardToolbar,
} from "./util/keyboardToolbar";
import {
+ applyPlatformClasses,
getLocalStorage,
initWindowOpenOverride,
isChromeBrowser,
- isInAndroid,
isInIOS,
isInMobileApp,
isIOSDevice,
@@ -217,7 +217,7 @@ class App {
addScript(`${Constants.PROTYLE_CDN}/js/protyle-html.js?v=${Constants.SIYUAN_VERSION}`, "protyleWcHtmlScript");
window.siyuan.config = systemConfig(confResponse.data.conf);
window.siyuan.isPublish = confResponse.data.isPublish;
- document.body.classList.toggle("body--android", Boolean(isInAndroid()));
+ applyPlatformClasses();
correctHotkey(siyuanApp);
await loadPlugins(this);
getLocalStorage(() => {
diff --git a/app/src/protyle/util/compatibility.test.ts b/app/src/protyle/util/compatibility.test.ts
index 1e450d7980..3e6c35e0d8 100644
--- a/app/src/protyle/util/compatibility.test.ts
+++ b/app/src/protyle/util/compatibility.test.ts
@@ -5,6 +5,7 @@ import {join} from "node:path";
import {runInNewContext} from "node:vm";
import * as ts from "typescript";
import * as clipboardData from "./clipboardData";
+import * as browserCompatibility from "./browserCompatibility";
const source = ts.transpileModule(readFileSync(join(process.cwd(), "src/protyle/util/compatibility.ts"), "utf8"), {
compilerOptions: {module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022},
@@ -85,3 +86,137 @@ describe("Harmony clipboard bridge", () => {
assert.equal((await createHarness(false, true).api.writeClipboardData(data)).status, "plain");
});
});
+
+const createPlatformHarness = (clientNavigator: {userAgent: string; platform: string; maxTouchPoints: number},
+ options: {browser?: boolean; container?: string} = {}) => {
+ const classes = new Set<string>();
+ const attributes: Record<string, string> = {};
+ const module = {exports: {}};
+ runInNewContext(source, {
+ module, exports: module.exports, console,
+ require: (id: string) => {
+ if (id === "./clipboardData") {
+ return clipboardData;
+ }
+ if (id === "./browserCompatibility") {
+ return browserCompatibility;
+ }
+ if (id === "../../util/functions") {
+ return {getFrontend: () => "desktop", isBrowser: () => Boolean(options.browser)};
+ }
+ return {};
+ },
+ navigator: clientNavigator,
+ window: {
+ siyuan: {
+ config: {system: {container: options.container || "std"}},
+ languages: {clipboardPermissionDenied: "Denied"},
+ },
+ },
+ document: {
+ body: {
+ classList: {
+ toggle: (name: string, force?: boolean) => {
+ if (force) {
+ classes.add(name);
+ } else {
+ classes.delete(name);
+ }
+ },
+ },
+ },
+ documentElement: {setAttribute: (name: string, value: string) => { attributes[name] = value; }},
+ },
+ });
+ return {api: module.exports as typeof import("./compatibility"), classes, attributes};
+};
+
+describe("frontend platform classes", () => {
+ const windowsUA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36";
+ const linuxUA = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36";
+ const cases = [
+ {
+ name: "a HarmonyOS phone", expected: "body--harmony",
+ navigator: {
+ userAgent: "Mozilla/5.0 (Phone; OpenHarmony 5.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 ArkWeb/4.1.6.1 Mobile",
+ platform: "Linux armv8l", maxTouchPoints: 5,
+ },
+ },
+ {
+ name: "a HarmonyOS 2in1 device", expected: "body--harmony",
+ navigator: {
+ userAgent: "Mozilla/5.0 (PC; OpenHarmony 5.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 ArkWeb/4.1.6.1",
+ platform: "Linux x86_64", maxTouchPoints: 0,
+ },
+ },
+ {
+ name: "a HarmonyOS UA carrying an Android compatibility field", expected: "body--harmony",
+ navigator: {
+ userAgent: "Mozilla/5.0 (Linux; Android 12; OpenHarmony 5.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36",
+ platform: "Linux armv8l", maxTouchPoints: 5,
+ },
+ },
+ {
+ name: "an older HarmonyOS built on an Android kernel", expected: "body--android",
+ navigator: {
+ userAgent: "Mozilla/5.0 (Linux; Android 10; HarmonyOS; AGS6-W09; HMSCore 6.16.4.352) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.0.0 Safari/537.36",
+ platform: "Linux armv8l", maxTouchPoints: 5,
+ },
+ },
+ {
+ name: "an iPhone", expected: "body--ios",
+ navigator: {
+ userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 18_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile/15E148 Safari/604.1",
+ platform: "iPhone", maxTouchPoints: 5,
+ },
+ },
+ {
+ name: "an iPad reporting a Macintosh platform", expected: "body--ios",
+ navigator: {
+ userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15",
+ platform: "MacIntel", maxTouchPoints: 5,
+ },
+ },
+ {
+ name: "an Android client", expected: "body--android",
+ navigator: {
+ userAgent: "Mozilla/5.0 (Linux; Android 15; Pixel 9) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Mobile Safari/537.36",
+ platform: "Linux armv8l", maxTouchPoints: 5,
+ },
+ },
+ {
+ name: "macOS", expected: "body--mac",
+ navigator: {
+ userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15",
+ platform: "MacIntel", maxTouchPoints: 0,
+ },
+ },
+ {name: "Windows", expected: "body--windows", navigator: {userAgent: windowsUA, platform: "Win32", maxTouchPoints: 0}},
+ {name: "Linux", expected: "body--linux", navigator: {userAgent: linuxUA, platform: "Linux x86_64", maxTouchPoints: 0}},
+ ];
+ cases.forEach(item => {
+ it(`resolves ${item.expected} for ${item.name}`, () => {
+ assert.equal(createPlatformHarness(item.navigator).api.resolvePlatformClass(), item.expected);
+ });
+ });
+
+ it("keeps the platform classes mutually exclusive and writes the frontend marker", () => {
+ const harness = createPlatformHarness({userAgent: windowsUA, platform: "Win32", maxTouchPoints: 0}, {browser: true});
+ harness.api.applyPlatformClasses();
+ assert.deepEqual([...harness.classes].sort(), ["body--win32-browser", "body--windows"]);
+ assert.equal(harness.attributes["data-frontend"], "desktop");
+ });
+
+ it("ignores the kernel container when resolving the platform", () => {
+ const harness = createPlatformHarness({userAgent: windowsUA, platform: "Win32", maxTouchPoints: 0}, {container: "ios"});
+ assert.equal(harness.api.resolvePlatformClass(), "body--windows");
+ });
+
+ it("keeps the legacy Electron class names for existing themes", () => {
+ const harness = createPlatformHarness({userAgent: linuxUA, platform: "Linux x86_64", maxTouchPoints: 0});
+ harness.api.applyPlatformClasses();
+ assert.ok(harness.classes.has("body--linux"));
+ assert.ok(harness.classes.has("body--win32"));
+ assert.ok(!harness.classes.has("body--win32-browser"));
+ });
+});
diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts
index 8699381e5a..edd376d58e 100644
--- a/app/src/protyle/util/compatibility.ts
+++ b/app/src/protyle/util/compatibility.ts
@@ -8,7 +8,7 @@ import {ipcRenderer} from "electron";
import {getDefaultSubType, getDefaultType, normalizeSearchTypes} from "../../search/getDefault";
import {hideMessage, showMessage} from "../../dialog/message";
import {isEncryptedBox, isSiYuanUriProtocol} from "../../util/pathName";
-import {isBrowser} from "../../util/functions";
+import {getFrontend, isBrowser} from "../../util/functions";
import type {App} from "../../index";
import {genUUID} from "../../util/genID";
import {buildBlockDOMClipboardData} from "./blockDOMClipboard";
@@ -651,6 +651,47 @@ export function isChromeBrowser(): boolean {
return isChromium && !isEdge && !isOpera;
}
+// 鸿蒙 WebView 用 OpenHarmony 标识操作系统,部分浏览器 UA 还会带上兼容的操作系统名
+// 因此该判断必须先于 Android 等平台判断,老版本 Android 内核鸿蒙不含此标识,按 Android 处理
+const isHarmonyOS = () => {
+ return /OpenHarmony/i.test(navigator.userAgent);
+};
+
+const PLATFORM_CLASSES = ["body--mac", "body--windows", "body--linux", "body--ios", "body--android", "body--harmony"];
+
+// 当前前端所在平台,取值互斥;只依据前端自身信息判断,不受内核上报的运行容器影响
+export const resolvePlatformClass = () => {
+ if (isHarmonyOS()) {
+ return "body--harmony";
+ }
+ if (isIOSDevice()) {
+ return "body--ios";
+ }
+ if (isAndroid()) {
+ return "body--android";
+ }
+ if (isMac()) {
+ return "body--mac";
+ }
+ if (isWindows()) {
+ return "body--windows";
+ }
+ return "body--linux";
+};
+
+// 平台类名集中在此写入,主窗口、独立窗口、设置窗口与移动端四个入口均需调用
+export const applyPlatformClasses = () => {
+ const platformClass = resolvePlatformClass();
+ PLATFORM_CLASSES.forEach(item => {
+ document.body.classList.toggle(item, item === platformClass);
+ });
+ // 前端形态标记供内置样式与第三方主题使用,在此提前写入,避免平台相关样式在首帧按浏览器端判断
+ document.documentElement.setAttribute("data-frontend", getFrontend());
+ // 下面两个类名仅供旧第三方主题使用,内置样式已改用上方平台类名,待主题迁移完成后移除
+ document.body.classList.toggle("body--win32", !isBrowser() && !isMac());
+ document.body.classList.toggle("body--win32-browser", isBrowser() && isWindows());
+};
+
export const updateHotkeyAfterTip = (hotkey: string, split = " ") => {
if (hotkey) {
return split + updateHotkeyTip(hotkey);
diff --git a/app/src/util/appearanceAssets.test.ts b/app/src/util/appearanceAssets.test.ts
index d81395cdbe..4dcc78f68e 100644
--- a/app/src/util/appearanceAssets.test.ts
+++ b/app/src/util/appearanceAssets.test.ts
@@ -75,7 +75,7 @@ const createAssets = (ensureLute: () => Promise<void> = async () => {}, client:
},
require: (name: string) => {
if (name === "../constants") {
- return {Constants: {SIYUAN_VERSION: "3.8.5", LOCAL_PDFTHEME: "pdf", ATTRIBUTE_IOS: "data-ios"}};
+ return {Constants: {SIYUAN_VERSION: "3.8.5", LOCAL_PDFTHEME: "pdf"}};
}
if (name === "./hostCapabilities") {
return {getHostCapabilities: () => ({customAppearance: true})};
@@ -110,24 +110,24 @@ const createAssets = (ensureLute: () => Promise<void> = async () => {}, client:
return {assets: moduleExports, appearance, elements, html, errors, scriptURLs, removedElements};
};
-test("appearance identifies the iOS client independently of the backend and layout", async () => {
+test("appearance exposes the kernel backend and the browser frontend independently", async () => {
const cases = [
- {name: "Windows client with iOS backend", backend: "ios", mobile: false, ios: false,
+ {name: "Windows client with iOS backend", backend: "ios", mobile: false,
navigator: {userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64)", platform: "Win32", maxTouchPoints: 0}},
- {name: "macOS client with iOS backend", backend: "ios", mobile: false, ios: false,
+ {name: "macOS client with iOS backend", backend: "ios", mobile: false,
navigator: {userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)", platform: "MacIntel", maxTouchPoints: 0}},
- {name: "Android client with iOS backend", backend: "ios", mobile: true, ios: false,
+ {name: "Android client with iOS backend", backend: "ios", mobile: true,
navigator: {userAgent: "Mozilla/5.0 (Linux; Android 15; Pixel 9)", platform: "Linux armv8l", maxTouchPoints: 5}},
- {name: "iPhone client with Linux backend", backend: "linux", mobile: true, ios: true,
+ {name: "iPhone client with Linux backend", backend: "linux", mobile: true,
navigator: {userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 18_6 like Mac OS X)", platform: "iPhone", maxTouchPoints: 5}},
- {name: "iPad desktop client with Linux backend", backend: "linux", mobile: false, ios: true,
+ {name: "iPad desktop client with Linux backend", backend: "linux", mobile: false,
navigator: {userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15)", platform: "MacIntel", maxTouchPoints: 5}},
];
for (const scenario of cases) {
const {assets, appearance, html} = createAssets(undefined, scenario);
await assets.loadAssets(appearance);
assert.equal(html.getAttribute("data-backend"), scenario.backend, scenario.name);
- assert.equal("data-ios" in html.attributes, scenario.ios, scenario.name);
+ assert.equal(html.getAttribute("data-frontend"), scenario.mobile ? "browser-mobile" : "browser-desktop", scenario.name);
}
});
diff --git a/app/src/util/assets.ts b/app/src/util/assets.ts
index 95ffe8ddf9..58d34f2c0c 100644
--- a/app/src/util/assets.ts
+++ b/app/src/util/assets.ts
@@ -33,7 +33,6 @@ import {refreshChartTheme} from "../protyle/render/chartRender";
import {getHostCapabilities} from "./hostCapabilities";
import {initSelectionStyle} from "./selectionStyle";
import {applyCompactMode} from "../config/tabs/compactMode";
-import {isIOSPlatform} from "../protyle/util/browserCompatibility";
let headingNumberMeasurementRefreshTimer: number;
let appearanceUpdate = Promise.resolve();
@@ -152,9 +151,9 @@ export const loadAssets = async (appearance: Config.IAppearance) => {
const themeMode = getThemeMode();
htmlElement.setAttribute("lang", window.siyuan.config.appearance.lang);
applyCompactMode();
+ // data-frontend 也会由 applyPlatformClasses 提前写入,此处保持为外观刷新时的权威来源
htmlElement.setAttribute("data-frontend", getFrontend()); // https://github.com/siyuan-note/siyuan/issues/12549
htmlElement.setAttribute("data-backend", getBackend());
- htmlElement.toggleAttribute(Constants.ATTRIBUTE_IOS, isIOSPlatform(window.navigator));
htmlElement.setAttribute("data-theme-mode", themeMode);
htmlElement.setAttribute("data-light-theme", data.themeLight);
htmlElement.setAttribute("data-dark-theme", data.themeDark);
diff --git a/app/src/window/init.ts b/app/src/window/init.ts
index ad88d648b2..073756a192 100644
--- a/app/src/window/init.ts
+++ b/app/src/window/init.ts
@@ -12,7 +12,7 @@ import {initDesktopHost, initWindow} from "../boot/onGetConfig";
import type {App} from "../index";
import {afterLayoutReady} from "../plugin/loader";
import {Tab} from "../layout/Tab";
-import {initWindowOpenOverride} from "../protyle/util/compatibility";
+import {applyPlatformClasses, initWindowOpenOverride} from "../protyle/util/compatibility";
/// #if !BROWSER
import {initNativeDialogOverride} from "../protyle/util/compatibility";
/// #endif
@@ -23,6 +23,7 @@ import {Wnd} from "../layout/Wnd";
export const init = async (app: App) => {
+ applyPlatformClasses();
await initDesktopHost();
webFrame.setZoomFactor(window.siyuan.storage[Constants.LOCAL_ZOOM]);
const position = Constants.SIZE_ZOOM.find((item) => item.zoom === window.siyuan.storage[Constants.LOCAL_ZOOM]).position;
diff --git a/app/tests/detachedWindowLoading.test.js b/app/tests/detachedWindowLoading.test.js
index 8f8980137a..8c6aff7df3 100644
--- a/app/tests/detachedWindowLoading.test.js
+++ b/app/tests/detachedWindowLoading.test.js
@@ -37,7 +37,7 @@ const runRendererCase = async (sources, expected) => {
invoke: async (_channel, data) => data.cmd === "isFullScreen" ? windowState.promise : false},
webFrame: {setZoomFactor() {}}};
const functions = {isWindow: () => true, setToolbarLeftMac() {}};
- const compatibility = {isMac: () => false};
+ const compatibility = {isMac: () => false, applyPlatformClasses() {}};
const controls = load(sources.controls, {electron, "../constants": {Constants: constants}, "../util/functions": functions});
const {initWindow} = load(sources.host, {
electron, "../constants": {Constants: constants}, "../util/functions": functions,
@@ -76,7 +76,7 @@ const runRendererCase = async (sources, expected) => {
wnd = {element, headersElement: element.querySelector(".layout-tab-bar"), children: [{}]};
}, adjustLayout() {}},
"../util/functions": {getSearch: () => "[]"},
- "../protyle/util/compatibility": {initWindowOpenOverride() {}, initNativeDialogOverride() {}},
+ "../protyle/util/compatibility": {initWindowOpenOverride() {}, initNativeDialogOverride() {}, applyPlatformClasses() {}},
"../util/assets": {initAssets: keepLoading => assert.equal(keepLoading, true),
enqueueAppearanceUpdate: apply => apply(), setInlineStyle: async () => {}},
"../config/tabs/appearanceRuntime": {appearanceConfigApi: {apply: () => {
diff --git a/app/tests/mainWindowLoading.test.js b/app/tests/mainWindowLoading.test.js
index 16f1bb7692..6b92e70768 100644
--- a/app/tests/mainWindowLoading.test.js
+++ b/app/tests/mainWindowLoading.test.js
@@ -32,7 +32,8 @@ const runCase = async (sources, options) => {
const getAllWnds = (_layout, wnds) => { if (wnd) wnds.push(wnd); };
const functions = {isWindow: () => false, setToolbarLeftMac() {}};
const tabs = load(sources.tabs, {"../util/functions": functions, "./getAll": {getAllWnds}});
- const compatibility = {isMac: () => false, isWindows: () => true, initWindowOpenOverride() {}, initNativeDialogOverride() {}};
+ const compatibility = {isMac: () => false, isWindows: () => true, applyPlatformClasses() {},
+ initWindowOpenOverride() {}, initNativeDialogOverride() {}};
const electron = {ipcRenderer: {send() {}, on() {}, invoke: async (channel, data) => {
if (channel === "init") return {};
return data.cmd === "isFullScreen" ? state.promise : false;
diff --git a/app/tests/settingsBoot.test.js b/app/tests/settingsBoot.test.js
index f1241ea860..6cd9569f6b 100644
--- a/app/tests/settingsBoot.test.js
+++ b/app/tests/settingsBoot.test.js
@@ -78,7 +78,8 @@ const createBoot = (plugin = false, failed = "", waitForStyles = false) => {
"../../util/pathName": {addBaseURL() {}, setNoteBook: () => wait("notebooks")},
"../../protyle/util/compatibility": {getLocalStorage: callback => {
void wait("storage").then(() => { window.siyuan.storage = {zoom: 1}; callback(); });
- }, isWindows: () => true, isMac: () => false, initNativeDialogOverride() {}, initWindowOpenOverride() {}},
+ }, isWindows: () => true, isMac: () => false, applyPlatformClasses() {},
+ initNativeDialogOverride() {}, initWindowOpenOverride() {}},
"../../protyle/util/addScript": {addScriptSync: async (_path, id) => {
assert.equal(id, "protyleWcHtmlScript");
await wait("html");
diff --git a/app/tests/settingsWindow.test.js b/app/tests/settingsWindow.test.js
index 41797e26b1..e2a078bacf 100644
--- a/app/tests/settingsWindow.test.js
+++ b/app/tests/settingsWindow.test.js
@@ -32,6 +32,7 @@ const rendererModules = (sources) => {
electron: {ipcRenderer}, "../constants": {Constants: {SIYUAN_CMD: "siyuan-cmd", LOCAL_ZOOM: "zoom"}},
"../util/functions": {setToolbarLeftMac() {}},
});
+ document.body.classList.toggle("body--windows", process.platform !== "darwin");
document.body.classList.toggle("body--win32", process.platform !== "darwin");
const fit = loadRendererModule(sources.fit, {
"../../boot/windowControls": controls, "../../protyle/util/compatibility": {isMac: () => process.platform === "darwin"},