46 lines
2.4 KiB
Python
46 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
from pathlib import Path
|
|
from datetime import datetime
|
|
import shutil
|
|
root=Path.cwd(); path=root/'OrionToolbar/OrionMenuView.swift'
|
|
if not path.exists(): raise SystemExit('Run from OrionToolbar project root')
|
|
s=path.read_text(); original=s
|
|
# Native macOS drag on the dedicated server-name grip, native drop on the full row.
|
|
s=s.replace('.draggable(server.id.uuidString)', '''.onDrag {
|
|
NSItemProvider(object: server.id.uuidString as NSString)
|
|
}''',1)
|
|
needle=''' .dropDestination(for: String.self) { items, _ in
|
|
guard let value = items.first,
|
|
let id = UUID(uuidString: value) else { return false }
|
|
vm.reorderServer(draggedID: id, onto: server.id)
|
|
return true
|
|
}'''
|
|
replacement=''' .onDrop(of: [.plainText], isTargeted: nil) { providers in
|
|
guard let provider = providers.first else { return false }
|
|
_ = provider.loadObject(ofClass: NSString.self) { value, _ in
|
|
guard let text = value as String?, let dragged = UUID(uuidString: text) else { return }
|
|
Task { @MainActor in
|
|
vm.reorderServer(draggedID: dragged, onto: server.id)
|
|
}
|
|
}
|
|
return true
|
|
}'''
|
|
if needle not in s: raise SystemExit('Expected integrated server drop target not found; no changes made')
|
|
s=s.replace(needle,replacement,1)
|
|
# Remove the redundant far-right chevron button on the All Virtual Machines rows;
|
|
# the adjacent +/checkmark remains and existing actions still work.
|
|
needle=''' Menu {
|
|
Button("Open in Parallels") { vm.openParallels() }
|
|
if machine.status.lowercased() == "running" {
|
|
Button("Restart") { vm.operate(machine, action: "restart") }
|
|
Button("Force Stop", role: .destructive) { pendingForceStop = machine }
|
|
}
|
|
} label: { Image(systemName: "chevron.right").foregroundStyle(OrionStyle.muted) }
|
|
.menuStyle(.borderlessButton).frame(width: 22)'''
|
|
if needle not in s: raise SystemExit('Expected redundant right chevron menu not found; no changes made')
|
|
s=s.replace(needle,'',1)
|
|
if s==original: raise SystemExit('No changes')
|
|
backup=root/'backups'/datetime.now().strftime('%Y%m%d-%H%M%S')/path.relative_to(root)
|
|
backup.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(path,backup);path.write_text(s)
|
|
print('Updated:',path,'\nBackup:',backup)
|