Files
OrionToolbar/patches/fix_settings_keep_dashboard.py
2026-10-23 10:07:59 +01:00

48 lines
1.4 KiB
Python

from pathlib import Path
from datetime import datetime
import shutil
root = Path.cwd()
path = root / "OrionToolbar/OrionMenuView.swift"
source = path.read_text()
start_marker = " // MenuBarExtra uses a transient panel"
end_marker = " // Begin a non-blocking AppKit modal session."
if start_marker not in source or end_marker not in source:
raise SystemExit("ERROR: Expected previous patch not found. No changes made.")
start = source.index(start_marker)
end = source.index(end_marker, start)
replacement = """ // Keep the dashboard visible behind Settings.
// MenuBarExtra panels can use a higher window level than .floating.
let dashboardLevel = NSApp.windows
.filter { $0 !== window && $0.isVisible }
.map { $0.level.rawValue }
.max() ?? NSWindow.Level.floating.rawValue
window.level = NSWindow.Level(
rawValue: min(dashboardLevel + 1, Int(CGWindowLevelForKey(.maximumWindow)))
)
NSApp.activate(ignoringOtherApps: true)
window.makeKeyAndOrderFront(nil)
window.orderFrontRegardless()
"""
backup = (
root / "backups"
/ datetime.now().strftime("%Y%m%d-%H%M%S-%f")
/ path.relative_to(root)
)
backup.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(path, backup)
path.write_text(source[:start] + replacement + source[end:])
print("UPDATED:", path)
print("BACKUP:", backup)
print("Dashboard will remain visible behind Settings.")