Skip to content

Commit

Permalink
macos: add Window>Show UTM menu option
Browse files Browse the repository at this point in the history
  • Loading branch information
garamb1 committed Nov 18, 2023
1 parent dacf074 commit 387663b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Platform/Shared/VMCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
}
5 changes: 4 additions & 1 deletion Platform/macOS/UTMApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -32,6 +32,9 @@ struct UTMApp: App {
data.showErrorAlert(message: message)
}
}
.onReceive(NSNotification.ShowMainWindow) { _ in
NSApplication.shared.windows.first?.makeKeyAndOrderFront(nil)
}
}

@SceneBuilder
Expand Down

0 comments on commit 387663b

Please sign in to comment.