Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

improve(win7): 启用 WebView2 109 的现代颜色支持 (#12761)

zipg88be98e5b030
diff --git a/docs/testing/win7-csscolor4/README.zh-CN.md b/docs/testing/win7-csscolor4/README.zh-CN.md
new file mode 100644
index 0000000000..125ec9917d
--- /dev/null
+++ b/docs/testing/win7-csscolor4/README.zh-CN.md
@@ -0,0 +1,50 @@
+# Win7 WebView2 现代颜色兼容实验
+
+Win7 安装包使用固定的 WebView2 109.0.1518.78。该版本内置的 `CSSColor4` 默认未开启,导致 `oklch()`、`color-mix()` 等颜色声明无法生效。
+
+`x86_64-win7-windows-msvc` 构建在创建 WebView2 前,将 `CSSColor4` 合并到 `WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS` 的最后一个 `--enable-blink-features` 参数中。保留已有参数与其他功能名称,并尊重显式的 `--disable-blink-features=CSSColor4`。其他目标不自动请求该功能。
+
+这项改动只启用现有内核中的颜色实现,不更换运行时、加载器或业务样式。Chromium 109 将此能力标为实验特性,不能据此视为完整支持现代 CSS。
+
+## 验证与回退
+
+每次切换前完全退出 DBX,包括托盘进程,避免新启动被转交给已经运行的实例。
+
+- 正常启动 Win7 构建:默认请求 CSSColor4。
+- 设置 `DBX_DISABLE_WIN7_CSS_COLOR4=1`:明确关闭该功能,可用于对比或兼容回退。
+- 设置 `DBX_KEEP_STARTUP_LOG=1`:保留 `%APPDATA%\com.dbx.app\startup.log`;其中 `CSSColor4 requested=true/false` 表示参数请求状态,仍应通过实际页面验证生效情况。
+
+例如,在 PowerShell 中将程序路径替换为实际位置:
+
+```powershell
+$env:DBX_KEEP_STARTUP_LOG = '1'
+$env:DBX_DISABLE_WIN7_CSS_COLOR4 = '1'
+& 'C:\path\to\dbx.exe'
+```
+
+重新启用时,完全退出 DBX,移除 `DBX_DISABLE_WIN7_CSS_COLOR4` 或设为 `0`,然后再次启动。
+
+建议比较亮/暗主题、背景、边框、悬停与选中状态,同时检查弹窗、DOM 与 Canvas 表格、滚动和输入法。
+
+## 已知颜色兼容差异
+
+可见诊断页发现:开启后,`oklch(0.62 0.22 260)` 虽然被接受,实际渲染却明显偏暗。109 的早期实验实现与当前颜色语法存在差异,`CSS.supports()` 返回 true 不足以确认主题色正确。
+
+Win7 用户实机测试反馈整体展示比之前明显改善。色块偏暗作为已知兼容差异继续跟踪,保留 `DBX_DISABLE_WIN7_CSS_COLOR4=1` 以便按需回退。
+
+下图均由测试包的 WebView2 109 渲染,运行环境为 Windows Server 2022 CI。它们是隔离颜色能力的诊断页,不是完整 DBX 界面,也不是 Win7 系统截图。
+
+| 关闭 CSSColor4 | 开启 CSSColor4(OKLCH 色块偏暗) |
+| --- | --- |
+| ![关闭](csscolor4-off.png) | ![开启](csscolor4-on.png) |
+
+[可见渲染验证构建](https://github.com/zipg/dbx/actions/runs/39269676386);原始结果见 [关闭](result-off.json) 与 [开启](result-on.json)。
+
+## 已有验证
+
+- 参数合并与回退策略有 8 个单元测试,覆盖目标限制、原有参数、引号、重复开关、幂等性、显式禁用与退出开关。
+- 测试包已完成 Win7 目标编译、PE/加载器与安装内容审计。
+- Windows CI 中,真实 DBX 与固定 WebView2 109 的开/关对比探针已通过:`oklch()`、sRGB 和 Oklab `color-mix()` 从不支持变为支持。该结果只验证声明可用性,不验证显示颜色是否正确。
+- Win7 用户实机反馈:整体展示比之前明显改善,部分此前缺失的新样式能够展示;尚未覆盖全部界面与设备配置。
+
+CI 使用 Windows Server 2022,截图与能力探针不能替代 Win7 系统兼容性测试。对应测试包构建:<https://github.com/zipg/dbx/actions/runs/39098197448>。
diff --git a/docs/testing/win7-csscolor4/csscolor4-off.png b/docs/testing/win7-csscolor4/csscolor4-off.png
new file mode 100644
index 0000000000..43e433ed06
Binary files /dev/null and b/docs/testing/win7-csscolor4/csscolor4-off.png differ
diff --git a/docs/testing/win7-csscolor4/csscolor4-on.png b/docs/testing/win7-csscolor4/csscolor4-on.png
new file mode 100644
index 0000000000..601d6df9bd
Binary files /dev/null and b/docs/testing/win7-csscolor4/csscolor4-on.png differ
diff --git a/docs/testing/win7-csscolor4/result-off.json b/docs/testing/win7-csscolor4/result-off.json
new file mode 100644
index 0000000000..200204caf7
--- /dev/null
+++ b/docs/testing/win7-csscolor4/result-off.json
@@ -0,0 +1,17 @@
+{
+ "mode": "off",
+ "runtimeVersion": "Edg/109.0.1518.78",
+ "capabilities": {
+ "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.78",
+ "oklch": false,
+ "mix": false,
+ "mixOklab": false
+ },
+ "targetUrl": "http://tauri.localhost/",
+ "scope": "WebView2 109 on Windows Actions runner; not a Win7 OS test",
+ "computedColors": {
+ "oklch": "rgb(230, 232, 236)",
+ "mix": "rgb(230, 232, 236)",
+ "mixOklab": "rgb(230, 232, 236)"
+ }
+}
\ No newline at end of file
diff --git a/docs/testing/win7-csscolor4/result-on.json b/docs/testing/win7-csscolor4/result-on.json
new file mode 100644
index 0000000000..fcaaf93678
--- /dev/null
+++ b/docs/testing/win7-csscolor4/result-on.json
@@ -0,0 +1,17 @@
+{
+ "mode": "on",
+ "runtimeVersion": "Edg/109.0.1518.78",
+ "capabilities": {
+ "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.78",
+ "oklch": true,
+ "mix": true,
+ "mixOklab": true
+ },
+ "targetUrl": "http://tauri.localhost/",
+ "scope": "WebView2 109 on Windows Actions runner; not a Win7 OS test",
+ "computedColors": {
+ "oklch": "oklch(0.62 0.22 260)",
+ "mix": "color(srgb 0.5 0 0.5)",
+ "mixOklab": "oklab(53.9974 0.0962087 -0.0928316)"
+ }
+}
\ No newline at end of file
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index f37a8ebd46..bdf237608e 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -16,6 +16,8 @@ mod startup_recovery;
#[path = "startup_recovery_noop.rs"]
mod startup_recovery;
#[cfg(any(target_os = "windows", test))]
+mod webview2_legacy_css;
+#[cfg(any(target_os = "windows", test))]
mod webview2_recovery;
mod window_state_guard;
diff --git a/src-tauri/src/startup_recovery.rs b/src-tauri/src/startup_recovery.rs
index eed1d94c6f..6f55d65f84 100644
--- a/src-tauri/src/startup_recovery.rs
+++ b/src-tauri/src/startup_recovery.rs
@@ -14,6 +14,8 @@ const STARTUP_LOG_DIR_ENV: &str = "DBX_STARTUP_LOG_DIR";
const KEEP_STARTUP_LOG_ENV: &str = "DBX_KEEP_STARTUP_LOG";
#[cfg(target_os = "windows")]
const NO_SANDBOX_ENV: &str = "DBX_WEBVIEW2_NO_SANDBOX";
+#[cfg(target_os = "windows")]
+const DISABLE_WIN7_CSS_COLOR4_ENV: &str = "DBX_DISABLE_WIN7_CSS_COLOR4";
const RECOVERY_ATTEMPT_ENV: &str = "DBX_STARTUP_COMPAT_RECOVERY";
const RECOVERY_PARENT_PID_ENV: &str = "DBX_STARTUP_COMPAT_PARENT_PID";
const DISABLE_ENTERPRISE_COMPAT_ENV: &str = "DBX_DISABLE_ENTERPRISE_COMPAT";
@@ -346,12 +348,20 @@ fn configure_webview2_compatibility(enterprise_compat: bool) {
None => record("enterprise compatibility profile unavailable: LOCALAPPDATA and APPDATA are missing"),
}
}
+ let existing_args = std::env::var("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS").unwrap_or_default();
+ let win7_css_disabled = env_flag(DISABLE_WIN7_CSS_COLOR4_ENV);
+ let args = crate::webview2_legacy_css::configure(&existing_args, cfg!(target_vendor = "win7"), win7_css_disabled);
+ let args = webview2_compatibility_arguments(args, enterprise_compat, manual_no_sandbox);
+ if args != existing_args {
+ std::env::set_var("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", &args);
+ }
+ if cfg!(target_vendor = "win7") {
+ record(format!(
+ "Win7 WebView2 CSSColor4 requested={} opt_out={win7_css_disabled}",
+ crate::webview2_legacy_css::requested(&args)
+ ));
+ }
if enterprise_compat || manual_no_sandbox {
- let args = std::env::var("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS").unwrap_or_default();
- std::env::set_var(
- "WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS",
- webview2_compatibility_arguments(args, enterprise_compat, manual_no_sandbox),
- );
record(format!("WebView2 no-sandbox enabled enterprise_compat={enterprise_compat} manual={manual_no_sandbox}"));
}
if enterprise_compat {
diff --git a/src-tauri/src/webview2_legacy_css.rs b/src-tauri/src/webview2_legacy_css.rs
new file mode 100644
index 0000000000..a10729db92
--- /dev/null
+++ b/src-tauri/src/webview2_legacy_css.rs
@@ -0,0 +1,161 @@
+//! Request the CSSColor4 implementation in the fixed WebView2 109 Win7 build.
+//! Chromium 109 includes color-mix()/OKLCH behind the CSSColor4 Blink feature.
+use std::ops::Range;
+
+const FEATURE: &str = "CSSColor4";
+const ENABLE: &str = "--enable-blink-features=";
+const DISABLE: &str = "--disable-blink-features=";
+
+// Keep every unrelated argument verbatim, including Windows paths and quoted
+// values. Chromium uses the last occurrence of a repeated switch.
+fn last_value(args: &str, switch: &str) -> Option<Range<usize>> {
+ let bytes = args.as_bytes();
+ let mut cursor = 0;
+ let mut result = None;
+ while cursor < bytes.len() {
+ while cursor < bytes.len() && bytes[cursor].is_ascii_whitespace() {
+ cursor += 1;
+ }
+ let mut start = cursor;
+ let mut quoted = false;
+ let mut slashes = 0;
+ while cursor < bytes.len() {
+ let byte = bytes[cursor];
+ if byte.is_ascii_whitespace() && !quoted {
+ break;
+ }
+ if byte == b'"' && slashes % 2 == 0 {
+ quoted = !quoted;
+ }
+ slashes = if byte == b'\\' { slashes + 1 } else { 0 };
+ cursor += 1;
+ }
+ let mut end = cursor;
+ if start == end || quoted {
+ continue;
+ }
+ if bytes[start] == b'"' && bytes[end - 1] == b'"' {
+ start += 1;
+ end -= 1;
+ }
+ let token = &args[start..end];
+ if !token.get(..switch.len()).is_some_and(|prefix| prefix.eq_ignore_ascii_case(switch)) {
+ continue;
+ }
+ start += switch.len();
+ if end > start && bytes[start] == b'"' && bytes[end - 1] == b'"' {
+ start += 1;
+ end -= 1;
+ }
+ result = Some(start..end);
+ }
+ result
+}
+
+fn contains_feature(args: &str, switch: &str) -> bool {
+ last_value(args, switch).is_some_and(|range| args[range].split(',').any(|name| name.trim() == FEATURE))
+}
+
+fn add_feature(args: &str, switch: &str) -> String {
+ if contains_feature(args, switch) {
+ return args.to_owned();
+ }
+ let mut updated = args.to_owned();
+ if let Some(range) = last_value(args, switch) {
+ let separator = if args[range.clone()].trim().is_empty() { "" } else { "," };
+ updated.insert_str(range.end, &format!("{separator}{FEATURE}"));
+ } else {
+ if !updated.is_empty() && !updated.as_bytes().last().is_some_and(|byte| byte.is_ascii_whitespace()) {
+ updated.push(' ');
+ }
+ updated.push_str(switch);
+ updated.push_str(FEATURE);
+ }
+ updated
+}
+
+pub(crate) fn configure(args: &str, win7_build: bool, disabled: bool) -> String {
+ if !win7_build {
+ return args.to_owned();
+ }
+ if disabled {
+ return add_feature(args, DISABLE);
+ }
+ if contains_feature(args, DISABLE) {
+ return args.to_owned();
+ }
+ add_feature(args, ENABLE)
+}
+
+pub(crate) fn requested(args: &str) -> bool {
+ contains_feature(args, ENABLE) && !contains_feature(args, DISABLE)
+}
+
+#[cfg(test)]
+mod tests {
+ use super::{configure, requested};
+
+ #[test]
+ fn only_requests_the_feature_for_the_win7_package() {
+ assert_eq!(configure("", false, false), "");
+ assert_eq!(configure("--disable-gpu", false, true), "--disable-gpu");
+ assert_eq!(configure("", true, false), "--enable-blink-features=CSSColor4");
+ }
+
+ #[test]
+ fn preserves_other_arguments_and_feature_names() {
+ let args = r#"--user-agent="DBX test browser" --disable-gpu --enable-blink-features=FeatureA,FeatureB"#;
+ assert_eq!(configure(args, true, false), format!("{args},CSSColor4"));
+ }
+
+ #[test]
+ fn preserves_quoted_feature_lists() {
+ for (args, expected) in [
+ (
+ r#"--enable-blink-features="FeatureA" --disable-gpu"#,
+ r#"--enable-blink-features="FeatureA,CSSColor4" --disable-gpu"#,
+ ),
+ (r#""--enable-blink-features=FeatureA""#, r#""--enable-blink-features=FeatureA,CSSColor4""#),
+ (r#"--enable-blink-features="""#, r#"--enable-blink-features="CSSColor4""#),
+ ] {
+ assert_eq!(configure(args, true, false), expected);
+ }
+ }
+
+ #[test]
+ fn does_not_duplicate_the_feature() {
+ let args = "--enable-blink-features=FeatureA,CSSColor4";
+ assert_eq!(configure(args, true, false), args);
+ assert_eq!(configure(&configure(args, true, false), true, false), args);
+ }
+
+ #[test]
+ fn updates_the_last_switch_without_reactivating_ignored_features() {
+ let args = "--enable-blink-features=CSSColor4,Ignored --enable-blink-features=Active";
+ assert_eq!(configure(args, true, false), format!("{args},CSSColor4"));
+ assert!(!requested(args));
+ assert!(requested(&configure(args, true, false)));
+ }
+
+ #[test]
+ fn respects_an_explicit_disable_switch() {
+ let args = "--enable-blink-features=FeatureA --disable-blink-features=CSSColor4,FeatureB";
+ assert_eq!(configure(args, true, false), args);
+ assert!(!requested(args));
+ }
+
+ #[test]
+ fn opt_out_disables_the_feature_and_preserves_other_switches() {
+ let args = "--enable-blink-features=CSSColor4,FeatureA --disable-blink-features=FeatureB";
+ let disabled = configure(args, true, true);
+ assert_eq!(disabled, format!("{args},CSSColor4"));
+ assert!(!requested(&disabled));
+ assert_eq!(configure(&disabled, true, true), disabled);
+ }
+
+ #[test]
+ fn quoted_unrelated_arguments_do_not_look_like_switches() {
+ let args = r#"--user-agent="test --enable-blink-features=Fake" --proxy-server="http://127.0.0.1:8080""#;
+ assert_eq!(configure(args, true, false), format!("{args} --enable-blink-features=CSSColor4"));
+ }
+}