98 lines
2.6 KiB
Python
98 lines
2.6 KiB
Python
from pathlib import Path
|
|
from datetime import datetime
|
|
import shutil
|
|
|
|
root = Path.cwd()
|
|
path = root / "OrionToolbar/OrionMenuView.swift"
|
|
source = path.read_text()
|
|
|
|
marker = "// Settings must be independent of the transient MenuBarExtra panel."
|
|
|
|
if marker not in source:
|
|
raise SystemExit(
|
|
"ERROR: Expected Settings presenter not found. "
|
|
"No files changed."
|
|
)
|
|
|
|
prefix = source.split(marker, 1)[0]
|
|
|
|
replacement = r'''// Keep Settings above its originating MenuBarExtra panel.
|
|
@MainActor
|
|
private final class OrionSettingsWindowPresenter: NSObject, NSWindowDelegate {
|
|
private static var current: OrionSettingsWindowPresenter?
|
|
|
|
private var window: NSWindow?
|
|
private weak var parentWindow: NSWindow?
|
|
|
|
static func present(vm: OrionVMController) {
|
|
if let current, let window = current.window {
|
|
NSApp.activate(ignoringOtherApps: true)
|
|
window.makeKeyAndOrderFront(nil)
|
|
return
|
|
}
|
|
|
|
let presenter = OrionSettingsWindowPresenter()
|
|
current = presenter
|
|
presenter.open(vm: vm)
|
|
}
|
|
|
|
private func open(vm: OrionVMController) {
|
|
// Capture the currently active menu-bar panel.
|
|
let parent = NSApp.keyWindow
|
|
?? NSApp.windows.first(where: { $0.isVisible })
|
|
|
|
let content = SettingsView()
|
|
.environmentObject(vm)
|
|
.preferredColorScheme(.dark)
|
|
|
|
let window = NSWindow(
|
|
contentRect: NSRect(x: 0, y: 0, width: 650, height: 380),
|
|
styleMask: [.titled, .closable],
|
|
backing: .buffered,
|
|
defer: false
|
|
)
|
|
|
|
window.title = "OrionToolbar Settings"
|
|
window.contentViewController = NSHostingController(rootView: content)
|
|
window.delegate = self
|
|
window.isReleasedWhenClosed = false
|
|
window.center()
|
|
|
|
self.window = window
|
|
self.parentWindow = parent
|
|
|
|
if let parent {
|
|
parent.addChildWindow(window, ordered: .above)
|
|
}
|
|
|
|
NSApp.activate(ignoringOtherApps: true)
|
|
window.makeKeyAndOrderFront(nil)
|
|
window.orderFrontRegardless()
|
|
}
|
|
|
|
func windowWillClose(_ notification: Notification) {
|
|
if let window {
|
|
parentWindow?.removeChildWindow(window)
|
|
}
|
|
|
|
window = nil
|
|
Self.current = nil
|
|
}
|
|
}
|
|
'''
|
|
|
|
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(prefix + replacement)
|
|
|
|
print("UPDATED:", path)
|
|
print("BACKUP:", backup)
|
|
print("Settings now attaches above the dashboard.")
|