updates to launcer
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
#!/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)
|
||||
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Replace SwiftUI Transferable drag/drop with NSItemProvider drag/drop for Settings servers."""
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
import shutil
|
||||
|
||||
root = Path.cwd()
|
||||
file = root / 'OrionToolbar/SettingsView.swift'
|
||||
if not file.is_file():
|
||||
raise SystemExit('Run from /Volumes/Developer/Applications/OrionToolbar')
|
||||
s = file.read_text()
|
||||
old = ''' .draggable(server.id.uuidString)
|
||||
.dropDestination(for: String.self) { values, _ in
|
||||
guard let first = values.first,
|
||||
let dragged = UUID(uuidString: first),
|
||||
dragged != server.id else { return false }
|
||||
vm.reorderServer(draggedID: dragged, onto: server.id)
|
||||
return true
|
||||
}'''
|
||||
new = ''' // Native macOS drag source. Works in the menu-bar Settings window.
|
||||
.onDrag {
|
||||
NSItemProvider(object: server.id.uuidString as NSString)
|
||||
}
|
||||
.onDrop(of: [UTType.utf8PlainText.identifier, UTType.plainText.identifier], isTargeted: nil) { providers in
|
||||
guard let provider = providers.first(where: {
|
||||
$0.canLoadObject(ofClass: NSString.self)
|
||||
}) else { return false }
|
||||
let targetID = server.id
|
||||
_ = provider.loadObject(ofClass: NSString.self) { object, _ in
|
||||
guard let raw = object as? String,
|
||||
let draggedID = UUID(uuidString: raw) else { return }
|
||||
Task { @MainActor in
|
||||
vm.reorderServer(draggedID: draggedID, onto: targetID)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}'''
|
||||
if old not in s:
|
||||
raise SystemExit('Expected V3 Settings drag/drop block not found. No changes made; show current SettingsView.swift.')
|
||||
if 'import UniformTypeIdentifiers' not in s:
|
||||
s = s.replace('import SwiftUI', 'import SwiftUI\nimport UniformTypeIdentifiers', 1)
|
||||
s = s.replace(old, new, 1)
|
||||
backup = root / 'backups' / datetime.now().strftime('%Y%m%d-%H%M%S-%f') / 'OrionToolbar' / 'SettingsView.swift'
|
||||
backup.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy2(file, backup)
|
||||
file.write_text(s)
|
||||
print('Updated:', file)
|
||||
print('Backup:', backup)
|
||||
print('Drag a server row onto another server row in Settings.')
|
||||
Reference in New Issue
Block a user