diff --git a/.cargo/config.toml b/.cargo/config.toml
new file mode 100644
index 000000000..4ada95f73
--- /dev/null
+++ b/.cargo/config.toml
@@ -0,0 +1,7 @@
+# Link debug builds for the oldest system we support, so Launch Services
+# accepts the bundle on macOS 11. Without this a newer SDK leaves
+# LC_BUILD_VERSION.minos at 12.0 and the app is refused (-10825) before main
+# can load a newer WebKit. An explicitly exported MACOSX_DEPLOYMENT_TARGET
+# still wins: this is only the default for local builds and CI.
+[env]
+MACOSX_DEPLOYMENT_TARGET = "11.0"
diff --git a/docs/en/contribute/guidelines/ui.mdx b/docs/en/contribute/guidelines/ui.mdx
index 65a7b035d..46f96c33e 100644
--- a/docs/en/contribute/guidelines/ui.mdx
+++ b/docs/en/contribute/guidelines/ui.mdx
@@ -43,7 +43,7 @@ User-visible text is written in English at the call site and goes through the te
## WebKit compatibility
-On macOS and Linux the app runs in WebKit, and the supported floor is Safari 15.4, the engine of macOS 12 (the app's minimum). `pnpm build` runs `scripts/check-webkit.ts` on the bundle, and `src/platform/webkitCompatibility.test.ts` checks application regexes. Avoid:
+On macOS and Linux the app runs in WebKit, and the supported floor is Safari 15.4, the engine of macOS 12 (the app's minimum). On macOS 11 and on macOS 12 before 12.3, `src-tauri/src/macos_webview.rs` loads the newer WebKit staged by a Safari update, provided that update is installed. `pnpm build` runs `scripts/check-webkit.ts` on the bundle, and `src/platform/webkitCompatibility.test.ts` checks application regexes. Avoid:
- regex lookbehind (`(?<=…)`, `(?` is the release version, for example `0.1.40
## macOS
-macOS 12 Monterey or later.
+macOS 12 Monterey or later. macOS 11 Big Sur also works: install the latest Safari update in Software Update first, and OpenIDEA will load the newer WebKit Apple stages alongside it (the system engine predates Safari 15.4). On macOS 12, install that update too if its system WebKit is older than Safari 15.4; otherwise the built-in engine is used as is.
| Mac | File |
| ------------- | -------------------------------- |
diff --git a/docs/zh/contribute/guidelines/ui.mdx b/docs/zh/contribute/guidelines/ui.mdx
index 281568fcd..392ba10e5 100644
--- a/docs/zh/contribute/guidelines/ui.mdx
+++ b/docs/zh/contribute/guidelines/ui.mdx
@@ -43,7 +43,7 @@ description: "前端 UI 代码的规则:设计 token、CSS Modules、图标、
## WebKit 兼容性
-在 macOS 和 Linux 上应用运行于 WebKit,最低支持 Safari 15.4,即 macOS 12 的引擎(应用的最低系统版本)。`pnpm build` 会对产物运行 `scripts/check-webkit.ts`,`src/platform/webkitCompatibility.test.ts` 会检查应用中的正则。请避免:
+在 macOS 和 Linux 上应用运行于 WebKit,最低支持 Safari 15.4,即 macOS 12 的引擎(应用的最低系统版本)。在 macOS 11 以及 12.3 之前的 macOS 12 上,`src-tauri/src/macos_webview.rs` 会加载 Safari 更新暂存的新版 WebKit,前提是已安装该更新。`pnpm build` 会对产物运行 `scripts/check-webkit.ts`,`src/platform/webkitCompatibility.test.ts` 会检查应用中的正则。请避免:
- 正则后行断言(`(?<=…)`、`(?
com.apple.security.cs.allow-unsigned-executable-memory
+
+ com.apple.security.cs.allow-dyld-environment-variables
+
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index dcf2cf451..7543ca6de 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -56,6 +56,12 @@ pub fn specta_builder() -> tauri_specta::Builder {
pub fn export_bindings(builder: &tauri_specta::Builder) {
let target = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/bindings.ts"));
+ // Debug builds can end up on machines other than the one that built them
+ // (packaged test builds). Without the checkout there is nothing to sync,
+ // and `CARGO_MANIFEST_DIR` points at the build machine anyway.
+ if !target.parent().is_some_and(Path::is_dir) {
+ return;
+ }
// Rewritten only when it changes: every debug launch exports, also a second instance that just
// hands its path over, and a rewrite makes Vite reload the running app's windows.
let fresh = std::env::temp_dir().join(format!("openidea-bindings-{}.ts", std::process::id()));
diff --git a/src-tauri/src/macos_webview.rs b/src-tauri/src/macos_webview.rs
new file mode 100644
index 000000000..0534a8b11
--- /dev/null
+++ b/src-tauri/src/macos_webview.rs
@@ -0,0 +1,124 @@
+//! On macOS systems whose WebKit predates Safari 15.4, WKWebView keeps using
+//! that old engine even after Safari itself is updated. Apple stages the newer
+//! WebKit next to the Safari app; Safari.app points dyld at it, and we do the
+//! same before Tauri creates a webview.
+//!
+//! dyld reads framework search paths at process start, so switching engines
+//! means setting `DYLD_FRAMEWORK_PATH` and re-executing. The second process
+//! clears the variable again: the new engine stays loaded (verified on macOS
+//! 11.7.11 by dlopen'ing WebKit after unsetenv), while children such as
+//! language servers and git helpers keep using the system frameworks.
+//!
+//! Only a system WebKit older than Safari 15.4 with a staged copy present
+//! takes this path. macOS 12.3+ already ships Safari 15.4's engine, and
+//! macOS 13+ ships an even newer one; neither restarts the process.
+
+use std::os::unix::process::CommandExt;
+use std::path::Path;
+use std::process::Command;
+
+const STAGED_FRAMEWORKS: &str = "/Library/Apple/System/Library/StagedFrameworks/Safari";
+const STAGED_WEBKIT: &str = "/Library/Apple/System/Library/StagedFrameworks/Safari/WebKit.framework";
+const SYSTEM_WEBKIT_PLIST: &str = "/System/Library/Frameworks/WebKit.framework/Resources/Info.plist";
+const DYLD_FRAMEWORK_PATH: &str = "DYLD_FRAMEWORK_PATH";
+/// Set on the re-exec so we never loop, and so the second process knows to
+/// drop the dyld variable before spawning children.
+const REEXEC_MARKER: &str = "OPENIDEA_WEBKIT_REEXEC";
+const DISABLE: &str = "OPENIDEA_DISABLE_STAGED_WEBKIT";
+
+/// WebKit's CFBundleVersion starts with `166NN`, where NN is the engine
+/// generation: 16611 = Safari 14.1 / WebKit 611, 16613 = Safari 15.4 / WebKit
+/// 613, 16615 = Safari 16 / WebKit 615. Anything below 16613 cannot parse the
+/// Safari 15.4 bundle (`vite.config.ts`).
+const MIN_SYSTEM_WEBKIT_BUNDLE: u32 = 16613;
+
+/// Call at the very start of `main`, before Tauri creates a webview.
+pub fn ensure_modern_webkit() {
+ if std::env::var_os(REEXEC_MARKER).is_some() {
+ // dyld snapshots DYLD_* at process start, so removing it here keeps
+ // the engine we loaded without passing the override to children.
+ clear_dyld_framework_path();
+ return;
+ }
+ // The `openidea` CLI wrapper runs this binary too, but never opens a
+ // webview; don't pay for a re-exec on every git hook invocation.
+ if std::env::args_os().any(|arg| arg.as_os_str() == std::ffi::OsStr::new("--cli")) {
+ return;
+ }
+ if std::env::var_os(DISABLE).is_some() {
+ return;
+ }
+ // Check for the staged copy first: it is a stat, while reading the system
+ // version spawns `defaults`, which every launch on a current macOS would pay.
+ if !Path::new(STAGED_WEBKIT).is_dir() || !needs_staged_webkit(system_webkit_bundle_version(), true) {
+ return;
+ }
+ relaunch();
+}
+
+fn needs_staged_webkit(system_bundle: Option, staged_present: bool) -> bool {
+ // If we cannot read the system version, keep the system engine: an
+ // unverifiable switch is worse than showing the startup failure page.
+ staged_present && matches!(system_bundle, Some(version) if version < MIN_SYSTEM_WEBKIT_BUNDLE)
+}
+
+fn relaunch() {
+ let Ok(exe) = std::env::current_exe() else { return };
+ let error = Command::new(exe)
+ .args(std::env::args_os().skip(1))
+ .env(DYLD_FRAMEWORK_PATH, STAGED_FRAMEWORKS)
+ .env(REEXEC_MARKER, "1")
+ .exec();
+ // `exec` returns only on failure. Continue on the system engine so the
+ // startup failure page can tell the user to install the Safari update.
+ eprintln!("OpenIDEA: could not relaunch with Safari's WebKit: {error}");
+}
+
+fn system_webkit_bundle_version() -> Option {
+ let out =
+ Command::new("/usr/bin/defaults").arg("read").arg(SYSTEM_WEBKIT_PLIST).arg("CFBundleVersion").output().ok()?;
+ if !out.status.success() {
+ return None;
+ }
+ bundle_prefix(&String::from_utf8_lossy(&out.stdout))
+}
+
+fn bundle_prefix(version: &str) -> Option {
+ let version = version.trim();
+ let end = version.find(|c: char| !c.is_ascii_digit()).unwrap_or(version.len());
+ version[..end].parse().ok()
+}
+
+// `remove_var` is unsafe from edition 2024 on. This runs single-threaded at
+// the start of main, before Tauri starts any workers.
+#[allow(unused_unsafe)]
+fn clear_dyld_framework_path() {
+ unsafe { std::env::remove_var(DYLD_FRAMEWORK_PATH) };
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn parses_webkit_bundle_versions() {
+ assert_eq!(bundle_prefix("16611.3.10.1.19\n"), Some(16611));
+ assert_eq!(bundle_prefix("16613.4.9.1.12"), Some(16613));
+ assert_eq!(bundle_prefix("16615"), Some(16615));
+ assert_eq!(bundle_prefix(""), None);
+ assert_eq!(bundle_prefix("unknown"), None);
+ }
+
+ #[test]
+ fn only_switches_when_system_webkit_predates_safari_15_4() {
+ // Big Sur and Monterey before 12.3: staged WebKit is needed.
+ assert!(needs_staged_webkit(Some(16611), true));
+ assert!(needs_staged_webkit(Some(16612), true));
+ // Monterey 12.3+ and Ventura+: system WebKit is already new enough.
+ assert!(!needs_staged_webkit(Some(16613), true));
+ assert!(!needs_staged_webkit(Some(16615), true));
+ // No staged copy, or an unreadable system version: leave it alone.
+ assert!(!needs_staged_webkit(Some(16611), false));
+ assert!(!needs_staged_webkit(None, true));
+ }
+}
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 661b614e7..429e84f27 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -1,10 +1,15 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
+#[cfg(target_os = "macos")]
+mod macos_webview;
+
fn main() {
// Started by `ssh` / `git` as their askpass program: answer and exit, no UI.
if let Some(code) = ide_ssh::askpass::run_helper() {
std::process::exit(code);
}
+ #[cfg(target_os = "macos")]
+ macos_webview::ensure_modern_webkit();
openidea_lib::run()
}
diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json
index f606fc32d..3613896bb 100644
--- a/src-tauri/tauri.conf.json
+++ b/src-tauri/tauri.conf.json
@@ -41,7 +41,7 @@
"longDescription": "OpenIDEA is an open-source IDE inspired by IntelliJ IDEA. Not affiliated with JetBrains.",
"macOS": {
"entitlements": "./Entitlements.plist",
- "minimumSystemVersion": "12.0"
+ "minimumSystemVersion": "11.0"
}
},
"mainBinaryName": "openidea",
diff --git a/src/platform/boot.test.ts b/src/platform/boot.test.ts
index eed439f05..20c9b28ac 100644
--- a/src/platform/boot.test.ts
+++ b/src/platform/boot.test.ts
@@ -221,6 +221,8 @@ it("names an outdated system web engine as the cause", () => {
window.dispatchEvent(new ErrorEvent("error", { error: new SyntaxError("Unexpected token '.'") }));
const hint = document.querySelector("#boot-error p")?.textContent;
expect(hint).toContain("needs macOS 12 Monterey or later");
+ expect(hint).toContain("macOS 11 Big Sur");
+ expect(hint).toContain("latest Safari update");
vi.unstubAllGlobals();
});