58 lines
2.5 KiB
Python
58 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Present OrionToolbar Settings as a blocking sheet attached to the menu window."""
|
|
from pathlib import Path
|
|
from datetime import datetime
|
|
import shutil
|
|
|
|
root = Path(__file__).resolve().parent.parent
|
|
if not (root / 'OrionToolbar/OrionMenuView.swift').exists():
|
|
root = Path.cwd()
|
|
path = root / 'OrionToolbar/OrionMenuView.swift'
|
|
if not path.exists():
|
|
raise SystemExit(f'Cannot locate {path}. Run from the OrionToolbar project directory.')
|
|
s = path.read_text()
|
|
if 'private var settingsSheet' in s:
|
|
print('Settings modal patch already applied.')
|
|
raise SystemExit(0)
|
|
if '@Environment(\\.openSettings) private var openSettings' not in s or 'private func showSettings() {' not in s:
|
|
raise SystemExit('Unexpected OrionMenuView.swift structure. No files changed.')
|
|
|
|
s = s.replace(' @Environment(\\.openSettings) private var openSettings\n', '', 1)
|
|
anchor = ' @State private var showRunning = true'
|
|
if anchor not in s: raise SystemExit('Missing state anchor. No files changed.')
|
|
s = s.replace(anchor, ' @State private var settingsPresented = false\n' + anchor, 1)
|
|
anchor = ' .preferredColorScheme(.dark)'
|
|
if anchor not in s: raise SystemExit('Missing sheet anchor. No files changed.')
|
|
s = s.replace(anchor, ''' .sheet(isPresented: $settingsPresented) {
|
|
VStack(spacing: 0) {
|
|
HStack {
|
|
Text("Settings")
|
|
.font(.headline)
|
|
Spacer()
|
|
Button("Done") { settingsPresented = false }
|
|
.keyboardShortcut(.cancelAction)
|
|
}
|
|
.padding(.horizontal, 18)
|
|
.padding(.top, 14)
|
|
.padding(.bottom, 8)
|
|
SettingsView()
|
|
.environmentObject(vm)
|
|
}
|
|
.frame(width: 650)
|
|
.interactiveDismissDisabled()
|
|
}
|
|
''' + anchor, 1)
|
|
start = s.index(' private func showSettings() {')
|
|
end = s.index('\n }', start) + len('\n }')
|
|
s = s[:start] + ''' private func showSettings() {
|
|
settingsPresented = true
|
|
NSApplication.shared.activate(ignoringOtherApps: true)
|
|
}''' + s[end:]
|
|
backup_dir = root / 'backups' / datetime.now().strftime('%Y%m%d-%H%M%S-%f') / 'OrionToolbar'
|
|
backup_dir.mkdir(parents=True, exist_ok=True)
|
|
shutil.copy2(path, backup_dir / path.name)
|
|
path.write_text(s)
|
|
print('Updated:', path)
|
|
print('Backup:', backup_dir / path.name)
|
|
print('Settings now opens as a blocking sheet attached to the OrionToolbar panel.')
|