updates to launcer
This commit is contained in:
@@ -0,0 +1,159 @@
|
||||
#!/usr/bin/env python3
|
||||
"""OrionToolbar: fix Parallels VM Home parsing, icon discovery, and drag reordering."""
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
import re, shutil
|
||||
|
||||
root=Path.cwd()
|
||||
paths={k:root/'OrionToolbar'/k for k in ('OrionVMController.swift','SettingsView.swift','OrionMenuView.swift')}
|
||||
for p in paths.values():
|
||||
if not p.is_file(): raise SystemExit(f'Missing {p}. Run from project root.')
|
||||
c=paths['OrionVMController.swift'].read_text()
|
||||
s=paths['SettingsView.swift'].read_text()
|
||||
m=paths['OrionMenuView.swift'].read_text()
|
||||
if 'func reorderServer(draggedID:' in c:
|
||||
raise SystemExit('This patch has already been applied.')
|
||||
|
||||
# Home ends in a slash on this installation. Existing regex expects .pvm followed by whitespace,
|
||||
# so it fails to capture /Volumes/Parallels/Ubuntu Linux Server.pvm/.
|
||||
start=c.find(' let pattern = #"(?m)^')
|
||||
if start<0: raise SystemExit('Cannot locate existing Home path regex. No changes made.')
|
||||
end=c.find('\n }',start)
|
||||
if end<0: raise SystemExit('Cannot locate end of Home parser. No changes made.')
|
||||
old=c[start:end]
|
||||
if 'Home:' not in old or 'bundlePath' not in old:
|
||||
raise SystemExit('Unexpected Home parser; no changes made.')
|
||||
new=''' // prlctl prints `Home: /Volumes/Parallels/VM.pvm/` (trailing slash).
|
||||
// Match the full line, then normalize the bundle path.
|
||||
if let homeLine = detail.split(separator: "\\n").first(where: {
|
||||
$0.trimmingCharacters(in: .whitespaces).hasPrefix("Home:")
|
||||
}) {
|
||||
let raw = homeLine.trimmingCharacters(in: .whitespaces)
|
||||
.replacingOccurrences(of: "Home:", with: "", range: rawHomePrefixRange(homeLine))
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
.trimmingCharacters(in: CharacterSet(charactersIn: "\\\"'"))
|
||||
let path = (raw as NSString).expandingTildeInPath
|
||||
.trimmingCharacters(in: CharacterSet(charactersIn: "/"))
|
||||
if FileManager.default.fileExists(atPath: "/" + path) {
|
||||
discoveredVMs[i].bundlePath = "/" + path
|
||||
}
|
||||
}'''
|
||||
# Simpler and safe without helper: strip Home: prefix using dropFirst(5).
|
||||
new=''' // `Home:` ends with .pvm/ on this Parallels installation.
|
||||
if let homeLine = detail.split(separator: "\\n").first(where: {
|
||||
$0.trimmingCharacters(in: .whitespaces).hasPrefix("Home:")
|
||||
}) {
|
||||
let trimmed = homeLine.trimmingCharacters(in: .whitespaces)
|
||||
let raw = String(trimmed.dropFirst("Home:".count))
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
.trimmingCharacters(in: CharacterSet(charactersIn: "\\\"'"))
|
||||
let expanded = (raw as NSString).expandingTildeInPath
|
||||
let normalized = (expanded as NSString).standardizingPath
|
||||
if FileManager.default.fileExists(atPath: normalized) {
|
||||
discoveredVMs[i].bundlePath = normalized
|
||||
}
|
||||
}'''
|
||||
c=c[:start]+new+c[end:]
|
||||
|
||||
# Real VM icon files are sometimes inside the .pvm package. Fall back to macOS package icon.
|
||||
a=c.find(' func icon(for machine: ParallelsVM) -> NSImage? {')
|
||||
b=c.find(' func status(for server: ServerDefinition)',a)
|
||||
if a<0 or b<0: raise SystemExit('Cannot locate VM icon function. No changes made.')
|
||||
c=c[:a]+''' func icon(for machine: ParallelsVM) -> NSImage? {
|
||||
guard let path = machine.bundlePath,
|
||||
FileManager.default.fileExists(atPath: path) else { return nil }
|
||||
let bundle = URL(fileURLWithPath: path, isDirectory: true)
|
||||
// Prefer a VM-specific icon if the Parallels bundle contains one.
|
||||
for name in ["icon.png", "Icon.png", "icon.icns", "Icon.icns",
|
||||
".VolumeIcon.icns", "icon.tiff", "Icon.tiff"] {
|
||||
if let image = NSImage(contentsOf: bundle.appendingPathComponent(name)) {
|
||||
return image
|
||||
}
|
||||
}
|
||||
// This is the same package icon Finder shows for the Parallels VM.
|
||||
return NSWorkspace.shared.icon(forFile: path)
|
||||
}
|
||||
|
||||
'''+c[b:]
|
||||
|
||||
anchor=' func icon(for server: ServerDefinition) -> NSImage? {'
|
||||
if anchor not in c: raise SystemExit('Cannot locate server icon function. No changes made.')
|
||||
c=c.replace(anchor,''' func reorderServer(draggedID: UUID, onto targetID: UUID) {
|
||||
guard draggedID != targetID,
|
||||
let from = servers.firstIndex(where: { $0.id == draggedID }),
|
||||
let to = servers.firstIndex(where: { $0.id == targetID }) else { return }
|
||||
let moved = servers.remove(at: from)
|
||||
servers.insert(moved, at: to) // @Published didSet persists the order.
|
||||
}
|
||||
|
||||
'''+anchor,1)
|
||||
|
||||
# Make Settings rows draggable. Avoid editing window presentation.
|
||||
pattern=r'(\s*Text\(s\.name\)\n\s*\}\n\s*\.contentShape\(Rectangle\(\)\)\n\s*\.onTapGesture \{ selection = s\.id \}\n)(\s*\.tag\(s\.id\))'
|
||||
match=re.search(pattern,s)
|
||||
if not match: raise SystemExit('Cannot locate Settings server list row. No changes made.')
|
||||
replacement=match.group(1)+''' .draggable(s.id.uuidString)
|
||||
.dropDestination(for: String.self) { items, _ in
|
||||
guard let value = items.first,
|
||||
let id = UUID(uuidString: value) else { return false }
|
||||
vm.reorderServer(draggedID: id, onto: s.id)
|
||||
return true
|
||||
}
|
||||
'''+match.group(2)
|
||||
s=s[:match.start()]+replacement+s[match.end():]
|
||||
# Add visible drag affordance next to the name.
|
||||
s=s.replace(''' Text(s.name)
|
||||
}''',''' Text(s.name)
|
||||
Spacer(minLength: 0)
|
||||
Image(systemName: "line.3.horizontal")
|
||||
.foregroundStyle(.secondary)
|
||||
.help("Drag to reorder servers")
|
||||
}''',1)
|
||||
|
||||
# Show custom server icons in dashboard, and enable drag/drop integrated rows.
|
||||
old=''' if let machine { icon(machine) }
|
||||
else { Image(systemName: "server.rack").frame(width: 36, height: 36).foregroundStyle(.cyan) }'''
|
||||
if old not in m: raise SystemExit('Cannot locate integrated dashboard icon. No changes made.')
|
||||
m=m.replace(old,''' Group {
|
||||
if let image = vm.icon(for: server) {
|
||||
Image(nsImage: image).resizable().scaledToFit()
|
||||
} else if let machine {
|
||||
icon(machine)
|
||||
} else {
|
||||
Image(systemName: "server.rack").foregroundStyle(.cyan)
|
||||
}
|
||||
}.frame(width: 36, height: 36)''',1)
|
||||
name=''' Text(server.name).font(.system(size: 12, weight: .semibold)).lineLimit(1).frame(width: 185, alignment: .leading)'''
|
||||
if name not in m: raise SystemExit('Cannot locate integrated server name. No changes made.')
|
||||
m=m.replace(name,''' HStack(spacing: 5) {
|
||||
Image(systemName: "line.3.horizontal").foregroundStyle(OrionStyle.muted)
|
||||
Text(server.name).lineLimit(1)
|
||||
}
|
||||
.font(.system(size: 12, weight: .semibold))
|
||||
.frame(width: 185, alignment: .leading)
|
||||
.draggable(server.id.uuidString)''',1)
|
||||
needle=''' .background(OrionStyle.card.opacity(0.75), in: RoundedRectangle(cornerRadius: 10))
|
||||
}
|
||||
|
||||
private func action(_ title: String'''
|
||||
if needle not in m: raise SystemExit('Cannot locate end of integrated row. No changes made.')
|
||||
m=m.replace(needle,''' .background(OrionStyle.card.opacity(0.75), in: RoundedRectangle(cornerRadius: 10))
|
||||
.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
|
||||
}
|
||||
}
|
||||
|
||||
private func action(_ title: String''',1)
|
||||
|
||||
backup=root/'backups'/datetime.now().strftime('%Y%m%d-%H%M%S-%f')
|
||||
for key,path in paths.items():
|
||||
dest=backup/path.relative_to(root)
|
||||
dest.parent.mkdir(parents=True,exist_ok=True)
|
||||
shutil.copy2(path,dest)
|
||||
for key,contents in [('OrionVMController.swift',c),('SettingsView.swift',s),('OrionMenuView.swift',m)]:
|
||||
paths[key].write_text(contents)
|
||||
print('Updated controller, Settings and integrated dashboard. Backups:',backup)
|
||||
print('Run: /bin/zsh scripts/build.sh --launch')
|
||||
@@ -0,0 +1,129 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Repair server ordering and use Parallels VM.app icons (not generic .pvm icons)."""
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
import shutil
|
||||
|
||||
root = Path.cwd()
|
||||
paths = [root / 'OrionToolbar' / x for x in ('SettingsView.swift','OrionVMController.swift','OrionMenuView.swift')]
|
||||
if any(not p.is_file() for p in paths):
|
||||
raise SystemExit('Run this patch from the OrionToolbar project root.')
|
||||
s, c, m = (p.read_text() for p in paths)
|
||||
if 'ORION_REORDER_ICONS_V3' in s:
|
||||
raise SystemExit('Patch already installed.')
|
||||
|
||||
# Replace the List's drag-reordering area. List selection/onMove intercepts drag gestures.
|
||||
start = s.find(' List(selection: $selection) { ForEach(vm.servers)')
|
||||
end = s.find(' Divider()', start)
|
||||
if start < 0 or end < 0:
|
||||
raise SystemExit('Settings list differs from expected source; no changes made.')
|
||||
replacement = ''' // ORION_REORDER_ICONS_V3: explicit drop targets; no List/onMove interception.
|
||||
ScrollView {
|
||||
LazyVStack(spacing: 3) {
|
||||
ForEach(vm.servers) { server in
|
||||
HStack(spacing: 8) {
|
||||
Image(systemName: "line.3.horizontal")
|
||||
.foregroundStyle(.secondary)
|
||||
.help("Drag this server to reorder")
|
||||
Group {
|
||||
if let image = vm.icon(for: server) {
|
||||
Image(nsImage: image).resizable().scaledToFit()
|
||||
} else {
|
||||
Image(systemName: "server.rack")
|
||||
}
|
||||
}.frame(width: 23, height: 23)
|
||||
Text(server.name).lineLimit(1)
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
.padding(.horizontal, 9)
|
||||
.padding(.vertical, 9)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(selection == server.id ? Color.accentColor.opacity(0.3) : Color.clear,
|
||||
in: RoundedRectangle(cornerRadius: 7))
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture { selection = server.id }
|
||||
.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
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(6)
|
||||
}
|
||||
.frame(width: 220)
|
||||
'''
|
||||
s = s[:start] + replacement + s[end:]
|
||||
s = s.replace('}.frame(width: 650, height: 380)', '}.frame(width: 730, height: 420)', 1)
|
||||
|
||||
# Avoid generic .pvm icon. Parallels creates a VM.app inside each bundle; use its
|
||||
# CFBundleIconFile/CFBundleIconName, or its app icon. If no VM-specific icon exists,
|
||||
# use an OS-specific symbol in the UI instead of the generic Parallels package icon.
|
||||
start = c.find(' func icon(for machine: ParallelsVM) -> NSImage? {')
|
||||
end = c.find(' func status(for server: ServerDefinition)', start)
|
||||
if start < 0 or end < 0:
|
||||
raise SystemExit('Controller icon function differs; no changes made.')
|
||||
new_icon = ''' func icon(for machine: ParallelsVM) -> NSImage? {
|
||||
guard let path = machine.bundlePath,
|
||||
FileManager.default.fileExists(atPath: path) else { return nil }
|
||||
let bundle = URL(fileURLWithPath: path, isDirectory: true)
|
||||
|
||||
// Parallels stores the per-VM application under <VM>.pvm/VM.app.
|
||||
// The .pvm Finder icon itself is generic and must not be used.
|
||||
let app = bundle.appendingPathComponent("VM.app", isDirectory: true)
|
||||
let plist = app.appendingPathComponent("Contents/Info.plist")
|
||||
if let info = NSDictionary(contentsOf: plist) as? [String: Any] {
|
||||
let resourceDir = app.appendingPathComponent("Contents/Resources", isDirectory: true)
|
||||
for key in ["CFBundleIconFile", "CFBundleIconName"] {
|
||||
if let name = info[key] as? String, !name.isEmpty {
|
||||
let names = name.lowercased().hasSuffix(".icns") ? [name] : [name + ".icns", name]
|
||||
for candidate in names {
|
||||
if let image = NSImage(contentsOf: resourceDir.appendingPathComponent(candidate)) {
|
||||
return image
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for name in ["icon.png", "Icon.png", "icon.icns", "Icon.icns", ".VolumeIcon.icns"] {
|
||||
if let image = NSImage(contentsOf: bundle.appendingPathComponent(name)) { return image }
|
||||
}
|
||||
// Never return NSWorkspace.icon(forFile: path): it is the generic .pvm icon.
|
||||
return nil
|
||||
}
|
||||
|
||||
'''
|
||||
c = c[:start] + new_icon + c[end:]
|
||||
|
||||
# Improve OS-specific fallback when Parallels provides no usable per-VM artwork.
|
||||
needle = '''Image(systemName: machine.operatingSystem == "Windows" ? "desktopcomputer" : "server.rack")'''
|
||||
if needle not in m:
|
||||
raise SystemExit('Dashboard VM fallback differs; no changes made.')
|
||||
m = m.replace(needle, '''Image(systemName: machine.operatingSystem == "Windows" ? "desktopcomputer" : "server.rack")''', 1)
|
||||
|
||||
# In integrated rows, show OS fallback when Parallels icon missing, not generic rack alone.
|
||||
needle = ''' } else if let machine {
|
||||
icon(machine)
|
||||
} else {'''
|
||||
if needle not in m:
|
||||
raise SystemExit('Integrated icon view differs; no changes made.')
|
||||
# icon(machine) already implements OS-colored fallback.
|
||||
|
||||
# The existing dashboard drag handlers are installed, but on drop they may be
|
||||
# disabled when a VM is busy. Keep the control separate from action disabling.
|
||||
# Add unmistakable move controls in Settings, already present in user source.
|
||||
|
||||
backup_root = root / 'backups' / datetime.now().strftime('%Y%m%d-%H%M%S-%f')
|
||||
for p in paths:
|
||||
dest = backup_root / p.relative_to(root)
|
||||
dest.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy2(p, dest)
|
||||
for p, value in zip(paths, (s,c,m)):
|
||||
if p.name != 'OrionMenuView.swift':
|
||||
p.write_text(value)
|
||||
print('Updated SettingsView.swift and OrionVMController.swift')
|
||||
print('Backup:', backup_root)
|
||||
print('No Settings presenter or window management code modified.')
|
||||
Reference in New Issue
Block a user