updates
This commit is contained in:
+145
-398
@@ -1,415 +1,162 @@
|
||||
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
struct OrionMenuView: View {
|
||||
@EnvironmentObject var vm: OrionVMController
|
||||
@EnvironmentObject private var vm: OrionVMController
|
||||
@Environment(\.openSettings) private var openSettings
|
||||
|
||||
@State private var expandedGroups: Set<String> = []
|
||||
@State private var expanded: Set<String> = []
|
||||
@State private var expandedServers: Set<UUID> = []
|
||||
|
||||
private var groups: [String] {
|
||||
let preferred = [
|
||||
"Windows", "Ubuntu", "Debian", "Fedora",
|
||||
"CentOS", "Alpine", "Oracle Linux",
|
||||
"Rocky Linux", "AlmaLinux", "Arch Linux",
|
||||
"Gentoo", "FreeBSD", "Other"
|
||||
]
|
||||
|
||||
return preferred.filter { os in
|
||||
vm.discoveredVMs.contains {
|
||||
$0.operatingSystem == os
|
||||
}
|
||||
}
|
||||
let order = ["Windows", "Ubuntu", "Debian", "Fedora", "CentOS", "Alpine", "Oracle Linux", "Rocky Linux", "AlmaLinux", "Arch Linux", "Gentoo", "FreeBSD", "Other"]
|
||||
return order.filter { os in vm.discoveredVMs.contains { $0.operatingSystem == os } }
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
header
|
||||
|
||||
Divider()
|
||||
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
discoverySection
|
||||
|
||||
Divider()
|
||||
.padding(.vertical, 10)
|
||||
|
||||
integratedSection
|
||||
}
|
||||
.padding(.horizontal, 14)
|
||||
.padding(.vertical, 10)
|
||||
}
|
||||
.frame(maxHeight: 560)
|
||||
|
||||
Divider()
|
||||
|
||||
footer
|
||||
}
|
||||
.frame(width: 410)
|
||||
.task {
|
||||
await vm.discoverVMs()
|
||||
}
|
||||
.alert(
|
||||
"OrionToolbar",
|
||||
isPresented: Binding(
|
||||
get: { vm.lastError != nil },
|
||||
set: { if !$0 { vm.lastError = nil } }
|
||||
)
|
||||
) {
|
||||
Button("OK") { vm.lastError = nil }
|
||||
} message: {
|
||||
Text(vm.lastError ?? "")
|
||||
}
|
||||
}
|
||||
|
||||
private var header: some View {
|
||||
HStack {
|
||||
Image(systemName: "server.rack")
|
||||
.foregroundStyle(.blue)
|
||||
|
||||
Text("OrionToolbar")
|
||||
.font(.headline)
|
||||
|
||||
Spacer()
|
||||
|
||||
if vm.discovering {
|
||||
ProgressView()
|
||||
.controlSize(.small)
|
||||
}
|
||||
|
||||
Button {
|
||||
Task { await vm.discoverVMs() }
|
||||
} label: {
|
||||
Image(systemName: "arrow.clockwise")
|
||||
}
|
||||
.buttonStyle(.borderless)
|
||||
.disabled(vm.discovering)
|
||||
.help("Refresh Parallels virtual machines")
|
||||
}
|
||||
.padding(16)
|
||||
}
|
||||
|
||||
private var discoverySection: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
VStack(spacing: 0) {
|
||||
HStack {
|
||||
Text("PARALLELS VIRTUAL MACHINES")
|
||||
.font(.caption)
|
||||
.fontWeight(.semibold)
|
||||
.foregroundStyle(.secondary)
|
||||
|
||||
Label("OrionToolbar", systemImage: "server.rack").font(.headline)
|
||||
Spacer()
|
||||
|
||||
Text("\(vm.discoveredVMs.count)")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
if vm.discoveredVMs.isEmpty {
|
||||
ContentUnavailableView(
|
||||
"No Virtual Machines",
|
||||
systemImage: "desktopcomputer",
|
||||
description: Text(
|
||||
"Refresh to discover Parallels virtual machines."
|
||||
)
|
||||
)
|
||||
.frame(height: 120)
|
||||
}
|
||||
|
||||
ForEach(groups, id: \.self) { group in
|
||||
operatingSystemGroup(group)
|
||||
}
|
||||
|
||||
if !vm.discoveredVMs.isEmpty {
|
||||
Divider()
|
||||
.padding(.vertical, 6)
|
||||
|
||||
HStack {
|
||||
Text("\(vm.selectedVMIDs.count) selected")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
|
||||
Spacer()
|
||||
|
||||
Button("Select All") {
|
||||
vm.selectAllVMs()
|
||||
}
|
||||
|
||||
Button("Clear") {
|
||||
vm.clearVMSelection()
|
||||
}
|
||||
.disabled(vm.selectedVMIDs.isEmpty)
|
||||
}
|
||||
|
||||
Button {
|
||||
vm.integrateSelectedVMs()
|
||||
} label: {
|
||||
Label(
|
||||
"Integrate Selected",
|
||||
systemImage: "plus.circle.fill"
|
||||
)
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.disabled(vm.selectedVMIDs.isEmpty)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func operatingSystemGroup(
|
||||
_ group: String
|
||||
) -> some View {
|
||||
let machines = vm.discoveredVMs.filter {
|
||||
$0.operatingSystem == group
|
||||
}
|
||||
|
||||
return VStack(alignment: .leading, spacing: 3) {
|
||||
Button {
|
||||
if expandedGroups.contains(group) {
|
||||
expandedGroups.remove(group)
|
||||
} else {
|
||||
expandedGroups.insert(group)
|
||||
}
|
||||
} label: {
|
||||
HStack(spacing: 10) {
|
||||
Image(systemName:
|
||||
expandedGroups.contains(group)
|
||||
? "chevron.down"
|
||||
: "chevron.right"
|
||||
)
|
||||
.font(.caption)
|
||||
.frame(width: 12)
|
||||
|
||||
Image(systemName: machines.first?.symbol
|
||||
?? "desktopcomputer"
|
||||
)
|
||||
.frame(width: 22)
|
||||
|
||||
Text(group)
|
||||
.fontWeight(.medium)
|
||||
|
||||
Spacer()
|
||||
|
||||
Text("\(machines.count)")
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.padding(.vertical, 9)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
|
||||
if expandedGroups.contains(group) {
|
||||
ForEach(machines) { machine in
|
||||
machineRow(machine)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func machineRow(
|
||||
_ machine: ParallelsVM
|
||||
) -> some View {
|
||||
HStack(alignment: .center, spacing: 10) {
|
||||
Toggle(
|
||||
"",
|
||||
isOn: Binding(
|
||||
get: {
|
||||
vm.selectedVMIDs.contains(machine.id)
|
||||
},
|
||||
set: { selected in
|
||||
if selected {
|
||||
vm.selectedVMIDs.insert(machine.id)
|
||||
} else {
|
||||
vm.selectedVMIDs.remove(machine.id)
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
.labelsHidden()
|
||||
.toggleStyle(.checkbox)
|
||||
|
||||
if let icon = vm.icon(for: machine) {
|
||||
Image(nsImage: icon)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 30, height: 30)
|
||||
} else {
|
||||
Image(systemName: machine.symbol)
|
||||
.font(.title3)
|
||||
.frame(width: 30, height: 30)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
VStack(alignment: .leading, spacing: 3) {
|
||||
Text(machine.name)
|
||||
.font(.system(size: 13, weight: .medium))
|
||||
|
||||
HStack(spacing: 5) {
|
||||
Circle()
|
||||
.fill(
|
||||
machine.status.lowercased() == "running"
|
||||
? Color.green : Color.gray
|
||||
)
|
||||
.frame(width: 7, height: 7)
|
||||
|
||||
Text(machine.status.capitalized)
|
||||
|
||||
if vm.isIntegrated(machine) {
|
||||
Text("· Integrated")
|
||||
.foregroundStyle(.green)
|
||||
}
|
||||
}
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
.padding(.leading, 22)
|
||||
.padding(.vertical, 6)
|
||||
}
|
||||
|
||||
private var integratedSection: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("INTEGRATED SERVERS")
|
||||
.font(.caption)
|
||||
.fontWeight(.semibold)
|
||||
.foregroundStyle(.secondary)
|
||||
|
||||
ForEach(vm.servers) { server in
|
||||
integratedServerRow(server)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func integratedServerRow(
|
||||
_ server: ServerDefinition
|
||||
) -> some View {
|
||||
let status = vm.status(for: server)
|
||||
let expanded = expandedServers.contains(server.id)
|
||||
|
||||
return VStack(alignment: .leading, spacing: 5) {
|
||||
Button {
|
||||
if expanded {
|
||||
expandedServers.remove(server.id)
|
||||
} else {
|
||||
expandedServers.insert(server.id)
|
||||
}
|
||||
} label: {
|
||||
HStack(spacing: 10) {
|
||||
Image(systemName:
|
||||
expanded ? "chevron.down" : "chevron.right"
|
||||
)
|
||||
.font(.caption)
|
||||
|
||||
Circle()
|
||||
.fill(status == .running
|
||||
? Color.green : Color.gray)
|
||||
.frame(width: 9, height: 9)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(server.name)
|
||||
.fontWeight(.medium)
|
||||
|
||||
Text(status.title)
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.padding(.vertical, 8)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
|
||||
if expanded {
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
if status == .stopped {
|
||||
action("Start", "play.fill") {
|
||||
vm.start(server)
|
||||
}
|
||||
} else {
|
||||
action("Stop", "stop.fill") {
|
||||
vm.stop(server)
|
||||
}
|
||||
.disabled(vm.isBusy(server))
|
||||
|
||||
action("Restart", "arrow.clockwise") {
|
||||
vm.restart(server)
|
||||
}
|
||||
.disabled(
|
||||
vm.isBusy(server) ||
|
||||
status != .running
|
||||
)
|
||||
|
||||
action(
|
||||
"Force Stop",
|
||||
"exclamationmark.triangle"
|
||||
) {
|
||||
vm.forceStop(server)
|
||||
}
|
||||
.disabled(vm.isBusy(server))
|
||||
}
|
||||
|
||||
action("Open SSH in Terminal", "terminal") {
|
||||
vm.openSSH(server)
|
||||
}
|
||||
.disabled(
|
||||
status != .running ||
|
||||
server.host.isEmpty
|
||||
)
|
||||
|
||||
action("Open Mailpit", "envelope") {
|
||||
vm.openMailpit(server)
|
||||
}
|
||||
.disabled(
|
||||
status != .running ||
|
||||
server.mailpitPort == nil ||
|
||||
server.host.isEmpty
|
||||
)
|
||||
}
|
||||
.padding(.leading, 26)
|
||||
.padding(.bottom, 8)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func action(
|
||||
_ title: String,
|
||||
_ symbol: String,
|
||||
perform: @escaping () -> Void
|
||||
) -> some View {
|
||||
Button(action: perform) {
|
||||
Label(title, systemImage: symbol)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(.vertical, 5)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
private var footer: some View {
|
||||
VStack(spacing: 2) {
|
||||
action("Open Parallels Desktop", "macwindow") {
|
||||
vm.openParallels()
|
||||
}
|
||||
|
||||
action("Settings…", "gearshape") {
|
||||
openSettings()
|
||||
NSApplication.shared.activate(
|
||||
ignoringOtherApps: true
|
||||
)
|
||||
}
|
||||
|
||||
if vm.discovering { ProgressView().controlSize(.small) }
|
||||
Button { Task { await vm.discoverVMs() } } label: { Image(systemName: "arrow.clockwise") }
|
||||
.buttonStyle(.borderless).help("Refresh virtual machines")
|
||||
}.padding(14)
|
||||
Divider()
|
||||
|
||||
action("Quit OrionToolbar", "xmark") {
|
||||
NSApplication.shared.terminate(nil)
|
||||
}
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
Text("PARALLELS VIRTUAL MACHINES").font(.caption.bold()).foregroundStyle(.secondary)
|
||||
if vm.discoveredVMs.isEmpty {
|
||||
Text(vm.discovering ? "Discovering virtual machines…" : "No VMs found. Use Refresh to try again.")
|
||||
.foregroundStyle(.secondary).padding(.vertical, 18)
|
||||
}
|
||||
ForEach(groups, id: \.self) { os in
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Button {
|
||||
if !expanded.insert(os).inserted { expanded.remove(os) }
|
||||
} label: {
|
||||
HStack {
|
||||
Image(systemName: expanded.contains(os) ? "chevron.down" : "chevron.right")
|
||||
.frame(width: 14)
|
||||
Text(os).fontWeight(.semibold)
|
||||
Spacer()
|
||||
Text("\(vm.discoveredVMs.filter { $0.operatingSystem == os }.count)")
|
||||
.foregroundStyle(.secondary)
|
||||
}.contentShape(Rectangle()).padding(.vertical, 5)
|
||||
}.buttonStyle(.plain)
|
||||
if expanded.contains(os) {
|
||||
ForEach(vm.discoveredVMs.filter { $0.operatingSystem == os }) { machine in
|
||||
vmRow(machine)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !vm.discoveredVMs.isEmpty {
|
||||
HStack {
|
||||
Button("Select All") { vm.selectAllVMs() }
|
||||
Button("Clear") { vm.clearVMSelection() }
|
||||
Spacer()
|
||||
Button("Integrate Selected") { vm.integrateSelectedVMs() }
|
||||
.disabled(vm.selectedVMIDs.isEmpty)
|
||||
}.font(.caption)
|
||||
}
|
||||
Divider()
|
||||
Text("INTEGRATED SERVERS").font(.caption.bold()).foregroundStyle(.secondary)
|
||||
ForEach(vm.servers) { server in serverRow(server) }
|
||||
}.padding(14)
|
||||
}.frame(height: 490)
|
||||
Divider()
|
||||
HStack {
|
||||
Button("Parallels") { vm.openParallels() }
|
||||
Spacer()
|
||||
Button("Settings…") {
|
||||
openSettings()
|
||||
NSApplication.shared.activate(ignoringOtherApps: true)
|
||||
}
|
||||
Button("Quit") { NSApplication.shared.terminate(nil) }
|
||||
}.padding(14)
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.vertical, 10)
|
||||
.frame(width: 460)
|
||||
.task { await vm.discoverVMs() }
|
||||
.alert("OrionToolbar", isPresented: Binding(
|
||||
get: { vm.lastError != nil },
|
||||
set: { if !$0 { vm.lastError = nil } }
|
||||
)) { Button("OK") { vm.lastError = nil } }
|
||||
message: { Text(vm.lastError ?? "") }
|
||||
}
|
||||
|
||||
private func vmRow(_ machine: ParallelsVM) -> some View {
|
||||
HStack(spacing: 9) {
|
||||
Toggle("", isOn: Binding(
|
||||
get: { vm.selectedVMIDs.contains(machine.id) },
|
||||
set: { selected in
|
||||
if selected { vm.selectedVMIDs.insert(machine.id) }
|
||||
else { vm.selectedVMIDs.remove(machine.id) }
|
||||
}
|
||||
)).labelsHidden().toggleStyle(.checkbox)
|
||||
vmIcon(machine)
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(machine.name).lineLimit(1)
|
||||
Text(machine.status.capitalized).font(.caption)
|
||||
.foregroundStyle(machine.status == "running" ? Color.green : Color.secondary)
|
||||
}
|
||||
Spacer(minLength: 4)
|
||||
if vm.busyVMIDs.contains(machine.id) { ProgressView().controlSize(.small) }
|
||||
else if machine.status == "stopped" {
|
||||
Button("Start") { vm.operate(machine, action: "start") }
|
||||
} else if machine.status == "running" {
|
||||
Button("Stop") { vm.operate(machine, action: "stop") }
|
||||
} else if machine.status == "suspended" {
|
||||
Button("Resume") { vm.operate(machine, action: "resume") }
|
||||
}
|
||||
if vm.isIntegrated(machine) {
|
||||
Image(systemName: "checkmark.circle.fill").foregroundStyle(.green).help("Integrated")
|
||||
} else {
|
||||
Button { vm.integrate(machine) } label: { Image(systemName: "plus.circle") }
|
||||
.help("Integrate VM")
|
||||
}
|
||||
}.padding(.leading, 20).padding(.vertical, 4)
|
||||
}
|
||||
|
||||
private func vmIcon(_ machine: ParallelsVM) -> some View {
|
||||
Group {
|
||||
if let icon = vm.icon(for: machine) {
|
||||
Image(nsImage: icon).resizable().scaledToFit()
|
||||
} else {
|
||||
Image(systemName: machine.symbol).resizable().scaledToFit().padding(4)
|
||||
}
|
||||
}.frame(width: 30, height: 30)
|
||||
}
|
||||
|
||||
private func serverRow(_ server: ServerDefinition) -> some View {
|
||||
let status = vm.status(for: server)
|
||||
return VStack(alignment: .leading, spacing: 6) {
|
||||
Button {
|
||||
if !expandedServers.insert(server.id).inserted { expandedServers.remove(server.id) }
|
||||
} label: {
|
||||
HStack {
|
||||
Image(systemName: expandedServers.contains(server.id) ? "chevron.down" : "chevron.right")
|
||||
if let icon = vm.icon(for: server) {
|
||||
Image(nsImage: icon).resizable().scaledToFit().frame(width: 25, height: 25)
|
||||
} else { Image(systemName: "server.rack") }
|
||||
Text(server.name)
|
||||
Spacer()
|
||||
Text(status.title).foregroundStyle(.secondary)
|
||||
}.contentShape(Rectangle())
|
||||
}.buttonStyle(.plain)
|
||||
if expandedServers.contains(server.id) {
|
||||
HStack {
|
||||
if status == .stopped {
|
||||
Button("Start") { vm.start(server) }
|
||||
} else if status == .running {
|
||||
Button("Stop") { vm.stop(server) }
|
||||
Button("Restart") { vm.restart(server) }
|
||||
}
|
||||
Button("SSH") { vm.openSSH(server) }
|
||||
.disabled(status != .running || server.host.isEmpty || server.sshUser.isEmpty)
|
||||
Button("Mailpit") { vm.openMailpit(server) }
|
||||
.disabled(status != .running || server.host.isEmpty || server.mailpitPort == nil)
|
||||
}.padding(.leading, 30)
|
||||
}
|
||||
}.padding(.vertical, 4)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@ final class OrionVMController: ObservableObject {
|
||||
@Published var discoveredVMs: [ParallelsVM] = []
|
||||
@Published var selectedVMIDs: Set<String> = []
|
||||
@Published var discovering = false
|
||||
@Published var busyVMIDs: Set<String> = []
|
||||
private var timer: Timer?
|
||||
private let defaultsKey = "serverDefinitions.v2"
|
||||
|
||||
@@ -82,7 +83,7 @@ final class OrionVMController: ObservableObject {
|
||||
await discoverVMs()
|
||||
await refreshAll()
|
||||
}
|
||||
timer = Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { [weak self] _ in Task { @MainActor in await self?.refreshAll() } }
|
||||
timer = Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { [weak self] _ in Task { @MainActor in guard let self else { return }; await self.discoverVMs(); await self.refreshAll() } }
|
||||
}
|
||||
deinit { timer?.invalidate() }
|
||||
|
||||
@@ -128,6 +129,17 @@ final class OrionVMController: ObservableObject {
|
||||
== .orderedAscending
|
||||
}
|
||||
|
||||
// Resolve Parallels VM bundles without requiring the guest to run.
|
||||
for i in discoveredVMs.indices {
|
||||
if let detail = try? await runPrlctl(["list", "-i", discoveredVMs[i].id]) {
|
||||
let pattern = #"(?m)^\s*Home:\s*(.+?\.pvm)\s*$"#
|
||||
if let range = detail.range(of: pattern, options: .regularExpression) {
|
||||
let line = String(detail[range.lowerBound..<range.upperBound])
|
||||
let path = line.replacingOccurrences(of: #"^\s*Home:\s*"#, with: "", options: .regularExpression)
|
||||
discoveredVMs[i].bundlePath = path.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
}
|
||||
}
|
||||
}
|
||||
// Keep selections only for VMs still present.
|
||||
let available = Set(discoveredVMs.map(\.id))
|
||||
selectedVMIDs.formIntersection(available)
|
||||
@@ -219,7 +231,7 @@ final class OrionVMController: ObservableObject {
|
||||
func refreshStatus(_ server: ServerDefinition) async {
|
||||
guard !isBusy(server) else { return }
|
||||
do {
|
||||
let output = try await runPrlctl(["status", server.vmName]); let value = output.lowercased()
|
||||
let output = try await runPrlctl(["status", server.vmUUID ?? server.vmName]); let value = output.lowercased()
|
||||
if value.contains("running") { statuses[server.id] = .running }
|
||||
else if value.contains("stopped") { statuses[server.id] = .stopped }
|
||||
else if value.contains("suspended") || value.contains("paused") { statuses[server.id] = .suspended }
|
||||
@@ -227,16 +239,43 @@ final class OrionVMController: ObservableObject {
|
||||
} catch { statuses[server.id] = .unavailable(error.localizedDescription) }
|
||||
}
|
||||
|
||||
func start(_ s: ServerDefinition) { perform(["start", s.vmName], server: s) }
|
||||
func stop(_ s: ServerDefinition) { perform(["stop", s.vmName], server: s) }
|
||||
func restart(_ s: ServerDefinition) { perform(["restart", s.vmName], server: s) }
|
||||
func forceStop(_ s: ServerDefinition) { perform(["stop", s.vmName, "--kill"], server: s) }
|
||||
func start(_ s: ServerDefinition) { perform(["start", s.vmUUID ?? s.vmName], server: s) }
|
||||
func stop(_ s: ServerDefinition) { perform(["stop", s.vmUUID ?? s.vmName], server: s) }
|
||||
func restart(_ s: ServerDefinition) { perform(["restart", s.vmUUID ?? s.vmName], server: s) }
|
||||
func forceStop(_ s: ServerDefinition) { perform(["stop", s.vmUUID ?? s.vmName, "--kill"], server: s) }
|
||||
|
||||
private func perform(_ arguments: [String], server: ServerDefinition) {
|
||||
guard !isBusy(server) else { return }; busyServers.insert(server.id); statuses[server.id] = .transitioning; lastError = nil
|
||||
Task { do { _ = try await runPrlctl(arguments) } catch { lastError = error.localizedDescription }; busyServers.remove(server.id); try? await Task.sleep(for: .seconds(1)); await refreshStatus(server) }
|
||||
}
|
||||
|
||||
func operate(_ machine: ParallelsVM, action: String) {
|
||||
guard !busyVMIDs.contains(machine.id) else { return }
|
||||
busyVMIDs.insert(machine.id)
|
||||
lastError = nil
|
||||
Task {
|
||||
do { _ = try await runPrlctl([action, machine.id]) }
|
||||
catch { lastError = error.localizedDescription }
|
||||
busyVMIDs.remove(machine.id)
|
||||
await discoverVMs()
|
||||
await refreshAll()
|
||||
}
|
||||
}
|
||||
|
||||
func integrate(_ machine: ParallelsVM) {
|
||||
guard !isIntegrated(machine) else { return }
|
||||
add(ServerDefinition(name: machine.name, vmName: machine.name,
|
||||
vmUUID: machine.id, host: machine.ipAddress, sshUser: "",
|
||||
sshPort: 22, sshIdentityFile: "", mailpitPort: nil))
|
||||
}
|
||||
|
||||
func icon(for server: ServerDefinition) -> NSImage? {
|
||||
guard let machine = discoveredVMs.first(where: {
|
||||
$0.id == server.vmUUID || $0.name == server.vmName
|
||||
}) else { return nil }
|
||||
return icon(for: machine)
|
||||
}
|
||||
|
||||
func openSSH(_ s: ServerDefinition) {
|
||||
let userHost = "\(s.sshUser)@\(s.host)"
|
||||
var command = "/usr/bin/ssh -p \(s.sshPort)"
|
||||
@@ -291,7 +330,7 @@ final class OrionVMController: ObservableObject {
|
||||
private func prlctlURL() -> URL? { ["/usr/local/bin/prlctl", "/Applications/Parallels Desktop.app/Contents/MacOS/prlctl"].map(URL.init(fileURLWithPath:)).first { FileManager.default.isExecutableFile(atPath: $0.path) } }
|
||||
private func runPrlctl(_ arguments: [String]) async throws -> String {
|
||||
guard let executable = prlctlURL() else { throw OrionError.prlctlNotFound }
|
||||
return try await Task.detached(priority: .userInitiated) { let p = Process(); let pipe = Pipe(); p.executableURL = executable; p.arguments = arguments; p.standardOutput = pipe; p.standardError = pipe; try p.run(); p.waitUntilExit(); let out = String(decoding: pipe.fileHandleForReading.readDataToEndOfFile(), as: UTF8.self); guard p.terminationStatus == 0 else { throw OrionError.commandFailed(out) }; return out }.value
|
||||
return try await Task.detached(priority: .userInitiated) { let p = Process(); let pipe = Pipe(); p.executableURL = executable; p.arguments = arguments; p.standardOutput = pipe; p.standardError = pipe; try p.run(); let data = pipe.fileHandleForReading.readDataToEndOfFile(); p.waitUntilExit(); let out = String(decoding: data, as: UTF8.self); guard p.terminationStatus == 0 else { throw OrionError.commandFailed(out) }; return out }.value
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,14 @@ struct SettingsView: View {
|
||||
@EnvironmentObject var vm: OrionVMController
|
||||
@State private var selection: UUID?
|
||||
@State private var editing: ServerDefinition?
|
||||
@State private var addingVMs = false
|
||||
var body: some View {
|
||||
HStack(spacing: 0) {
|
||||
List(selection: $selection) { ForEach(vm.servers) { s in Label(s.name, systemImage: vm.status(for: s).symbolName).tag(s.id) } }
|
||||
List(selection: $selection) { ForEach(vm.servers) { s in HStack {
|
||||
if let icon = vm.icon(for: s) { Image(nsImage: icon).resizable().scaledToFit().frame(width: 22, height: 22) }
|
||||
else { Image(systemName: vm.status(for: s).symbolName) }
|
||||
Text(s.name)
|
||||
}.tag(s.id) } }
|
||||
.frame(width: 190)
|
||||
Divider()
|
||||
VStack(alignment: .leading, spacing: 14) {
|
||||
@@ -17,9 +22,35 @@ struct SettingsView: View {
|
||||
Spacer()
|
||||
} else { ContentUnavailableView("Select a Server", systemImage: "server.rack") }
|
||||
Divider()
|
||||
HStack { Button("Add Server…", systemImage: "plus") { editing = ServerDefinition(name: "New Server", vmName: "", host: "", sshUser: "sysadmin", sshPort: 22, sshIdentityFile: "", mailpitPort: nil) }; Spacer(); Button("Delete", role: .destructive) { if let id = selection, let i = vm.servers.firstIndex(where: {$0.id == id}) { vm.delete(at: IndexSet(integer: i)); selection = nil } }.disabled(selection == nil) }
|
||||
HStack { Button("Add Server…", systemImage: "plus") { addingVMs = true }; Spacer(); Button("Delete", role: .destructive) { if let id = selection, let i = vm.servers.firstIndex(where: {$0.id == id}) { vm.delete(at: IndexSet(integer: i)); selection = nil } }.disabled(selection == nil) }
|
||||
}.padding(20)
|
||||
}.frame(width: 650, height: 380)
|
||||
.sheet(isPresented: $addingVMs) {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text("Add Parallels Virtual Machines").font(.title2.bold())
|
||||
List(vm.discoveredVMs) { machine in
|
||||
HStack {
|
||||
Toggle(machine.name, isOn: Binding(
|
||||
get: { vm.selectedVMIDs.contains(machine.id) },
|
||||
set: { value in
|
||||
if value { vm.selectedVMIDs.insert(machine.id) }
|
||||
else { vm.selectedVMIDs.remove(machine.id) }
|
||||
}
|
||||
))
|
||||
Spacer()
|
||||
if vm.isIntegrated(machine) { Text("Integrated").foregroundStyle(.secondary) }
|
||||
}
|
||||
}
|
||||
HStack {
|
||||
Button("Refresh") { Task { await vm.discoverVMs() } }
|
||||
Spacer()
|
||||
Button("Cancel") { addingVMs = false }
|
||||
Button("Integrate Selected") { vm.integrateSelectedVMs(); addingVMs = false }
|
||||
.disabled(vm.selectedVMIDs.isEmpty)
|
||||
}
|
||||
}.padding(20).frame(width: 530, height: 420)
|
||||
.task { await vm.discoverVMs() }
|
||||
}
|
||||
.sheet(item: $editing) { server in ServerEditor(server: server, isNew: !vm.servers.contains(where: {$0.id == server.id})) { value, isNew in if isNew { vm.add(value) } else { vm.update(value) }; selection = value.id } }
|
||||
}
|
||||
}
|
||||
@@ -41,7 +72,7 @@ struct ServerEditor: View {
|
||||
TextField("SSH identity file (optional)", text: $server.sshIdentityFile, prompt: Text("~/.ssh/id_ed25519"))
|
||||
TextField("Mailpit port (optional)", text: Binding(get: { server.mailpitPort.map(String.init) ?? "" }, set: { server.mailpitPort = Int($0) }))
|
||||
}
|
||||
HStack { Spacer(); Button("Cancel") { dismiss() }; Button("Save") { save(server, isNew); dismiss() }.keyboardShortcut(.defaultAction).disabled(server.name.isEmpty || server.vmName.isEmpty || server.host.isEmpty || server.sshUser.isEmpty || server.sshPort < 1 || server.sshPort > 65535) }
|
||||
HStack { Spacer(); Button("Cancel") { dismiss() }; Button("Save") { save(server, isNew); dismiss() }.keyboardShortcut(.defaultAction).disabled(server.name.isEmpty || server.vmName.isEmpty || server.sshPort < 1 || server.sshPort > 65535) }
|
||||
}.padding(20).frame(width: 470)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,415 @@
|
||||
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
struct OrionMenuView: View {
|
||||
@EnvironmentObject var vm: OrionVMController
|
||||
@Environment(\.openSettings) private var openSettings
|
||||
|
||||
@State private var expandedGroups: Set<String> = []
|
||||
@State private var expandedServers: Set<UUID> = []
|
||||
|
||||
private var groups: [String] {
|
||||
let preferred = [
|
||||
"Windows", "Ubuntu", "Debian", "Fedora",
|
||||
"CentOS", "Alpine", "Oracle Linux",
|
||||
"Rocky Linux", "AlmaLinux", "Arch Linux",
|
||||
"Gentoo", "FreeBSD", "Other"
|
||||
]
|
||||
|
||||
return preferred.filter { os in
|
||||
vm.discoveredVMs.contains {
|
||||
$0.operatingSystem == os
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
header
|
||||
|
||||
Divider()
|
||||
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
discoverySection
|
||||
|
||||
Divider()
|
||||
.padding(.vertical, 10)
|
||||
|
||||
integratedSection
|
||||
}
|
||||
.padding(.horizontal, 14)
|
||||
.padding(.vertical, 10)
|
||||
}
|
||||
.frame(maxHeight: 560)
|
||||
|
||||
Divider()
|
||||
|
||||
footer
|
||||
}
|
||||
.frame(width: 410)
|
||||
.task {
|
||||
await vm.discoverVMs()
|
||||
}
|
||||
.alert(
|
||||
"OrionToolbar",
|
||||
isPresented: Binding(
|
||||
get: { vm.lastError != nil },
|
||||
set: { if !$0 { vm.lastError = nil } }
|
||||
)
|
||||
) {
|
||||
Button("OK") { vm.lastError = nil }
|
||||
} message: {
|
||||
Text(vm.lastError ?? "")
|
||||
}
|
||||
}
|
||||
|
||||
private var header: some View {
|
||||
HStack {
|
||||
Image(systemName: "server.rack")
|
||||
.foregroundStyle(.blue)
|
||||
|
||||
Text("OrionToolbar")
|
||||
.font(.headline)
|
||||
|
||||
Spacer()
|
||||
|
||||
if vm.discovering {
|
||||
ProgressView()
|
||||
.controlSize(.small)
|
||||
}
|
||||
|
||||
Button {
|
||||
Task { await vm.discoverVMs() }
|
||||
} label: {
|
||||
Image(systemName: "arrow.clockwise")
|
||||
}
|
||||
.buttonStyle(.borderless)
|
||||
.disabled(vm.discovering)
|
||||
.help("Refresh Parallels virtual machines")
|
||||
}
|
||||
.padding(16)
|
||||
}
|
||||
|
||||
private var discoverySection: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack {
|
||||
Text("PARALLELS VIRTUAL MACHINES")
|
||||
.font(.caption)
|
||||
.fontWeight(.semibold)
|
||||
.foregroundStyle(.secondary)
|
||||
|
||||
Spacer()
|
||||
|
||||
Text("\(vm.discoveredVMs.count)")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
if vm.discoveredVMs.isEmpty {
|
||||
ContentUnavailableView(
|
||||
"No Virtual Machines",
|
||||
systemImage: "desktopcomputer",
|
||||
description: Text(
|
||||
"Refresh to discover Parallels virtual machines."
|
||||
)
|
||||
)
|
||||
.frame(height: 120)
|
||||
}
|
||||
|
||||
ForEach(groups, id: \.self) { group in
|
||||
operatingSystemGroup(group)
|
||||
}
|
||||
|
||||
if !vm.discoveredVMs.isEmpty {
|
||||
Divider()
|
||||
.padding(.vertical, 6)
|
||||
|
||||
HStack {
|
||||
Text("\(vm.selectedVMIDs.count) selected")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
|
||||
Spacer()
|
||||
|
||||
Button("Select All") {
|
||||
vm.selectAllVMs()
|
||||
}
|
||||
|
||||
Button("Clear") {
|
||||
vm.clearVMSelection()
|
||||
}
|
||||
.disabled(vm.selectedVMIDs.isEmpty)
|
||||
}
|
||||
|
||||
Button {
|
||||
vm.integrateSelectedVMs()
|
||||
} label: {
|
||||
Label(
|
||||
"Integrate Selected",
|
||||
systemImage: "plus.circle.fill"
|
||||
)
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.disabled(vm.selectedVMIDs.isEmpty)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func operatingSystemGroup(
|
||||
_ group: String
|
||||
) -> some View {
|
||||
let machines = vm.discoveredVMs.filter {
|
||||
$0.operatingSystem == group
|
||||
}
|
||||
|
||||
return VStack(alignment: .leading, spacing: 3) {
|
||||
Button {
|
||||
if expandedGroups.contains(group) {
|
||||
expandedGroups.remove(group)
|
||||
} else {
|
||||
expandedGroups.insert(group)
|
||||
}
|
||||
} label: {
|
||||
HStack(spacing: 10) {
|
||||
Image(systemName:
|
||||
expandedGroups.contains(group)
|
||||
? "chevron.down"
|
||||
: "chevron.right"
|
||||
)
|
||||
.font(.caption)
|
||||
.frame(width: 12)
|
||||
|
||||
Image(systemName: machines.first?.symbol
|
||||
?? "desktopcomputer"
|
||||
)
|
||||
.frame(width: 22)
|
||||
|
||||
Text(group)
|
||||
.fontWeight(.medium)
|
||||
|
||||
Spacer()
|
||||
|
||||
Text("\(machines.count)")
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.padding(.vertical, 9)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
|
||||
if expandedGroups.contains(group) {
|
||||
ForEach(machines) { machine in
|
||||
machineRow(machine)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func machineRow(
|
||||
_ machine: ParallelsVM
|
||||
) -> some View {
|
||||
HStack(alignment: .center, spacing: 10) {
|
||||
Toggle(
|
||||
"",
|
||||
isOn: Binding(
|
||||
get: {
|
||||
vm.selectedVMIDs.contains(machine.id)
|
||||
},
|
||||
set: { selected in
|
||||
if selected {
|
||||
vm.selectedVMIDs.insert(machine.id)
|
||||
} else {
|
||||
vm.selectedVMIDs.remove(machine.id)
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
.labelsHidden()
|
||||
.toggleStyle(.checkbox)
|
||||
|
||||
if let icon = vm.icon(for: machine) {
|
||||
Image(nsImage: icon)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 30, height: 30)
|
||||
} else {
|
||||
Image(systemName: machine.symbol)
|
||||
.font(.title3)
|
||||
.frame(width: 30, height: 30)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
VStack(alignment: .leading, spacing: 3) {
|
||||
Text(machine.name)
|
||||
.font(.system(size: 13, weight: .medium))
|
||||
|
||||
HStack(spacing: 5) {
|
||||
Circle()
|
||||
.fill(
|
||||
machine.status.lowercased() == "running"
|
||||
? Color.green : Color.gray
|
||||
)
|
||||
.frame(width: 7, height: 7)
|
||||
|
||||
Text(machine.status.capitalized)
|
||||
|
||||
if vm.isIntegrated(machine) {
|
||||
Text("· Integrated")
|
||||
.foregroundStyle(.green)
|
||||
}
|
||||
}
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
.padding(.leading, 22)
|
||||
.padding(.vertical, 6)
|
||||
}
|
||||
|
||||
private var integratedSection: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("INTEGRATED SERVERS")
|
||||
.font(.caption)
|
||||
.fontWeight(.semibold)
|
||||
.foregroundStyle(.secondary)
|
||||
|
||||
ForEach(vm.servers) { server in
|
||||
integratedServerRow(server)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func integratedServerRow(
|
||||
_ server: ServerDefinition
|
||||
) -> some View {
|
||||
let status = vm.status(for: server)
|
||||
let expanded = expandedServers.contains(server.id)
|
||||
|
||||
return VStack(alignment: .leading, spacing: 5) {
|
||||
Button {
|
||||
if expanded {
|
||||
expandedServers.remove(server.id)
|
||||
} else {
|
||||
expandedServers.insert(server.id)
|
||||
}
|
||||
} label: {
|
||||
HStack(spacing: 10) {
|
||||
Image(systemName:
|
||||
expanded ? "chevron.down" : "chevron.right"
|
||||
)
|
||||
.font(.caption)
|
||||
|
||||
Circle()
|
||||
.fill(status == .running
|
||||
? Color.green : Color.gray)
|
||||
.frame(width: 9, height: 9)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(server.name)
|
||||
.fontWeight(.medium)
|
||||
|
||||
Text(status.title)
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.padding(.vertical, 8)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
|
||||
if expanded {
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
if status == .stopped {
|
||||
action("Start", "play.fill") {
|
||||
vm.start(server)
|
||||
}
|
||||
} else {
|
||||
action("Stop", "stop.fill") {
|
||||
vm.stop(server)
|
||||
}
|
||||
.disabled(vm.isBusy(server))
|
||||
|
||||
action("Restart", "arrow.clockwise") {
|
||||
vm.restart(server)
|
||||
}
|
||||
.disabled(
|
||||
vm.isBusy(server) ||
|
||||
status != .running
|
||||
)
|
||||
|
||||
action(
|
||||
"Force Stop",
|
||||
"exclamationmark.triangle"
|
||||
) {
|
||||
vm.forceStop(server)
|
||||
}
|
||||
.disabled(vm.isBusy(server))
|
||||
}
|
||||
|
||||
action("Open SSH in Terminal", "terminal") {
|
||||
vm.openSSH(server)
|
||||
}
|
||||
.disabled(
|
||||
status != .running ||
|
||||
server.host.isEmpty
|
||||
)
|
||||
|
||||
action("Open Mailpit", "envelope") {
|
||||
vm.openMailpit(server)
|
||||
}
|
||||
.disabled(
|
||||
status != .running ||
|
||||
server.mailpitPort == nil ||
|
||||
server.host.isEmpty
|
||||
)
|
||||
}
|
||||
.padding(.leading, 26)
|
||||
.padding(.bottom, 8)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func action(
|
||||
_ title: String,
|
||||
_ symbol: String,
|
||||
perform: @escaping () -> Void
|
||||
) -> some View {
|
||||
Button(action: perform) {
|
||||
Label(title, systemImage: symbol)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(.vertical, 5)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
private var footer: some View {
|
||||
VStack(spacing: 2) {
|
||||
action("Open Parallels Desktop", "macwindow") {
|
||||
vm.openParallels()
|
||||
}
|
||||
|
||||
action("Settings…", "gearshape") {
|
||||
openSettings()
|
||||
NSApplication.shared.activate(
|
||||
ignoringOtherApps: true
|
||||
)
|
||||
}
|
||||
|
||||
Divider()
|
||||
|
||||
action("Quit OrionToolbar", "xmark") {
|
||||
NSApplication.shared.terminate(nil)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.vertical, 10)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,298 @@
|
||||
import AppKit
|
||||
import Foundation
|
||||
|
||||
struct ServerDefinition: Identifiable, Codable, Hashable {
|
||||
var id = UUID()
|
||||
var name: String
|
||||
var vmName: String
|
||||
var vmUUID: String? = nil
|
||||
var host: String
|
||||
var sshUser: String
|
||||
var sshPort: Int = 22
|
||||
var sshIdentityFile: String = ""
|
||||
var mailpitPort: Int?
|
||||
|
||||
static let orion = ServerDefinition(name: "Orion", vmName: "Ubuntu Linux Server", host: "10.211.55.100", sshUser: "sysadmin", sshPort: 22, sshIdentityFile: "", mailpitPort: 8025)
|
||||
}
|
||||
|
||||
|
||||
struct ParallelsVM: Identifiable, Hashable {
|
||||
let id: String
|
||||
let name: String
|
||||
let status: String
|
||||
let ipAddress: String
|
||||
let operatingSystem: String
|
||||
var bundlePath: String?
|
||||
|
||||
var symbol: String {
|
||||
switch operatingSystem {
|
||||
case "Windows": return "desktopcomputer"
|
||||
case "Ubuntu": return "server.rack"
|
||||
case "Debian": return "server.rack"
|
||||
case "Fedora": return "server.rack"
|
||||
case "CentOS": return "server.rack"
|
||||
case "Alpine": return "server.rack"
|
||||
case "Oracle Linux": return "server.rack"
|
||||
default: return "desktopcomputer"
|
||||
}
|
||||
}
|
||||
|
||||
static func detectOS(_ name: String) -> String {
|
||||
let value = name.lowercased()
|
||||
|
||||
if value.contains("windows") { return "Windows" }
|
||||
if value.contains("ubuntu") { return "Ubuntu" }
|
||||
if value.contains("debian") { return "Debian" }
|
||||
if value.contains("fedora") { return "Fedora" }
|
||||
if value.contains("centos") { return "CentOS" }
|
||||
if value.contains("alpine") { return "Alpine" }
|
||||
if value.contains("oracle") { return "Oracle Linux" }
|
||||
if value.contains("rocky") { return "Rocky Linux" }
|
||||
if value.contains("alma") { return "AlmaLinux" }
|
||||
if value.contains("arch") { return "Arch Linux" }
|
||||
if value.contains("gentoo") { return "Gentoo" }
|
||||
if value.contains("freebsd") { return "FreeBSD" }
|
||||
|
||||
return "Other"
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
final class OrionVMController: ObservableObject {
|
||||
enum VMStatus: Equatable {
|
||||
case checking, running, stopped, suspended, transitioning, unavailable(String)
|
||||
var title: String { switch self { case .checking: "Checking…"; case .running: "Running"; case .stopped: "Stopped"; case .suspended: "Suspended"; case .transitioning: "Working…"; case .unavailable: "Unavailable" } }
|
||||
var symbolName: String { switch self { case .running: "server.rack"; case .stopped: "power"; case .suspended: "pause.circle"; case .transitioning, .checking: "arrow.triangle.2.circlepath"; case .unavailable: "exclamationmark.triangle" } }
|
||||
}
|
||||
|
||||
@Published var servers: [ServerDefinition] { didSet { saveServers() } }
|
||||
@Published var statuses: [UUID: VMStatus] = [:]
|
||||
@Published var busyServers: Set<UUID> = []
|
||||
@Published var lastError: String?
|
||||
@Published var discoveredVMs: [ParallelsVM] = []
|
||||
@Published var selectedVMIDs: Set<String> = []
|
||||
@Published var discovering = false
|
||||
private var timer: Timer?
|
||||
private let defaultsKey = "serverDefinitions.v2"
|
||||
|
||||
init() {
|
||||
if let data = UserDefaults.standard.data(forKey: defaultsKey), let saved = try? JSONDecoder().decode([ServerDefinition].self, from: data), !saved.isEmpty { servers = saved }
|
||||
else { servers = [.orion] }
|
||||
Task {
|
||||
await discoverVMs()
|
||||
await refreshAll()
|
||||
}
|
||||
timer = Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { [weak self] _ in Task { @MainActor in await self?.refreshAll() } }
|
||||
}
|
||||
deinit { timer?.invalidate() }
|
||||
|
||||
|
||||
func discoverVMs() async {
|
||||
guard !discovering else { return }
|
||||
|
||||
discovering = true
|
||||
defer { discovering = false }
|
||||
|
||||
do {
|
||||
let output = try await runPrlctl(["list", "-a", "-j"])
|
||||
|
||||
guard let data = output.data(using: .utf8),
|
||||
let records = try JSONSerialization.jsonObject(
|
||||
with: data
|
||||
) as? [[String: Any]] else {
|
||||
throw OrionError.commandFailed(
|
||||
"Invalid Parallels VM discovery response."
|
||||
)
|
||||
}
|
||||
|
||||
discoveredVMs = records.compactMap { record in
|
||||
guard let uuid = record["uuid"] as? String,
|
||||
let name = record["name"] as? String else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let status = record["status"] as? String ?? "unknown"
|
||||
let ip = record["ip_configured"] as? String ?? ""
|
||||
|
||||
return ParallelsVM(
|
||||
id: uuid,
|
||||
name: name,
|
||||
status: status,
|
||||
ipAddress: ip == "-" ? "" : ip,
|
||||
operatingSystem: ParallelsVM.detectOS(name),
|
||||
bundlePath: nil
|
||||
)
|
||||
}
|
||||
.sorted {
|
||||
$0.name.localizedStandardCompare($1.name)
|
||||
== .orderedAscending
|
||||
}
|
||||
|
||||
// Keep selections only for VMs still present.
|
||||
let available = Set(discoveredVMs.map(\.id))
|
||||
selectedVMIDs.formIntersection(available)
|
||||
|
||||
// Associate existing configurations with discovered VMs.
|
||||
// This preserves the original Orion configuration.
|
||||
for machine in discoveredVMs {
|
||||
guard let index = servers.firstIndex(where: {
|
||||
$0.vmUUID == machine.id ||
|
||||
($0.vmUUID == nil && $0.vmName == machine.name)
|
||||
}) else {
|
||||
continue
|
||||
}
|
||||
|
||||
if servers[index].vmUUID == nil {
|
||||
servers[index].vmUUID = machine.id
|
||||
}
|
||||
}
|
||||
|
||||
} catch {
|
||||
lastError = error.localizedDescription
|
||||
}
|
||||
}
|
||||
|
||||
func isIntegrated(_ machine: ParallelsVM) -> Bool {
|
||||
servers.contains {
|
||||
$0.vmUUID == machine.id ||
|
||||
($0.vmUUID == nil && $0.vmName == machine.name)
|
||||
}
|
||||
}
|
||||
|
||||
func toggleSelection(_ machine: ParallelsVM) {
|
||||
if selectedVMIDs.contains(machine.id) {
|
||||
selectedVMIDs.remove(machine.id)
|
||||
} else {
|
||||
selectedVMIDs.insert(machine.id)
|
||||
}
|
||||
}
|
||||
|
||||
func selectAllVMs() {
|
||||
selectedVMIDs = Set(discoveredVMs.map(\.id))
|
||||
}
|
||||
|
||||
func clearVMSelection() {
|
||||
selectedVMIDs.removeAll()
|
||||
}
|
||||
|
||||
func integrateSelectedVMs() {
|
||||
let selected = discoveredVMs.filter {
|
||||
selectedVMIDs.contains($0.id)
|
||||
}
|
||||
|
||||
for machine in selected {
|
||||
guard !isIntegrated(machine) else { continue }
|
||||
|
||||
let server = ServerDefinition(
|
||||
name: machine.name,
|
||||
vmName: machine.name,
|
||||
vmUUID: machine.id,
|
||||
host: machine.ipAddress,
|
||||
sshUser: "sysadmin",
|
||||
sshPort: 22,
|
||||
sshIdentityFile: "",
|
||||
mailpitPort: nil
|
||||
)
|
||||
|
||||
add(server)
|
||||
}
|
||||
|
||||
selectedVMIDs.removeAll()
|
||||
}
|
||||
|
||||
func icon(for machine: ParallelsVM) -> NSImage? {
|
||||
guard let path = machine.bundlePath,
|
||||
FileManager.default.fileExists(atPath: path) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return NSWorkspace.shared.icon(forFile: path)
|
||||
}
|
||||
|
||||
func status(for server: ServerDefinition) -> VMStatus { statuses[server.id] ?? .checking }
|
||||
func isBusy(_ server: ServerDefinition) -> Bool { busyServers.contains(server.id) }
|
||||
func add(_ server: ServerDefinition) { servers.append(server); Task { await refreshStatus(server) } }
|
||||
func update(_ server: ServerDefinition) { if let i = servers.firstIndex(where: { $0.id == server.id }) { servers[i] = server; Task { await refreshStatus(server) } } }
|
||||
func delete(at offsets: IndexSet) { for i in offsets { statuses[servers[i].id] = nil }; servers.remove(atOffsets: offsets) }
|
||||
|
||||
func refreshAll() async { for server in servers { await refreshStatus(server) } }
|
||||
func refreshStatus(_ server: ServerDefinition) async {
|
||||
guard !isBusy(server) else { return }
|
||||
do {
|
||||
let output = try await runPrlctl(["status", server.vmName]); let value = output.lowercased()
|
||||
if value.contains("running") { statuses[server.id] = .running }
|
||||
else if value.contains("stopped") { statuses[server.id] = .stopped }
|
||||
else if value.contains("suspended") || value.contains("paused") { statuses[server.id] = .suspended }
|
||||
else { statuses[server.id] = .unavailable(output.trimmingCharacters(in: .whitespacesAndNewlines)) }
|
||||
} catch { statuses[server.id] = .unavailable(error.localizedDescription) }
|
||||
}
|
||||
|
||||
func start(_ s: ServerDefinition) { perform(["start", s.vmName], server: s) }
|
||||
func stop(_ s: ServerDefinition) { perform(["stop", s.vmName], server: s) }
|
||||
func restart(_ s: ServerDefinition) { perform(["restart", s.vmName], server: s) }
|
||||
func forceStop(_ s: ServerDefinition) { perform(["stop", s.vmName, "--kill"], server: s) }
|
||||
|
||||
private func perform(_ arguments: [String], server: ServerDefinition) {
|
||||
guard !isBusy(server) else { return }; busyServers.insert(server.id); statuses[server.id] = .transitioning; lastError = nil
|
||||
Task { do { _ = try await runPrlctl(arguments) } catch { lastError = error.localizedDescription }; busyServers.remove(server.id); try? await Task.sleep(for: .seconds(1)); await refreshStatus(server) }
|
||||
}
|
||||
|
||||
func openSSH(_ s: ServerDefinition) {
|
||||
let userHost = "\(s.sshUser)@\(s.host)"
|
||||
var command = "/usr/bin/ssh -p \(s.sshPort)"
|
||||
let identity = s.sshIdentityFile.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
if !identity.isEmpty {
|
||||
command += " -i \(shellQuote((identity as NSString).expandingTildeInPath))"
|
||||
}
|
||||
command += " \(shellQuote(userHost))"
|
||||
|
||||
do {
|
||||
// Terminal reliably opens executable .command files without requiring
|
||||
// Apple Events/Automation permission from this menu-bar application.
|
||||
let directory = FileManager.default.temporaryDirectory
|
||||
.appendingPathComponent("OrionToolbar", isDirectory: true)
|
||||
try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true)
|
||||
|
||||
let safeName = s.name.replacingOccurrences(of: "/", with: "-")
|
||||
let scriptURL = directory.appendingPathComponent("SSH-\(safeName).command")
|
||||
let script = """
|
||||
#!/bin/zsh
|
||||
clear
|
||||
echo "Connecting to \(s.name) (\(userHost))..."
|
||||
exec \(command)
|
||||
"""
|
||||
try script.write(to: scriptURL, atomically: true, encoding: .utf8)
|
||||
try FileManager.default.setAttributes([.posixPermissions: 0o700], ofItemAtPath: scriptURL.path)
|
||||
|
||||
guard let terminalURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.apple.Terminal") else {
|
||||
lastError = "Terminal.app could not be found."
|
||||
return
|
||||
}
|
||||
|
||||
let configuration = NSWorkspace.OpenConfiguration()
|
||||
configuration.activates = true
|
||||
NSWorkspace.shared.open([scriptURL], withApplicationAt: terminalURL, configuration: configuration) { _, error in
|
||||
Task { @MainActor in
|
||||
if let error { self.lastError = "Could not open Terminal: \(error.localizedDescription)" }
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
lastError = "Could not create SSH launcher: \(error.localizedDescription)"
|
||||
}
|
||||
}
|
||||
|
||||
private func shellQuote(_ value: String) -> String {
|
||||
"'" + value.replacingOccurrences(of: "'", with: "'\"'\"'") + "'"
|
||||
}
|
||||
func openMailpit(_ s: ServerDefinition) { if let p = s.mailpitPort, let url = URL(string: "http://\(s.host):\(p)") { NSWorkspace.shared.open(url) } }
|
||||
func openParallels() { NSWorkspace.shared.openApplication(at: URL(fileURLWithPath: "/Applications/Parallels Desktop.app"), configuration: .init()) }
|
||||
|
||||
private func saveServers() { if let data = try? JSONEncoder().encode(servers) { UserDefaults.standard.set(data, forKey: defaultsKey) } }
|
||||
private func prlctlURL() -> URL? { ["/usr/local/bin/prlctl", "/Applications/Parallels Desktop.app/Contents/MacOS/prlctl"].map(URL.init(fileURLWithPath:)).first { FileManager.default.isExecutableFile(atPath: $0.path) } }
|
||||
private func runPrlctl(_ arguments: [String]) async throws -> String {
|
||||
guard let executable = prlctlURL() else { throw OrionError.prlctlNotFound }
|
||||
return try await Task.detached(priority: .userInitiated) { let p = Process(); let pipe = Pipe(); p.executableURL = executable; p.arguments = arguments; p.standardOutput = pipe; p.standardError = pipe; try p.run(); p.waitUntilExit(); let out = String(decoding: pipe.fileHandleForReading.readDataToEndOfFile(), as: UTF8.self); guard p.terminationStatus == 0 else { throw OrionError.commandFailed(out) }; return out }.value
|
||||
}
|
||||
}
|
||||
|
||||
enum OrionError: LocalizedError { case prlctlNotFound, commandFailed(String); var errorDescription: String? { switch self { case .prlctlNotFound: "Parallels prlctl was not found."; case .commandFailed(let o): o.trimmingCharacters(in: .whitespacesAndNewlines) } } }
|
||||
@@ -0,0 +1,47 @@
|
||||
import SwiftUI
|
||||
|
||||
struct SettingsView: View {
|
||||
@EnvironmentObject var vm: OrionVMController
|
||||
@State private var selection: UUID?
|
||||
@State private var editing: ServerDefinition?
|
||||
var body: some View {
|
||||
HStack(spacing: 0) {
|
||||
List(selection: $selection) { ForEach(vm.servers) { s in Label(s.name, systemImage: vm.status(for: s).symbolName).tag(s.id) } }
|
||||
.frame(width: 190)
|
||||
Divider()
|
||||
VStack(alignment: .leading, spacing: 14) {
|
||||
if let id = selection, let server = vm.servers.first(where: { $0.id == id }) {
|
||||
Text(server.name).font(.title2).fontWeight(.semibold)
|
||||
LabeledContent("Parallels VM", value: server.vmName); LabeledContent("Host", value: server.host); LabeledContent("SSH user", value: server.sshUser); LabeledContent("SSH port", value: String(server.sshPort)); LabeledContent("SSH key", value: server.sshIdentityFile.isEmpty ? "Default SSH configuration" : server.sshIdentityFile); LabeledContent("Mailpit", value: server.mailpitPort.map(String.init) ?? "Disabled")
|
||||
HStack { Button("Edit…") { editing = server }; Button("Force Stop", role: .destructive) { vm.forceStop(server) }.disabled(vm.status(for: server) == .stopped) }
|
||||
Spacer()
|
||||
} else { ContentUnavailableView("Select a Server", systemImage: "server.rack") }
|
||||
Divider()
|
||||
HStack { Button("Add Server…", systemImage: "plus") { editing = ServerDefinition(name: "New Server", vmName: "", host: "", sshUser: "sysadmin", sshPort: 22, sshIdentityFile: "", mailpitPort: nil) }; Spacer(); Button("Delete", role: .destructive) { if let id = selection, let i = vm.servers.firstIndex(where: {$0.id == id}) { vm.delete(at: IndexSet(integer: i)); selection = nil } }.disabled(selection == nil) }
|
||||
}.padding(20)
|
||||
}.frame(width: 650, height: 380)
|
||||
.sheet(item: $editing) { server in ServerEditor(server: server, isNew: !vm.servers.contains(where: {$0.id == server.id})) { value, isNew in if isNew { vm.add(value) } else { vm.update(value) }; selection = value.id } }
|
||||
}
|
||||
}
|
||||
|
||||
struct ServerEditor: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@State var server: ServerDefinition
|
||||
let isNew: Bool
|
||||
let save: (ServerDefinition, Bool) -> Void
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 14) {
|
||||
Text(isNew ? "Add Server" : "Edit Server").font(.title2).fontWeight(.semibold)
|
||||
Form {
|
||||
TextField("Display name", text: $server.name)
|
||||
TextField("Parallels VM name", text: $server.vmName)
|
||||
TextField("IP address / host", text: $server.host)
|
||||
TextField("SSH user", text: $server.sshUser)
|
||||
TextField("SSH port", value: $server.sshPort, format: .number)
|
||||
TextField("SSH identity file (optional)", text: $server.sshIdentityFile, prompt: Text("~/.ssh/id_ed25519"))
|
||||
TextField("Mailpit port (optional)", text: Binding(get: { server.mailpitPort.map(String.init) ?? "" }, set: { server.mailpitPort = Int($0) }))
|
||||
}
|
||||
HStack { Spacer(); Button("Cancel") { dismiss() }; Button("Save") { save(server, isNew); dismiss() }.keyboardShortcut(.defaultAction).disabled(server.name.isEmpty || server.vmName.isEmpty || server.host.isEmpty || server.sshUser.isEmpty || server.sshPort < 1 || server.sshPort > 65535) }
|
||||
}.padding(20).frame(width: 470)
|
||||
}
|
||||
}
|
||||
@@ -1,276 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# ============================================================
|
||||
# Orion Toolbar - Direct Distribution Build
|
||||
# ============================================================
|
||||
|
||||
APP_NAME="OrionToolbar"
|
||||
SCHEME="OrionToolbar"
|
||||
PROJECT="OrionToolbar.xcodeproj"
|
||||
|
||||
# Change this if your Developer ID identity has a different name.
|
||||
SIGNING_IDENTITY="B99D353C88996866C49E4389B375645F76870A3F"
|
||||
|
||||
# Existing notarytool Keychain profile.
|
||||
# Change if you use a different profile name.
|
||||
NOTARY_PROFILE="orion-notary"
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
BUILD_DIR="$ROOT_DIR/build"
|
||||
ARCHIVE_PATH="$BUILD_DIR/$APP_NAME.xcarchive"
|
||||
EXPORT_DIR="$BUILD_DIR/export"
|
||||
DMG_STAGE="$BUILD_DIR/dmg"
|
||||
DMG_PATH="$ROOT_DIR/$APP_NAME.dmg"
|
||||
EXPORT_OPTIONS="$BUILD_DIR/ExportOptions.plist"
|
||||
|
||||
echo
|
||||
echo "============================================================"
|
||||
echo " ORION TOOLBAR - DIRECT DISTRIBUTION"
|
||||
echo "============================================================"
|
||||
echo
|
||||
|
||||
cd "$ROOT_DIR"
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Clean
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo "==> Cleaning previous build..."
|
||||
|
||||
rm -rf "$BUILD_DIR"
|
||||
rm -f "$DMG_PATH"
|
||||
|
||||
mkdir -p "$BUILD_DIR"
|
||||
mkdir -p "$EXPORT_DIR"
|
||||
mkdir -p "$DMG_STAGE"
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Export options
|
||||
# ------------------------------------------------------------
|
||||
|
||||
cat > "$EXPORT_OPTIONS" <<EOF
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
|
||||
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>method</key>
|
||||
<string>developer-id</string>
|
||||
|
||||
<key>signingStyle</key>
|
||||
<string>automatic</string>
|
||||
|
||||
<key>teamID</key>
|
||||
<string>39R6U3437D</string>
|
||||
</dict>
|
||||
</plist>
|
||||
EOF
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Archive
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo
|
||||
echo "==> Creating Release archive..."
|
||||
|
||||
xcodebuild \
|
||||
-project "$PROJECT" \
|
||||
-scheme "$SCHEME" \
|
||||
-configuration Release \
|
||||
-destination "generic/platform=macOS" \
|
||||
-archivePath "$ARCHIVE_PATH" \
|
||||
clean archive
|
||||
|
||||
echo
|
||||
echo "==> Archive created."
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Export Developer ID application
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo
|
||||
echo "==> Exporting Developer ID application..."
|
||||
|
||||
xcodebuild \
|
||||
-exportArchive \
|
||||
-archivePath "$ARCHIVE_PATH" \
|
||||
-exportPath "$EXPORT_DIR" \
|
||||
-exportOptionsPlist "$EXPORT_OPTIONS"
|
||||
|
||||
APP_PATH="$EXPORT_DIR/$APP_NAME.app"
|
||||
|
||||
if [ ! -d "$APP_PATH" ]; then
|
||||
echo
|
||||
echo "ERROR: Exported application not found:"
|
||||
echo "$APP_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Verify application signature
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo
|
||||
echo "==> Verifying application signature..."
|
||||
|
||||
codesign \
|
||||
--verify \
|
||||
--deep \
|
||||
--strict \
|
||||
--verbose=2 \
|
||||
"$APP_PATH"
|
||||
|
||||
echo
|
||||
echo "==> Signature information..."
|
||||
|
||||
codesign -dv --verbose=4 "$APP_PATH" 2>&1 | \
|
||||
grep -E "Identifier=|Authority=|TeamIdentifier=|Runtime Version=" || true
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Notarize application
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo
|
||||
echo "==> Creating notarization ZIP..."
|
||||
|
||||
APP_ZIP="$BUILD_DIR/$APP_NAME.zip"
|
||||
|
||||
ditto \
|
||||
-c \
|
||||
-k \
|
||||
--keepParent \
|
||||
"$APP_PATH" \
|
||||
"$APP_ZIP"
|
||||
|
||||
echo
|
||||
echo "==> Submitting application to Apple notarization..."
|
||||
|
||||
xcrun notarytool submit \
|
||||
"$APP_ZIP" \
|
||||
--keychain-profile "$NOTARY_PROFILE" \
|
||||
--wait
|
||||
|
||||
echo
|
||||
echo "==> Stapling notarization ticket to application..."
|
||||
|
||||
xcrun stapler staple "$APP_PATH"
|
||||
|
||||
echo
|
||||
echo "==> Validating application ticket..."
|
||||
|
||||
xcrun stapler validate "$APP_PATH"
|
||||
|
||||
echo
|
||||
echo "==> Gatekeeper application check..."
|
||||
|
||||
spctl \
|
||||
--assess \
|
||||
--type execute \
|
||||
--verbose=4 \
|
||||
"$APP_PATH"
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Build DMG contents
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo
|
||||
echo "==> Preparing DMG..."
|
||||
|
||||
rm -rf "$DMG_STAGE"
|
||||
mkdir -p "$DMG_STAGE"
|
||||
|
||||
ditto "$APP_PATH" "$DMG_STAGE/$APP_NAME.app"
|
||||
|
||||
ln -s /Applications "$DMG_STAGE/Applications"
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Create DMG
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo
|
||||
echo "==> Creating DMG..."
|
||||
|
||||
hdiutil create \
|
||||
-volname "$APP_NAME" \
|
||||
-srcfolder "$DMG_STAGE" \
|
||||
-ov \
|
||||
-format UDZO \
|
||||
"$DMG_PATH"
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Sign DMG
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo
|
||||
echo "==> Signing DMG..."
|
||||
|
||||
codesign \
|
||||
--force \
|
||||
--timestamp \
|
||||
--sign "$SIGNING_IDENTITY" \
|
||||
"$DMG_PATH"
|
||||
|
||||
echo
|
||||
echo "==> Verifying DMG signature..."
|
||||
|
||||
codesign \
|
||||
--verify \
|
||||
--verbose=2 \
|
||||
"$DMG_PATH"
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Notarize DMG
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo
|
||||
echo "==> Submitting DMG to Apple notarization..."
|
||||
|
||||
xcrun notarytool submit \
|
||||
"$DMG_PATH" \
|
||||
--keychain-profile "$NOTARY_PROFILE" \
|
||||
--wait
|
||||
|
||||
echo
|
||||
echo "==> Stapling notarization ticket to DMG..."
|
||||
|
||||
xcrun stapler staple "$DMG_PATH"
|
||||
|
||||
echo
|
||||
echo "==> Validating DMG ticket..."
|
||||
|
||||
xcrun stapler validate "$DMG_PATH"
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Final verification
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo
|
||||
echo "==> Final Gatekeeper assessment..."
|
||||
|
||||
spctl \
|
||||
--assess \
|
||||
--type open \
|
||||
--context context:primary-signature \
|
||||
--verbose=4 \
|
||||
"$DMG_PATH" || true
|
||||
|
||||
echo
|
||||
echo "==> DMG information..."
|
||||
|
||||
ls -lh "$DMG_PATH"
|
||||
|
||||
echo
|
||||
echo "==> SHA-256..."
|
||||
|
||||
shasum -a 256 "$DMG_PATH"
|
||||
|
||||
echo
|
||||
echo "============================================================"
|
||||
echo " RELEASE BUILD COMPLETE"
|
||||
echo "============================================================"
|
||||
echo
|
||||
echo "DMG:"
|
||||
echo "$DMG_PATH"
|
||||
echo
|
||||
@@ -1,200 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
APP_NAME="OrionToolbar"
|
||||
SCHEME="OrionToolbar"
|
||||
PROJECT="OrionToolbar.xcodeproj"
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
BUILD_DIR="$ROOT_DIR/.build"
|
||||
LOG_DIR="$ROOT_DIR/build-logs"
|
||||
|
||||
CONFIGURATION="Release"
|
||||
LAUNCH=false
|
||||
RUN_TESTS=true
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--launch)
|
||||
LAUNCH=true
|
||||
;;
|
||||
--no-tests)
|
||||
RUN_TESTS=false
|
||||
;;
|
||||
*)
|
||||
echo "Unknown argument: $arg"
|
||||
echo "Usage: $0 [--launch] [--no-tests]"
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
mkdir -p "$BUILD_DIR" "$LOG_DIR"
|
||||
|
||||
LOG_FILE="$LOG_DIR/build-test-$(date +%Y%m%d-%H%M%S).log"
|
||||
|
||||
exec > >(tee -a "$LOG_FILE") 2>&1
|
||||
|
||||
echo
|
||||
echo "============================================================"
|
||||
echo " ORION TOOLBAR - RELEASE BUILD AND TEST"
|
||||
echo "============================================================"
|
||||
echo
|
||||
|
||||
cd "$ROOT_DIR"
|
||||
|
||||
echo "==> Environment"
|
||||
|
||||
xcodebuild -version
|
||||
swift --version
|
||||
|
||||
echo
|
||||
echo "==> Checking project"
|
||||
|
||||
test -d "$PROJECT" || {
|
||||
echo "ERROR: Xcode project not found."
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo
|
||||
echo "==> Checking Parallels"
|
||||
|
||||
PRLCTL=""
|
||||
|
||||
for candidate in \
|
||||
/usr/local/bin/prlctl \
|
||||
"/Applications/Parallels Desktop.app/Contents/MacOS/prlctl"
|
||||
do
|
||||
if [ -x "$candidate" ]; then
|
||||
PRLCTL="$candidate"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -n "$PRLCTL" ]; then
|
||||
echo "Parallels CLI: $PRLCTL"
|
||||
|
||||
echo
|
||||
echo "==> Discovering virtual machines"
|
||||
|
||||
"$PRLCTL" list -a -j | python3 -c '
|
||||
import json
|
||||
import sys
|
||||
|
||||
machines = json.load(sys.stdin)
|
||||
|
||||
print(f"Discovered {len(machines)} virtual machines")
|
||||
print()
|
||||
|
||||
for machine in machines:
|
||||
print(
|
||||
f"{machine.get('name', 'Unknown'):<35} "
|
||||
f"{machine.get('status', 'unknown'):<12} "
|
||||
f"{machine.get('uuid', '')}"
|
||||
)
|
||||
'
|
||||
else
|
||||
echo "WARNING: Parallels CLI not found."
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "==> Building Release configuration"
|
||||
|
||||
xcodebuild \
|
||||
-project "$PROJECT" \
|
||||
-scheme "$SCHEME" \
|
||||
-configuration "$CONFIGURATION" \
|
||||
-destination "generic/platform=macOS" \
|
||||
-derivedDataPath "$BUILD_DIR" \
|
||||
CODE_SIGNING_ALLOWED=NO \
|
||||
clean build
|
||||
|
||||
APP_PATH="$BUILD_DIR/Build/Products/$CONFIGURATION/$APP_NAME.app"
|
||||
|
||||
if [ ! -d "$APP_PATH" ]; then
|
||||
echo "ERROR: Built application not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "==> Validating application bundle"
|
||||
|
||||
plutil -lint "$APP_PATH/Contents/Info.plist"
|
||||
|
||||
echo
|
||||
echo "==> Application information"
|
||||
|
||||
defaults read "$APP_PATH/Contents/Info" \
|
||||
CFBundleIdentifier || true
|
||||
|
||||
defaults read "$APP_PATH/Contents/Info" \
|
||||
CFBundleShortVersionString || true
|
||||
|
||||
defaults read "$APP_PATH/Contents/Info" \
|
||||
CFBundleVersion || true
|
||||
|
||||
echo
|
||||
echo "==> Checking executable"
|
||||
|
||||
EXECUTABLE=$(
|
||||
/usr/libexec/PlistBuddy \
|
||||
-c "Print CFBundleExecutable" \
|
||||
"$APP_PATH/Contents/Info.plist"
|
||||
)
|
||||
|
||||
test -x "$APP_PATH/Contents/MacOS/$EXECUTABLE"
|
||||
|
||||
file "$APP_PATH/Contents/MacOS/$EXECUTABLE"
|
||||
|
||||
echo
|
||||
echo "==> Checking available test targets"
|
||||
|
||||
if [ "$RUN_TESTS" = true ]; then
|
||||
|
||||
TEST_OUTPUT="$LOG_DIR/test-targets.txt"
|
||||
|
||||
xcodebuild \
|
||||
-list \
|
||||
-project "$PROJECT" > "$TEST_OUTPUT"
|
||||
|
||||
if grep -Eq '^[[:space:]]+.*Tests$' "$TEST_OUTPUT"; then
|
||||
|
||||
echo "Test targets detected."
|
||||
|
||||
xcodebuild \
|
||||
-project "$PROJECT" \
|
||||
-scheme "$SCHEME" \
|
||||
-configuration "$CONFIGURATION" \
|
||||
-destination "platform=macOS" \
|
||||
-derivedDataPath "$BUILD_DIR" \
|
||||
CODE_SIGNING_ALLOWED=NO \
|
||||
test
|
||||
|
||||
else
|
||||
echo "No test targets detected; skipping XCTest."
|
||||
fi
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "==> Build size"
|
||||
|
||||
du -sh "$APP_PATH"
|
||||
|
||||
if [ "$LAUNCH" = true ]; then
|
||||
echo
|
||||
echo "==> Launching OrionToolbar"
|
||||
|
||||
open "$APP_PATH"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "============================================================"
|
||||
echo " BUILD AND TEST COMPLETE"
|
||||
echo "============================================================"
|
||||
echo
|
||||
echo "Application:"
|
||||
echo "$APP_PATH"
|
||||
echo
|
||||
echo "Log:"
|
||||
echo "$LOG_FILE"
|
||||
echo
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/bin/zsh
|
||||
set -euo pipefail
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
APP_NAME=OrionToolbar
|
||||
DERIVED="$ROOT/.build"
|
||||
CONFIGURATION="${CONFIGURATION:-Debug}"
|
||||
[[ "$CONFIGURATION" == Debug || "$CONFIGURATION" == Release ]] || { echo 'CONFIGURATION must be Debug or Release' >&2; exit 2; }
|
||||
mkdir -p "$ROOT/build-logs"
|
||||
LOG="$ROOT/build-logs/build-${CONFIGURATION}-$(date +%Y%m%d-%H%M%S).log"
|
||||
echo "Building $APP_NAME ($CONFIGURATION)"
|
||||
set -o pipefail
|
||||
xcodebuild -project "$ROOT/OrionToolbar.xcodeproj" -scheme "$APP_NAME" -configuration "$CONFIGURATION" -derivedDataPath "$DERIVED" CODE_SIGNING_ALLOWED=NO build 2>&1 | tee "$LOG"
|
||||
APP="$DERIVED/Build/Products/$CONFIGURATION/$APP_NAME.app"
|
||||
[[ -d "$APP" ]] || { echo "Missing application: $APP" >&2; exit 1; }
|
||||
plutil -lint "$APP/Contents/Info.plist"
|
||||
EXE=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleExecutable' "$APP/Contents/Info.plist")
|
||||
[[ -x "$APP/Contents/MacOS/$EXE" ]] || { echo 'Application executable missing' >&2; exit 1; }
|
||||
echo "Build complete: $APP"
|
||||
echo "Log: $LOG"
|
||||
if [[ "${1:-}" == '--launch' ]]; then
|
||||
pkill -x "$APP_NAME" 2>/dev/null || true
|
||||
open "$APP"
|
||||
fi
|
||||
+65
-316
@@ -1,318 +1,67 @@
|
||||
#!/bin/bash
|
||||
#!/bin/zsh
|
||||
set -euo pipefail
|
||||
|
||||
# ============================================================
|
||||
# OrionToolbar - Developer ID Release
|
||||
# ============================================================
|
||||
|
||||
APP_NAME="OrionToolbar"
|
||||
SCHEME="OrionToolbar"
|
||||
PROJECT="OrionToolbar.xcodeproj"
|
||||
|
||||
SIGNING_IDENTITY="B99D353C88996866C49E4389B375645F76870A3F"
|
||||
TEAM_ID="39R6U3437D"
|
||||
NOTARY_PROFILE="orion-notary"
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
|
||||
BUILD_DIR="$ROOT_DIR/build"
|
||||
LOG_DIR="$ROOT_DIR/build-logs"
|
||||
|
||||
ARCHIVE_PATH="$BUILD_DIR/$APP_NAME.xcarchive"
|
||||
EXPORT_DIR="$BUILD_DIR/export"
|
||||
DMG_STAGE="$BUILD_DIR/dmg"
|
||||
|
||||
DMG_PATH="$ROOT_DIR/$APP_NAME.dmg"
|
||||
EXPORT_OPTIONS="$BUILD_DIR/ExportOptions.plist"
|
||||
|
||||
mkdir -p "$LOG_DIR"
|
||||
|
||||
LOG_FILE="$LOG_DIR/release-$(date +%Y%m%d-%H%M%S).log"
|
||||
|
||||
exec > >(tee -a "$LOG_FILE") 2>&1
|
||||
|
||||
echo
|
||||
echo "============================================================"
|
||||
echo " ORION TOOLBAR - DIRECT DISTRIBUTION"
|
||||
echo "============================================================"
|
||||
echo
|
||||
|
||||
cd "$ROOT_DIR"
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Prerequisites
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo "==> Checking signing identity"
|
||||
|
||||
security find-identity -v -p codesigning
|
||||
|
||||
if ! security find-identity -v -p codesigning | \
|
||||
grep -q "$SIGNING_IDENTITY"; then
|
||||
|
||||
echo "ERROR: Developer ID signing identity unavailable."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "==> Checking notarization profile"
|
||||
|
||||
xcrun notarytool history \
|
||||
--keychain-profile "$NOTARY_PROFILE" \
|
||||
>/dev/null
|
||||
|
||||
echo "Notarization profile available."
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Clean
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo
|
||||
echo "==> Cleaning previous release"
|
||||
|
||||
rm -rf "$BUILD_DIR"
|
||||
rm -f "$DMG_PATH"
|
||||
|
||||
mkdir -p \
|
||||
"$BUILD_DIR" \
|
||||
"$EXPORT_DIR" \
|
||||
"$DMG_STAGE"
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Export options
|
||||
# ------------------------------------------------------------
|
||||
|
||||
cat > "$EXPORT_OPTIONS" <<EOF
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
APP_NAME=OrionToolbar
|
||||
PROJECT="$ROOT/OrionToolbar.xcodeproj"
|
||||
DERIVED="$ROOT/.build"
|
||||
WORK="$ROOT/.build/release"
|
||||
DIST="$ROOT/dist"
|
||||
SIGNING_IDENTITY="${SIGNING_IDENTITY:-B99D353C88996866C49E4389B375645F76870A3F}"
|
||||
TEAM_ID="${TEAM_ID:-39R6U3437D}"
|
||||
NOTARY_PROFILE="${NOTARY_PROFILE:-orion-notary}"
|
||||
mkdir -p "$ROOT/build-logs" "$DIST"
|
||||
LOG="$ROOT/build-logs/release-$(date +%Y%m%d-%H%M%S).log"
|
||||
exec > >(tee "$LOG") 2>&1
|
||||
command -v xcodebuild >/dev/null
|
||||
command -v hdiutil >/dev/null
|
||||
security find-identity -v -p codesigning | grep -q "$SIGNING_IDENTITY" || { echo 'Developer ID identity missing' >&2; exit 1; }
|
||||
xcrun notarytool history --keychain-profile "$NOTARY_PROFILE" >/dev/null
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK/export" "$WORK/dmg"
|
||||
cat > "$WORK/ExportOptions.plist" <<PLIST
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
|
||||
"http://www.apple.com/DTDs/PropertyList-1.0.dtd"\>
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>method</key>
|
||||
<string>developer-id</string>
|
||||
|
||||
<key>signingStyle</key>
|
||||
<string>automatic</string>
|
||||
|
||||
<key>teamID</key>
|
||||
<string>$TEAM_ID</string>
|
||||
</dict>
|
||||
</plist>
|
||||
EOF
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Archive
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo
|
||||
echo "==> Creating Release archive"
|
||||
|
||||
xcodebuild \
|
||||
-project "$PROJECT" \
|
||||
-scheme "$SCHEME" \
|
||||
-configuration Release \
|
||||
-destination "generic/platform=macOS" \
|
||||
-archivePath "$ARCHIVE_PATH" \
|
||||
clean archive
|
||||
|
||||
echo
|
||||
echo "==> Archive created"
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Export
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo
|
||||
echo "==> Exporting Developer ID application"
|
||||
|
||||
xcodebuild \
|
||||
-exportArchive \
|
||||
-archivePath "$ARCHIVE_PATH" \
|
||||
-exportPath "$EXPORT_DIR" \
|
||||
-exportOptionsPlist "$EXPORT_OPTIONS"
|
||||
|
||||
APP_PATH="$EXPORT_DIR/$APP_NAME.app"
|
||||
|
||||
if [ ! -d "$APP_PATH" ]; then
|
||||
echo "ERROR: Exported application not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Verify signature
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo
|
||||
echo "==> Verifying application signature"
|
||||
|
||||
codesign \
|
||||
--verify \
|
||||
--deep \
|
||||
--strict \
|
||||
--verbose=2 \
|
||||
"$APP_PATH"
|
||||
|
||||
echo
|
||||
echo "==> Checking signing team"
|
||||
|
||||
ACTUAL_TEAM=$(
|
||||
codesign -dv --verbose=4 "$APP_PATH" 2>&1 |
|
||||
sed -n 's/^TeamIdentifier=//p'
|
||||
)
|
||||
|
||||
if [ "$ACTUAL_TEAM" != "$TEAM_ID" ]; then
|
||||
echo "ERROR: Incorrect signing team: $ACTUAL_TEAM"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Signing team verified: $ACTUAL_TEAM"
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Notarize application
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo
|
||||
echo "==> Creating notarization ZIP"
|
||||
|
||||
APP_ZIP="$BUILD_DIR/$APP_NAME.zip"
|
||||
|
||||
ditto \
|
||||
-c \
|
||||
-k \
|
||||
--keepParent \
|
||||
"$APP_PATH" \
|
||||
"$APP_ZIP"
|
||||
|
||||
echo
|
||||
echo "==> Notarizing application"
|
||||
|
||||
xcrun notarytool submit \
|
||||
"$APP_ZIP" \
|
||||
--keychain-profile "$NOTARY_PROFILE" \
|
||||
--wait
|
||||
|
||||
echo
|
||||
echo "==> Stapling application"
|
||||
|
||||
xcrun stapler staple "$APP_PATH"
|
||||
|
||||
echo
|
||||
echo "==> Validating application ticket"
|
||||
|
||||
xcrun stapler validate "$APP_PATH"
|
||||
|
||||
echo
|
||||
echo "==> Gatekeeper application verification"
|
||||
|
||||
spctl \
|
||||
--assess \
|
||||
--type execute \
|
||||
--verbose=4 \
|
||||
"$APP_PATH"
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Prepare DMG
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo
|
||||
echo "==> Preparing DMG"
|
||||
|
||||
rm -rf "$DMG_STAGE"
|
||||
mkdir -p "$DMG_STAGE"
|
||||
|
||||
ditto "$APP_PATH" "$DMG_STAGE/$APP_NAME.app"
|
||||
|
||||
ln -s /Applications "$DMG_STAGE/Applications"
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Create DMG
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo
|
||||
echo "==> Creating DMG"
|
||||
|
||||
hdiutil create \
|
||||
-volname "$APP_NAME" \
|
||||
-srcfolder "$DMG_STAGE" \
|
||||
-ov \
|
||||
-format UDZO \
|
||||
"$DMG_PATH"
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Sign DMG
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo
|
||||
echo "==> Signing DMG"
|
||||
|
||||
codesign \
|
||||
--force \
|
||||
--timestamp \
|
||||
--sign "$SIGNING_IDENTITY" \
|
||||
"$DMG_PATH"
|
||||
|
||||
echo
|
||||
echo "==> Verifying DMG signature"
|
||||
|
||||
codesign \
|
||||
--verify \
|
||||
--verbose=2 \
|
||||
"$DMG_PATH"
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Notarize DMG
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo
|
||||
echo "==> Notarizing DMG"
|
||||
|
||||
xcrun notarytool submit \
|
||||
"$DMG_PATH" \
|
||||
--keychain-profile "$NOTARY_PROFILE" \
|
||||
--wait
|
||||
|
||||
echo
|
||||
echo "==> Stapling DMG"
|
||||
|
||||
xcrun stapler staple "$DMG_PATH"
|
||||
|
||||
echo
|
||||
echo "==> Validating DMG ticket"
|
||||
|
||||
xcrun stapler validate "$DMG_PATH"
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Final verification
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo
|
||||
echo "==> Final Gatekeeper verification"
|
||||
|
||||
spctl \
|
||||
--assess \
|
||||
--type open \
|
||||
--context context:primary-signature \
|
||||
--verbose=4 \
|
||||
"$DMG_PATH"
|
||||
|
||||
echo
|
||||
echo "==> Final DMG information"
|
||||
|
||||
ls -lh "$DMG_PATH"
|
||||
|
||||
echo
|
||||
echo "==> SHA-256"
|
||||
|
||||
shasum -a 256 "$DMG_PATH"
|
||||
|
||||
echo
|
||||
echo "============================================================"
|
||||
echo " RELEASE BUILD COMPLETE"
|
||||
echo "============================================================"
|
||||
echo
|
||||
echo "DMG:"
|
||||
echo "$DMG_PATH"
|
||||
echo
|
||||
echo "Build log:"
|
||||
echo "$LOG_FILE"
|
||||
echo
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0"><dict>
|
||||
<key>method</key><string>developer-id</string>
|
||||
<key>signingStyle</key><string>automatic</string>
|
||||
<key>teamID</key><string>$TEAM_ID</string>
|
||||
</dict></plist>
|
||||
PLIST
|
||||
xcodebuild -project "$PROJECT" -scheme "$APP_NAME" -configuration Release -destination 'generic/platform=macOS' -archivePath "$WORK/$APP_NAME.xcarchive" archive
|
||||
xcodebuild -exportArchive -archivePath "$WORK/$APP_NAME.xcarchive" -exportPath "$WORK/export" -exportOptionsPlist "$WORK/ExportOptions.plist"
|
||||
APP="$WORK/export/$APP_NAME.app"
|
||||
[[ -d "$APP" ]] || { echo 'Exported app missing' >&2; exit 1; }
|
||||
codesign --verify --deep --strict --verbose=2 "$APP"
|
||||
ACTUAL_TEAM=$(codesign -dv --verbose=4 "$APP" 2>&1 | sed -n 's/^TeamIdentifier=//p')
|
||||
[[ "$ACTUAL_TEAM" == "$TEAM_ID" ]] || { echo "Unexpected team: $ACTUAL_TEAM" >&2; exit 1; }
|
||||
VERSION=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$APP/Contents/Info.plist")
|
||||
[[ -n "$VERSION" ]] || { echo 'Missing marketing version' >&2; exit 1; }
|
||||
DMG="$DIST/$APP_NAME-$VERSION.dmg"
|
||||
ZIP="$WORK/$APP_NAME.zip"
|
||||
ditto -c -k --keepParent "$APP" "$ZIP"
|
||||
notarize() {
|
||||
local file="$1" result status
|
||||
result=$(xcrun notarytool submit "$file" --keychain-profile "$NOTARY_PROFILE" --wait --output-format json)
|
||||
echo "$result"
|
||||
status=$(printf '%s' "$result" | python3 -c 'import json,sys; print(json.load(sys.stdin).get("status", ""))')
|
||||
[[ "$status" == Accepted ]] || { echo "Notarization not accepted for $file: $status" >&2; exit 1; }
|
||||
}
|
||||
notarize "$ZIP"
|
||||
xcrun stapler staple "$APP"
|
||||
xcrun stapler validate "$APP"
|
||||
spctl --assess --type execute --verbose=4 "$APP"
|
||||
ditto "$APP" "$WORK/dmg/$APP_NAME.app"
|
||||
ln -s /Applications "$WORK/dmg/Applications"
|
||||
rm -f "$DMG"
|
||||
hdiutil create -volname "$APP_NAME" -srcfolder "$WORK/dmg" -ov -format UDZO "$DMG"
|
||||
codesign --force --timestamp --sign "$SIGNING_IDENTITY" "$DMG"
|
||||
codesign --verify --verbose=2 "$DMG"
|
||||
notarize "$DMG"
|
||||
xcrun stapler staple "$DMG"
|
||||
xcrun stapler validate "$DMG"
|
||||
spctl --assess --type open --context context:primary-signature --verbose=4 "$DMG"
|
||||
shasum -a 256 "$DMG" | tee "$DMG.sha256"
|
||||
echo "Release complete: $DMG"
|
||||
echo "Checksum: $DMG.sha256"
|
||||
echo "Log: $LOG"
|
||||
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
#!/bin/zsh
|
||||
set -euo pipefail
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
mkdir -p "$ROOT/build-logs"
|
||||
LOG="$ROOT/build-logs/test-$(date +%Y%m%d-%H%M%S).log"
|
||||
exec > >(tee "$LOG") 2>&1
|
||||
print '=== OrionToolbar tests ==='
|
||||
# A successful compile is the minimum regression check.
|
||||
"$ROOT/Scripts/build.sh"
|
||||
APP="$ROOT/.build/Build/Products/Debug/OrionToolbar.app"
|
||||
plutil -lint "$APP/Contents/Info.plist"
|
||||
# Verify that the Parallels executable and JSON discovery work independently of SwiftUI.
|
||||
PRLCTL=''
|
||||
for candidate in /usr/local/bin/prlctl '/Applications/Parallels Desktop.app/Contents/MacOS/prlctl'; do
|
||||
if [[ -x "$candidate" ]]; then PRLCTL="$candidate"; break; fi
|
||||
done
|
||||
if [[ -n "$PRLCTL" ]]; then
|
||||
"$PRLCTL" list -a -j | python3 -c '
|
||||
import json,sys
|
||||
v=json.load(sys.stdin)
|
||||
assert isinstance(v,list), "Expected Parallels JSON array"
|
||||
for item in v:
|
||||
assert isinstance(item,dict), "Invalid VM record"
|
||||
assert item.get("name"), "VM without name"
|
||||
assert item.get("uuid"), "VM without UUID"
|
||||
print("Parallels discovery OK: {} VM(s)".format(len(v)))
|
||||
'
|
||||
else
|
||||
echo 'SKIP: Parallels CLI not installed'
|
||||
fi
|
||||
if [[ -d "$ROOT/tests" ]] && find "$ROOT/tests" -name 'test_*.py' -print -quit | grep -q .; then
|
||||
python3 -m unittest discover -s "$ROOT/tests" -v
|
||||
fi
|
||||
# Run Xcode tests only if a test plan is configured for this scheme.
|
||||
if [[ "${RUN_XCODE_TESTS:-0}" == 1 ]]; then
|
||||
xcodebuild -project "$ROOT/OrionToolbar.xcodeproj" -scheme OrionToolbar -configuration Debug -destination 'platform=macOS' -derivedDataPath "$ROOT/.build" CODE_SIGNING_ALLOWED=NO test
|
||||
else
|
||||
echo 'XCTest not run (set RUN_XCODE_TESTS=1 if the scheme has a test target).'
|
||||
fi
|
||||
print "Tests complete. Log: $LOG"
|
||||
Reference in New Issue
Block a user