fix(macos): show capsule across Spaces
This commit is contained in:
1 parent
e4acd1d9b4
commit
40b8c0ce13
4 files changed
+41
-1
No files matched your search
@@ -85,6 +85,9 @@ jobs:
|
||||
}
|
||||
}
|
||||
|
||||
- name: Check macOS capsule Spaces contract
|
||||
run: npm run check:macos-capsule-spaces
|
||||
|
||||
- name: Build frontend (tsc + vite)
|
||||
run: npm run build
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"build": "tsc && vite build",
|
||||
"preview": "vite preview",
|
||||
"tauri": "tauri",
|
||||
"check:macos-capsule-spaces": "node scripts/macos-capsule-spaces-contract.test.mjs",
|
||||
"check:hotkey-injection": "node scripts/check-hotkey-injection.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { readFile } from 'node:fs/promises';
|
||||
|
||||
function assertMatch(source, pattern, name) {
|
||||
if (!pattern.test(source)) {
|
||||
throw new Error(`${name}: pattern ${pattern} not found`);
|
||||
}
|
||||
}
|
||||
|
||||
const coordinatorRs = await readFile(new URL('../src-tauri/src/coordinator.rs', import.meta.url), 'utf-8');
|
||||
const functionMatch = coordinatorRs.match(
|
||||
/#\[cfg\(target_os = "macos"\)\]\s*fn show_capsule_window_no_activate[\s\S]*?\n}\n\n#\[cfg\(target_os = "linux"\)\]/,
|
||||
);
|
||||
|
||||
if (!functionMatch) {
|
||||
throw new Error('macOS capsule no-activate function not found');
|
||||
}
|
||||
|
||||
const macosNoActivateFunction = functionMatch[0];
|
||||
const executableMacosNoActivateFunction = macosNoActivateFunction.replace(/\/\/.*$/gm, '');
|
||||
|
||||
assertMatch(
|
||||
macosNoActivateFunction,
|
||||
/set_visible_on_all_workspaces\(true\)[\s\S]*?orderFrontRegardless/,
|
||||
'macOS capsule should join all Spaces before showing without activation',
|
||||
);
|
||||
|
||||
for (const forbidden of ['window.show()', 'set_focus', 'NSApp.activate', 'makeKeyAndOrderFront']) {
|
||||
if (executableMacosNoActivateFunction.includes(forbidden)) {
|
||||
throw new Error(`macOS capsule no-activate path must not call ${forbidden}`);
|
||||
}
|
||||
}
|
||||
@@ -4500,7 +4500,12 @@ fn show_capsule_window_no_activate<R: tauri::Runtime>(
|
||||
|
||||
// emit_capsule 已经把窗口操作 marshal 到 Tauri 主线程;这里不能再调用
|
||||
// window.show()/set_focus()/NSApp.activate,否则 AeroSpace 会把 workspace 切回
|
||||
// OpenLess 主窗口所在空间。orderFrontRegardless 只让胶囊可见,不成为 key window。
|
||||
// OpenLess 主窗口所在空间。先让胶囊加入所有 Spaces,再用
|
||||
// orderFrontRegardless 做无激活展示。
|
||||
if let Err(e) = window.set_visible_on_all_workspaces(true) {
|
||||
log::warn!("[capsule] set visible on all macOS Spaces failed: {e}");
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let _: () = msg_send![ns_window, orderFrontRegardless];
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user