updates to launcer
This commit is contained in:
@@ -12,7 +12,6 @@ private enum OrionStyle {
|
|||||||
|
|
||||||
struct OrionMenuView: View {
|
struct OrionMenuView: View {
|
||||||
@EnvironmentObject private var vm: OrionVMController
|
@EnvironmentObject private var vm: OrionVMController
|
||||||
@State private var settingsPresented = false
|
|
||||||
@State private var showRunning = true
|
@State private var showRunning = true
|
||||||
@State private var showAll = true
|
@State private var showAll = true
|
||||||
@State private var showIntegrated = true
|
@State private var showIntegrated = true
|
||||||
@@ -67,24 +66,7 @@ struct OrionMenuView: View {
|
|||||||
.background(
|
.background(
|
||||||
LinearGradient(colors: [Color(red: 0.10, green: 0.15, blue: 0.23), Color(red: 0.075, green: 0.09, blue: 0.13)], startPoint: .topTrailing, endPoint: .bottomLeading)
|
LinearGradient(colors: [Color(red: 0.10, green: 0.15, blue: 0.23), Color(red: 0.075, green: 0.09, blue: 0.13)], startPoint: .topTrailing, endPoint: .bottomLeading)
|
||||||
)
|
)
|
||||||
.sheet(isPresented: $settingsPresented) {
|
|
||||||
VStack(spacing: 0) {
|
|
||||||
HStack {
|
|
||||||
Text("Settings")
|
|
||||||
.font(.headline)
|
|
||||||
Spacer()
|
|
||||||
Button("Done") { settingsPresented = false }
|
|
||||||
.keyboardShortcut(.cancelAction)
|
|
||||||
}
|
|
||||||
.padding(.horizontal, 18)
|
|
||||||
.padding(.top, 14)
|
|
||||||
.padding(.bottom, 8)
|
|
||||||
SettingsView()
|
|
||||||
.environmentObject(vm)
|
|
||||||
}
|
|
||||||
.frame(width: 650)
|
|
||||||
.interactiveDismissDisabled()
|
|
||||||
}
|
|
||||||
.preferredColorScheme(.dark)
|
.preferredColorScheme(.dark)
|
||||||
.task { await vm.discoverVMs(); await vm.refreshAll() }
|
.task { await vm.discoverVMs(); await vm.refreshAll() }
|
||||||
.alert("OrionToolbar", isPresented: Binding(get: { vm.lastError != nil }, set: { if !$0 { vm.lastError = nil } })) {
|
.alert("OrionToolbar", isPresented: Binding(get: { vm.lastError != nil }, set: { if !$0 { vm.lastError = nil } })) {
|
||||||
@@ -327,8 +309,7 @@ struct OrionMenuView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func showSettings() {
|
private func showSettings() {
|
||||||
settingsPresented = true
|
OrionSettingsWindowPresenter.present(vm: vm)
|
||||||
NSApplication.shared.activate(ignoringOtherApps: true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,3 +323,49 @@ private struct OrionActionStyle: ButtonStyle {
|
|||||||
.opacity(configuration.isPressed ? 0.8 : 1)
|
.opacity(configuration.isPressed ? 0.8 : 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// A MenuBarExtra window is transient. Sheets attached to it can disappear
|
||||||
|
// when the user interacts with controls inside Settings. Use a real window.
|
||||||
|
@MainActor
|
||||||
|
private final class OrionSettingsWindowPresenter: NSObject, NSWindowDelegate {
|
||||||
|
private static var current: OrionSettingsWindowPresenter?
|
||||||
|
private var window: NSWindow?
|
||||||
|
|
||||||
|
static func present(vm: OrionVMController) {
|
||||||
|
if let current, let window = current.window {
|
||||||
|
NSApp.activate(ignoringOtherApps: true)
|
||||||
|
window.makeKeyAndOrderFront(nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let presenter = OrionSettingsWindowPresenter()
|
||||||
|
current = presenter
|
||||||
|
presenter.open(vm: vm)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func open(vm: OrionVMController) {
|
||||||
|
let content = SettingsView()
|
||||||
|
.environmentObject(vm)
|
||||||
|
.preferredColorScheme(.dark)
|
||||||
|
let window = NSWindow(
|
||||||
|
contentRect: NSRect(x: 0, y: 0, width: 650, height: 380),
|
||||||
|
styleMask: [.titled, .closable, .miniaturizable],
|
||||||
|
backing: .buffered,
|
||||||
|
defer: false
|
||||||
|
)
|
||||||
|
window.title = "OrionToolbar Settings"
|
||||||
|
window.contentViewController = NSHostingController(rootView: content)
|
||||||
|
window.delegate = self
|
||||||
|
window.isReleasedWhenClosed = false
|
||||||
|
window.level = .floating
|
||||||
|
window.center()
|
||||||
|
self.window = window
|
||||||
|
NSApp.activate(ignoringOtherApps: true)
|
||||||
|
window.makeKeyAndOrderFront(nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func windowWillClose(_ notification: Notification) {
|
||||||
|
window = nil
|
||||||
|
Self.current = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,344 @@
|
|||||||
|
import AppKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
private enum OrionStyle {
|
||||||
|
static let panel = Color(red: 0.105, green: 0.14, blue: 0.20)
|
||||||
|
static let card = Color(red: 0.15, green: 0.19, blue: 0.25)
|
||||||
|
static let blue = Color(red: 0.08, green: 0.39, blue: 0.91)
|
||||||
|
static let green = Color(red: 0.05, green: 0.88, blue: 0.49)
|
||||||
|
static let red = Color(red: 0.91, green: 0.19, blue: 0.23)
|
||||||
|
static let muted = Color(red: 0.62, green: 0.73, blue: 0.86)
|
||||||
|
}
|
||||||
|
|
||||||
|
struct OrionMenuView: View {
|
||||||
|
@EnvironmentObject private var vm: OrionVMController
|
||||||
|
@State private var settingsPresented = false
|
||||||
|
@State private var showRunning = true
|
||||||
|
@State private var showAll = true
|
||||||
|
@State private var showIntegrated = true
|
||||||
|
@State private var pendingRemoval: ServerDefinition?
|
||||||
|
@State private var pendingForceStop: ParallelsVM?
|
||||||
|
|
||||||
|
private var running: [ParallelsVM] {
|
||||||
|
vm.discoveredVMs.filter { $0.status.lowercased() == "running" }
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack(spacing: 0) {
|
||||||
|
header
|
||||||
|
Divider().overlay(.white.opacity(0.10))
|
||||||
|
ScrollView {
|
||||||
|
VStack(alignment: .leading, spacing: 15) {
|
||||||
|
section(icon: "play.fill", title: "Running Virtual Machines", count: "\(running.count) running", accent: OrionStyle.green, expanded: $showRunning) {
|
||||||
|
if running.isEmpty {
|
||||||
|
emptyState("No running virtual machines", icon: "moon.zzz")
|
||||||
|
} else {
|
||||||
|
ForEach(running) { machine in
|
||||||
|
runningRow(machine)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
section(icon: "desktopcomputer", title: "All Virtual Machines", count: "\(vm.discoveredVMs.count) VMs", accent: .cyan, expanded: $showAll) {
|
||||||
|
if vm.discoveredVMs.isEmpty {
|
||||||
|
emptyState(vm.discovering ? "Discovering Parallels VMs…" : "No virtual machines found", icon: "desktopcomputer.trianglebadge.exclamationmark")
|
||||||
|
} else {
|
||||||
|
ForEach(vm.discoveredVMs) { machine in
|
||||||
|
machineRow(machine)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
section(icon: "server.rack", title: "Integrated Servers", count: "\(vm.servers.count) servers", accent: OrionStyle.blue, expanded: $showIntegrated) {
|
||||||
|
if vm.servers.isEmpty {
|
||||||
|
emptyState("No integrations. Add a VM using + above.", icon: "plus.circle")
|
||||||
|
} else {
|
||||||
|
ForEach(vm.servers) { server in
|
||||||
|
integratedRow(server)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(14)
|
||||||
|
}
|
||||||
|
.frame(height: 610)
|
||||||
|
Divider().overlay(.white.opacity(0.10))
|
||||||
|
footer
|
||||||
|
}
|
||||||
|
.frame(width: 960)
|
||||||
|
.background(
|
||||||
|
LinearGradient(colors: [Color(red: 0.10, green: 0.15, blue: 0.23), Color(red: 0.075, green: 0.09, blue: 0.13)], startPoint: .topTrailing, endPoint: .bottomLeading)
|
||||||
|
)
|
||||||
|
.sheet(isPresented: $settingsPresented) {
|
||||||
|
VStack(spacing: 0) {
|
||||||
|
HStack {
|
||||||
|
Text("Settings")
|
||||||
|
.font(.headline)
|
||||||
|
Spacer()
|
||||||
|
Button("Done") { settingsPresented = false }
|
||||||
|
.keyboardShortcut(.cancelAction)
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 18)
|
||||||
|
.padding(.top, 14)
|
||||||
|
.padding(.bottom, 8)
|
||||||
|
SettingsView()
|
||||||
|
.environmentObject(vm)
|
||||||
|
}
|
||||||
|
.frame(width: 650)
|
||||||
|
.interactiveDismissDisabled()
|
||||||
|
}
|
||||||
|
.preferredColorScheme(.dark)
|
||||||
|
.task { await vm.discoverVMs(); await vm.refreshAll() }
|
||||||
|
.alert("OrionToolbar", isPresented: Binding(get: { vm.lastError != nil }, set: { if !$0 { vm.lastError = nil } })) {
|
||||||
|
Button("OK") { vm.lastError = nil }
|
||||||
|
} message: { Text(vm.lastError ?? "") }
|
||||||
|
.confirmationDialog("Remove server integration?", isPresented: Binding(get: { pendingRemoval != nil }, set: { if !$0 { pendingRemoval = nil } }), titleVisibility: .visible) {
|
||||||
|
Button("Remove Integration", role: .destructive) {
|
||||||
|
if let server = pendingRemoval { vm.removeDefinition(server) }
|
||||||
|
pendingRemoval = nil
|
||||||
|
}
|
||||||
|
Button("Cancel", role: .cancel) { pendingRemoval = nil }
|
||||||
|
} message: {
|
||||||
|
Text("The Parallels virtual machine will not be deleted.")
|
||||||
|
}
|
||||||
|
.confirmationDialog("Force stop virtual machine?", isPresented: Binding(get: { pendingForceStop != nil }, set: { if !$0 { pendingForceStop = nil } }), titleVisibility: .visible) {
|
||||||
|
Button("Force Stop", role: .destructive) {
|
||||||
|
if let machine = pendingForceStop { vm.operate(machine, action: "force-stop") }
|
||||||
|
pendingForceStop = nil
|
||||||
|
}
|
||||||
|
Button("Cancel", role: .cancel) { pendingForceStop = nil }
|
||||||
|
} message: { Text("Force Stop immediately powers off the VM and can cause data loss.") }
|
||||||
|
}
|
||||||
|
|
||||||
|
private var header: some View {
|
||||||
|
HStack(spacing: 12) {
|
||||||
|
Image(systemName: "server.rack")
|
||||||
|
.font(.system(size: 22, weight: .bold))
|
||||||
|
.foregroundStyle(.cyan)
|
||||||
|
.frame(width: 37, height: 37)
|
||||||
|
.background(OrionStyle.blue.opacity(0.24), in: RoundedRectangle(cornerRadius: 10))
|
||||||
|
Text("OrionToolbar").font(.system(size: 21, weight: .bold))
|
||||||
|
Circle().fill(vm.discoveredVMs.isEmpty ? Color.orange : OrionStyle.green).frame(width: 8, height: 8)
|
||||||
|
Text(vm.discoveredVMs.isEmpty ? "Waiting for Parallels" : "Parallels Connected")
|
||||||
|
.foregroundStyle(OrionStyle.muted).font(.subheadline)
|
||||||
|
Spacer()
|
||||||
|
if vm.discovering { ProgressView().controlSize(.small) }
|
||||||
|
Button { Task { await vm.discoverVMs(); await vm.refreshAll() } } label: {
|
||||||
|
Image(systemName: "arrow.clockwise").font(.system(size: 16, weight: .semibold))
|
||||||
|
}.buttonStyle(OrionActionStyle(tint: OrionStyle.card)).help("Refresh virtual machines")
|
||||||
|
Button { showSettings() } label: {
|
||||||
|
Image(systemName: "gearshape.fill").font(.system(size: 16))
|
||||||
|
}.buttonStyle(OrionActionStyle(tint: OrionStyle.card)).help("Settings")
|
||||||
|
}.padding(.horizontal, 17).padding(.vertical, 13)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func section<Content: View>(icon: String, title: String, count: String, accent: Color, expanded: Binding<Bool>, @ViewBuilder content: () -> Content) -> some View {
|
||||||
|
VStack(spacing: 4) {
|
||||||
|
Button { expanded.wrappedValue.toggle() } label: {
|
||||||
|
HStack(spacing: 10) {
|
||||||
|
Image(systemName: icon).font(.system(size: 17, weight: .bold))
|
||||||
|
.foregroundStyle(accent).frame(width: 27)
|
||||||
|
Text(title).font(.system(size: 16, weight: .semibold))
|
||||||
|
Spacer()
|
||||||
|
Text(count).font(.caption.weight(.medium))
|
||||||
|
.foregroundStyle(accent)
|
||||||
|
.padding(.horizontal, 10).padding(.vertical, 5)
|
||||||
|
.background(accent.opacity(0.13), in: RoundedRectangle(cornerRadius: 8))
|
||||||
|
Image(systemName: expanded.wrappedValue ? "chevron.up" : "chevron.down")
|
||||||
|
.font(.caption.weight(.bold)).foregroundStyle(OrionStyle.muted)
|
||||||
|
}
|
||||||
|
.contentShape(Rectangle())
|
||||||
|
.padding(.horizontal, 11).padding(.vertical, 10)
|
||||||
|
}.buttonStyle(.plain)
|
||||||
|
if expanded.wrappedValue {
|
||||||
|
VStack(spacing: 3) { content() }
|
||||||
|
.padding(.horizontal, 5).padding(.bottom, 7)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.background(OrionStyle.panel.opacity(0.92), in: RoundedRectangle(cornerRadius: 16))
|
||||||
|
.overlay(RoundedRectangle(cornerRadius: 16).strokeBorder(.white.opacity(0.09)))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func emptyState(_ title: String, icon: String) -> some View {
|
||||||
|
Label(title, systemImage: icon)
|
||||||
|
.font(.subheadline).foregroundStyle(OrionStyle.muted)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
.padding(15)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func icon(_ machine: ParallelsVM) -> some View {
|
||||||
|
Group {
|
||||||
|
if let image = vm.icon(for: machine) {
|
||||||
|
Image(nsImage: image).resizable().scaledToFit()
|
||||||
|
} else {
|
||||||
|
Image(systemName: machine.operatingSystem == "Windows" ? "desktopcomputer" : "server.rack")
|
||||||
|
.font(.system(size: 21, weight: .medium))
|
||||||
|
.foregroundStyle(.white)
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
|
.background(osColor(machine.operatingSystem), in: Circle())
|
||||||
|
}
|
||||||
|
}.frame(width: 36, height: 36)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func osColor(_ os: String) -> Color {
|
||||||
|
switch os {
|
||||||
|
case "Ubuntu": return .orange
|
||||||
|
case "Debian": return .pink
|
||||||
|
case "Fedora": return .blue
|
||||||
|
case "CentOS": return .purple
|
||||||
|
case "Alpine": return .teal
|
||||||
|
case "Windows": return .cyan
|
||||||
|
default: return OrionStyle.blue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func state(_ status: String) -> some View {
|
||||||
|
let s = status.lowercased()
|
||||||
|
let color: Color = s == "running" ? OrionStyle.green : (s == "stopped" ? OrionStyle.muted : .orange)
|
||||||
|
return HStack(spacing: 6) {
|
||||||
|
Circle().fill(color).frame(width: 8, height: 8)
|
||||||
|
Text(status.capitalized).font(.system(size: 12, weight: .medium))
|
||||||
|
.foregroundStyle(color)
|
||||||
|
}.frame(width: 90, alignment: .leading)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func integrated(_ machine: ParallelsVM) -> ServerDefinition? {
|
||||||
|
vm.servers.first { $0.vmUUID == machine.id || $0.vmName == machine.name }
|
||||||
|
}
|
||||||
|
|
||||||
|
private func runningRow(_ machine: ParallelsVM) -> some View {
|
||||||
|
HStack(spacing: 10) {
|
||||||
|
icon(machine)
|
||||||
|
Text(machine.name).font(.system(size: 12, weight: .semibold)).lineLimit(1).frame(width: 210, alignment: .leading)
|
||||||
|
state(machine.status)
|
||||||
|
Text(machine.ipAddress.isEmpty ? "—" : machine.ipAddress)
|
||||||
|
.font(.system(size: 11, design: .monospaced))
|
||||||
|
.foregroundStyle(OrionStyle.muted).lineLimit(1).frame(width: 125, alignment: .leading)
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
if let server = integrated(machine) {
|
||||||
|
action("SSH", "terminal", tint: OrionStyle.blue) { vm.openSSH(server) }
|
||||||
|
.disabled(server.host.isEmpty || server.sshUser.isEmpty)
|
||||||
|
action("Mailpit", "globe", tint: OrionStyle.blue) { vm.openMailpit(server) }
|
||||||
|
.disabled(server.host.isEmpty || server.mailpitPort == nil)
|
||||||
|
}
|
||||||
|
if vm.busyVMIDs.contains(machine.id) {
|
||||||
|
ProgressView().controlSize(.small)
|
||||||
|
.frame(width: 70)
|
||||||
|
.help("Waiting for Parallels to complete the operation")
|
||||||
|
} else {
|
||||||
|
action("Restart", "arrow.clockwise", tint: OrionStyle.card) { vm.operate(machine, action: "restart") }
|
||||||
|
action("Stop", "stop.fill", tint: OrionStyle.red) { vm.operate(machine, action: "stop") }
|
||||||
|
}
|
||||||
|
Menu {
|
||||||
|
Button("Force Stop", role: .destructive) { pendingForceStop = machine }
|
||||||
|
} label: {
|
||||||
|
Image(systemName: "ellipsis").frame(width: 16)
|
||||||
|
}.menuStyle(.borderlessButton).frame(width: 22)
|
||||||
|
.help("More VM actions")
|
||||||
|
}
|
||||||
|
.disabled(vm.busyVMIDs.contains(machine.id))
|
||||||
|
.padding(.horizontal, 10).padding(.vertical, 7)
|
||||||
|
.background(OrionStyle.card.opacity(0.75), in: RoundedRectangle(cornerRadius: 10))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func machineRow(_ machine: ParallelsVM) -> some View {
|
||||||
|
HStack(spacing: 10) {
|
||||||
|
icon(machine)
|
||||||
|
Text(machine.name).font(.system(size: 12, weight: .semibold)).lineLimit(1).frame(width: 230, alignment: .leading)
|
||||||
|
state(machine.status)
|
||||||
|
Text(machine.ipAddress.isEmpty ? "—" : machine.ipAddress)
|
||||||
|
.font(.system(size: 11, design: .monospaced))
|
||||||
|
.foregroundStyle(OrionStyle.muted).lineLimit(1)
|
||||||
|
Spacer(minLength: 2)
|
||||||
|
if vm.busyVMIDs.contains(machine.id) { ProgressView().controlSize(.small) }
|
||||||
|
else if machine.status.lowercased() == "running" {
|
||||||
|
action("Stop", "stop.fill", tint: OrionStyle.red) { vm.operate(machine, action: "stop") }
|
||||||
|
} else if ["suspended", "paused"].contains(machine.status.lowercased()) {
|
||||||
|
action("Resume", "play.fill", tint: OrionStyle.blue) { vm.operate(machine, action: "resume") }
|
||||||
|
} else {
|
||||||
|
action("Start", "play.fill", tint: OrionStyle.blue) { vm.operate(machine, action: "start") }
|
||||||
|
}
|
||||||
|
if vm.isIntegrated(machine) {
|
||||||
|
Image(systemName: "checkmark.circle.fill").foregroundStyle(OrionStyle.green)
|
||||||
|
.frame(width: 28).help("Integrated")
|
||||||
|
} else {
|
||||||
|
Button { vm.integrate(machine) } label: {
|
||||||
|
Image(systemName: "plus.circle").font(.system(size: 20))
|
||||||
|
}.buttonStyle(.plain).foregroundStyle(OrionStyle.muted)
|
||||||
|
.frame(width: 28).help("Integrate VM")
|
||||||
|
}
|
||||||
|
Menu {
|
||||||
|
Button("Open in Parallels") { vm.openParallels() }
|
||||||
|
if machine.status.lowercased() == "running" {
|
||||||
|
Button("Restart") { vm.operate(machine, action: "restart") }
|
||||||
|
Button("Force Stop", role: .destructive) { pendingForceStop = machine }
|
||||||
|
}
|
||||||
|
} label: { Image(systemName: "chevron.right").foregroundStyle(OrionStyle.muted) }
|
||||||
|
.menuStyle(.borderlessButton).frame(width: 22)
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 10).padding(.vertical, 7)
|
||||||
|
.background(OrionStyle.card.opacity(0.75), in: RoundedRectangle(cornerRadius: 10))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func integratedRow(_ server: ServerDefinition) -> some View {
|
||||||
|
let machine = vm.discoveredVMs.first { $0.id == server.vmUUID || $0.name == server.vmName }
|
||||||
|
let status = machine?.status ?? "unavailable"
|
||||||
|
return HStack(spacing: 10) {
|
||||||
|
if let machine { icon(machine) }
|
||||||
|
else { Image(systemName: "server.rack").frame(width: 36, height: 36).foregroundStyle(.cyan) }
|
||||||
|
Text(server.name).font(.system(size: 12, weight: .semibold)).lineLimit(1).frame(width: 185, alignment: .leading)
|
||||||
|
state(status)
|
||||||
|
Text(server.host.isEmpty ? "—" : server.host)
|
||||||
|
.font(.system(size: 11, design: .monospaced)).foregroundStyle(OrionStyle.muted)
|
||||||
|
.lineLimit(1).frame(width: 125, alignment: .leading)
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
if let machine {
|
||||||
|
if status.lowercased() == "running" {
|
||||||
|
action("Stop", "stop.fill", tint: OrionStyle.red) { vm.operate(machine, action: "stop") }
|
||||||
|
} else {
|
||||||
|
action("Start", "play.fill", tint: OrionStyle.blue) { vm.operate(machine, action: "start") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
action("SSH", "terminal", tint: OrionStyle.card) { vm.openSSH(server) }
|
||||||
|
.disabled(status.lowercased() != "running" || server.host.isEmpty || server.sshUser.isEmpty)
|
||||||
|
action("Mailpit", "globe", tint: OrionStyle.card) { vm.openMailpit(server) }
|
||||||
|
.disabled(status.lowercased() != "running" || server.host.isEmpty || server.mailpitPort == nil)
|
||||||
|
action("Remove", "trash", tint: OrionStyle.card) { pendingRemoval = server }
|
||||||
|
}
|
||||||
|
.disabled(machine.map { vm.busyVMIDs.contains($0.id) } ?? false)
|
||||||
|
.padding(.horizontal, 10).padding(.vertical, 7)
|
||||||
|
.background(OrionStyle.card.opacity(0.75), in: RoundedRectangle(cornerRadius: 10))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func action(_ title: String, _ symbol: String, tint: Color, perform: @escaping () -> Void) -> some View {
|
||||||
|
Button(action: perform) {
|
||||||
|
Label(title, systemImage: symbol)
|
||||||
|
.font(.system(size: 11, weight: .semibold))
|
||||||
|
.lineLimit(1)
|
||||||
|
.frame(minWidth: 48)
|
||||||
|
}.buttonStyle(OrionActionStyle(tint: tint))
|
||||||
|
}
|
||||||
|
|
||||||
|
private var footer: some View {
|
||||||
|
HStack {
|
||||||
|
action("Open Parallels", "macwindow", tint: OrionStyle.card) { vm.openParallels() }
|
||||||
|
Spacer()
|
||||||
|
action("Settings…", "gearshape", tint: OrionStyle.card) { showSettings() }
|
||||||
|
action("Quit", "power", tint: OrionStyle.card) { NSApplication.shared.terminate(nil) }
|
||||||
|
}.padding(.horizontal, 17).padding(.vertical, 12)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func showSettings() {
|
||||||
|
settingsPresented = true
|
||||||
|
NSApplication.shared.activate(ignoringOtherApps: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct OrionActionStyle: ButtonStyle {
|
||||||
|
let tint: Color
|
||||||
|
func makeBody(configuration: Configuration) -> some View {
|
||||||
|
configuration.label
|
||||||
|
.foregroundStyle(.white)
|
||||||
|
.padding(.horizontal, 8).padding(.vertical, 7)
|
||||||
|
.background(tint.opacity(configuration.isPressed ? 0.65 : 1), in: RoundedRectangle(cornerRadius: 8))
|
||||||
|
.opacity(configuration.isPressed ? 0.8 : 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Replace fragile MenuBarExtra Settings sheet with a standalone modal NSWindow."""
|
||||||
|
from pathlib import Path
|
||||||
|
from datetime import datetime
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
root = Path(__file__).resolve().parent.parent
|
||||||
|
if not (root / 'OrionToolbar/OrionMenuView.swift').exists():
|
||||||
|
root = Path.cwd()
|
||||||
|
path = root / 'OrionToolbar/OrionMenuView.swift'
|
||||||
|
if not path.is_file():
|
||||||
|
raise SystemExit(f'Missing {path}')
|
||||||
|
s = path.read_text()
|
||||||
|
if 'OrionSettingsWindowPresenter.present(vm: vm)' in s:
|
||||||
|
print('Already applied')
|
||||||
|
raise SystemExit(0)
|
||||||
|
start = s.find(' .sheet(isPresented: $settingsPresented) {')
|
||||||
|
if start < 0:
|
||||||
|
raise SystemExit('Expected Settings sheet not found. No changes made.')
|
||||||
|
# Match Swift brace depth for the .sheet closure.
|
||||||
|
brace = s.find('{', start)
|
||||||
|
depth = 0
|
||||||
|
end = None
|
||||||
|
for i in range(brace, len(s)):
|
||||||
|
if s[i] == '{': depth += 1
|
||||||
|
elif s[i] == '}':
|
||||||
|
depth -= 1
|
||||||
|
if depth == 0:
|
||||||
|
end = i + 1
|
||||||
|
break
|
||||||
|
if end is None:
|
||||||
|
raise SystemExit('Unbalanced Settings sheet. No changes made.')
|
||||||
|
s = s[:start] + s[end:]
|
||||||
|
s = s.replace(' @State private var settingsPresented = false\n', '', 1)
|
||||||
|
start = s.find(' private func showSettings() {')
|
||||||
|
if start < 0:
|
||||||
|
raise SystemExit('showSettings() not found. No changes made.')
|
||||||
|
brace = s.find('{', start)
|
||||||
|
depth = 0
|
||||||
|
end = None
|
||||||
|
for i in range(brace, len(s)):
|
||||||
|
if s[i] == '{': depth += 1
|
||||||
|
elif s[i] == '}':
|
||||||
|
depth -= 1
|
||||||
|
if depth == 0:
|
||||||
|
end = i + 1
|
||||||
|
break
|
||||||
|
if end is None:
|
||||||
|
raise SystemExit('Unbalanced showSettings(). No changes made.')
|
||||||
|
s = s[:start] + ''' private func showSettings() {
|
||||||
|
OrionSettingsWindowPresenter.present(vm: vm)
|
||||||
|
}''' + s[end:]
|
||||||
|
# Put window presentation in the existing file so no Xcode project membership changes are required.
|
||||||
|
s += '''
|
||||||
|
|
||||||
|
// A MenuBarExtra window is transient. Sheets attached to it can disappear
|
||||||
|
// when the user interacts with controls inside Settings. Use a real window.
|
||||||
|
@MainActor
|
||||||
|
private final class OrionSettingsWindowPresenter: NSObject, NSWindowDelegate {
|
||||||
|
private static var current: OrionSettingsWindowPresenter?
|
||||||
|
private var window: NSWindow?
|
||||||
|
|
||||||
|
static func present(vm: OrionVMController) {
|
||||||
|
if let current, let window = current.window {
|
||||||
|
NSApp.activate(ignoringOtherApps: true)
|
||||||
|
window.makeKeyAndOrderFront(nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let presenter = OrionSettingsWindowPresenter()
|
||||||
|
current = presenter
|
||||||
|
presenter.open(vm: vm)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func open(vm: OrionVMController) {
|
||||||
|
let content = SettingsView()
|
||||||
|
.environmentObject(vm)
|
||||||
|
.preferredColorScheme(.dark)
|
||||||
|
let window = NSWindow(
|
||||||
|
contentRect: NSRect(x: 0, y: 0, width: 650, height: 380),
|
||||||
|
styleMask: [.titled, .closable, .miniaturizable],
|
||||||
|
backing: .buffered,
|
||||||
|
defer: false
|
||||||
|
)
|
||||||
|
window.title = "OrionToolbar Settings"
|
||||||
|
window.contentViewController = NSHostingController(rootView: content)
|
||||||
|
window.delegate = self
|
||||||
|
window.isReleasedWhenClosed = false
|
||||||
|
window.level = .floating
|
||||||
|
window.center()
|
||||||
|
self.window = window
|
||||||
|
NSApp.activate(ignoringOtherApps: true)
|
||||||
|
window.makeKeyAndOrderFront(nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func windowWillClose(_ notification: Notification) {
|
||||||
|
window = nil
|
||||||
|
Self.current = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
backup = root / 'backups' / datetime.now().strftime('%Y%m%d-%H%M%S-%f') / 'OrionToolbar' / path.name
|
||||||
|
backup.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
shutil.copy2(path, backup)
|
||||||
|
path.write_text(s)
|
||||||
|
print('Updated:', path)
|
||||||
|
print('Backup:', backup)
|
||||||
|
print('Settings now uses a persistent foreground window.')
|
||||||
Reference in New Issue
Block a user