From 387663bdc5b5c4f779022e6fb64c1fdf83cbd0a7 Mon Sep 17 00:00:00 2001 From: Vincenzo Garambone Date: Sat, 18 Nov 2023 18:29:51 +0100 Subject: [PATCH] macos: add Window>Show UTM menu option --- Platform/Shared/VMCommands.swift | 6 ++++++ Platform/macOS/UTMApp.swift | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Platform/Shared/VMCommands.swift b/Platform/Shared/VMCommands.swift index 54cc75970..558488d4b 100644 --- a/Platform/Shared/VMCommands.swift +++ b/Platform/Shared/VMCommands.swift @@ -31,6 +31,11 @@ struct VMCommands: Commands { } SidebarCommands() ToolbarCommands() + CommandGroup(replacing: .windowList, addition: { + Button(action: { NotificationCenter.default.post(name: NSNotification.ShowMainWindow, object: nil) }, label: { + Text("Show UTM") + }).keyboardShortcut(KeyEquivalent("L"), modifiers: [.command, .option]) + }) CommandGroup(replacing: .help) { Button(action: { NotificationCenter.default.post(name: NSNotification.ShowReleaseNotes, object: nil) }, label: { Text("What's New") @@ -56,4 +61,5 @@ extension NSNotification { static let NewVirtualMachine = NSNotification.Name("NewVirtualMachine") static let OpenVirtualMachine = NSNotification.Name("OpenVirtualMachine") static let ShowReleaseNotes = NSNotification.Name("ShowReleaseNotes") + static let ShowMainWindow = NSNotification.Name("ShowMainWindow") } diff --git a/Platform/macOS/UTMApp.swift b/Platform/macOS/UTMApp.swift index 3e70c479a..ee11f7d00 100644 --- a/Platform/macOS/UTMApp.swift +++ b/Platform/macOS/UTMApp.swift @@ -19,7 +19,7 @@ import SwiftUI struct UTMApp: App { @State var data = UTMData() @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate: AppDelegate - + @ViewBuilder var homeWindow: some View { ContentView().environmentObject(data) @@ -32,6 +32,9 @@ struct UTMApp: App { data.showErrorAlert(message: message) } } + .onReceive(NSNotification.ShowMainWindow) { _ in + NSApplication.shared.windows.first?.makeKeyAndOrderFront(nil) + } } @SceneBuilder