Skip to content

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

:bug: Scope the iOS caret color to the client platform https://github.com/siyuan-note/siyuan/issues/20005

Daniel2a9ebb4c54b9
diff --git a/app/src/assets/scss/util/_reset.scss b/app/src/assets/scss/util/_reset.scss
index 91f2c032b0..7cbf3bd124 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-backend="ios"]:is([data-frontend="desktop"], [data-frontend="mobile"]) {
+:root[data-ios] {
caret-color: #3575f0;
}
diff --git a/app/src/constants.ts b/app/src/constants.ts
index 8ee193fa6e..93f6b39af7 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -103,6 +103,7 @@ 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/util/appearanceAssets.test.ts b/app/src/util/appearanceAssets.test.ts
index 535a61217a..d81395cdbe 100644
--- a/app/src/util/appearanceAssets.test.ts
+++ b/app/src/util/appearanceAssets.test.ts
@@ -5,18 +5,31 @@ import {test} from "node:test";
import {runInNewContext} from "node:vm";
import {ModuleKind, transpileModule} from "typescript";
import * as themeCompatibility from "./themeCompatibility";
+import * as browserCompatibility from "../protyle/util/browserCompatibility";
+import type {TBrowserNavigator} from "../protyle/util/browserCompatibility";
const {parse} = require("ifdef-loader/preprocessor");
-const createAssets = (ensureLute: () => Promise<void> = async () => {}) => {
+const createAssets = (ensureLute: () => Promise<void> = async () => {}, client: {
+ navigator?: TBrowserNavigator;
+ backend?: string;
+ mobile?: boolean;
+} = {}) => {
const source = readFileSync(resolve(process.cwd(), "src/util/assets.ts"), "utf8");
- const processed = parse(source, {MOBILE: false, BROWSER: true}, false, true);
+ const processed = parse(source, {MOBILE: client.mobile || false, BROWSER: true}, false, true);
const code = transpileModule(processed, {compilerOptions: {module: ModuleKind.CommonJS}}).outputText;
const removedElements: string[] = [];
const element = (attributes: Record<string, string>) => ({
attributes,
getAttribute: (key: string) => attributes[key],
setAttribute: (key: string, value: string) => attributes[key] = value,
+ toggleAttribute: (key: string, enabled: boolean) => {
+ if (enabled) {
+ attributes[key] = "";
+ } else {
+ delete attributes[key];
+ }
+ },
addEventListener: () => {},
remove: () => removedElements.push(attributes.href || attributes.src),
});
@@ -48,7 +61,7 @@ const createAssets = (ensureLute: () => Promise<void> = async () => {}) => {
window: {
siyuan: {config: {appearance}, storage: {pdf: {light: "light", dark: "dark"}}},
location: {href: "http://localhost/stage/build/desktop/"},
- navigator: {},
+ navigator: client.navigator || {userAgent: "", platform: "", maxTouchPoints: 0},
matchMedia: () => ({matches: false}),
setTimeout: () => 0,
clearTimeout: () => {},
@@ -62,7 +75,7 @@ const createAssets = (ensureLute: () => Promise<void> = async () => {}) => {
},
require: (name: string) => {
if (name === "../constants") {
- return {Constants: {SIYUAN_VERSION: "3.8.5", LOCAL_PDFTHEME: "pdf"}};
+ return {Constants: {SIYUAN_VERSION: "3.8.5", LOCAL_PDFTHEME: "pdf", ATTRIBUTE_IOS: "data-ios"}};
}
if (name === "./hostCapabilities") {
return {getHostCapabilities: () => ({customAppearance: true})};
@@ -70,6 +83,15 @@ const createAssets = (ensureLute: () => Promise<void> = async () => {}) => {
if (name === "./themeCompatibility") {
return themeCompatibility;
}
+ if (name === "../protyle/util/browserCompatibility") {
+ return browserCompatibility;
+ }
+ if (name === "./functions") {
+ return {
+ getBackend: () => client.backend || "linux",
+ getFrontend: () => client.mobile ? "browser-mobile" : "browser-desktop",
+ };
+ }
if (name === "../layout/getAll") {
return {getAllModels: (): {graph: unknown[]} => ({graph: []})};
}
@@ -85,9 +107,30 @@ const createAssets = (ensureLute: () => Promise<void> = async () => {}) => {
return new Proxy({}, {get: () => (): undefined => undefined});
},
});
- return {assets: moduleExports, appearance, elements, errors, scriptURLs, removedElements};
+ return {assets: moduleExports, appearance, elements, html, errors, scriptURLs, removedElements};
};
+test("appearance identifies the iOS client independently of the backend and layout", async () => {
+ const cases = [
+ {name: "Windows client with iOS backend", backend: "ios", mobile: false, ios: 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,
+ 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,
+ 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,
+ 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,
+ 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);
+ }
+});
+
test("third-party appearance scripts wait for Lute before execution", async () => {
let complete: () => void;
const pending = new Promise<void>(resolve => complete = resolve);
diff --git a/app/src/util/assets.ts b/app/src/util/assets.ts
index b42e79f98b..95ffe8ddf9 100644
--- a/app/src/util/assets.ts
+++ b/app/src/util/assets.ts
@@ -33,6 +33,7 @@ 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();
@@ -153,6 +154,7 @@ export const loadAssets = async (appearance: Config.IAppearance) => {
applyCompactMode();
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);