Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macos: add Window>Show UTM menu option #5908

Closed
wants to merge 11 commits into from
6 changes: 6 additions & 0 deletions Platform/Shared/VMCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ struct VMCommands: Commands {
#endif
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 @@ -58,4 +63,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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is good enough. I might play around with it but thinking of capturing a reference in the AppDelegate in order to reference it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, thanks!

}
}

@SceneBuilder
Expand Down
Loading