VMCommands.swift 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // Copyright © 2020 osy. All rights reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. import SwiftUI
  17. struct VMCommands: Commands {
  18. @Environment(\.openURL) private var openURL
  19. @CommandsBuilder
  20. var body: some Commands {
  21. #if !WITH_REMOTE // FIXME: implement remote feature
  22. CommandGroup(replacing: .newItem) {
  23. Button(action: { NotificationCenter.default.post(name: NSNotification.NewVirtualMachine, object: nil) }, label: {
  24. Text("New…")
  25. }).keyboardShortcut(KeyEquivalent("n"))
  26. Button(action: { NotificationCenter.default.post(name: NSNotification.OpenVirtualMachine, object: nil) }, label: {
  27. Text("Open…")
  28. }).keyboardShortcut(KeyEquivalent("o"))
  29. }
  30. #endif
  31. SidebarCommands()
  32. ToolbarCommands()
  33. CommandGroup(replacing: .help) {
  34. Button(action: { NotificationCenter.default.post(name: NSNotification.ShowReleaseNotes, object: nil) }, label: {
  35. Text("What's New")
  36. }).keyboardShortcut(KeyEquivalent("1"), modifiers: [.command, .control])
  37. Button(action: { openLink("https://mac.getutm.app/gallery/") }, label: {
  38. Text("Virtual Machine Gallery")
  39. }).keyboardShortcut(KeyEquivalent("2"), modifiers: [.command, .control])
  40. Button(action: { openLink("https://docs.getutm.app/") }, label: {
  41. Text("Support")
  42. }).keyboardShortcut(KeyEquivalent("3"), modifiers: [.command, .control])
  43. Button(action: { openLink("https://mac.getutm.app/licenses/") }, label: {
  44. Text("License")
  45. }).keyboardShortcut(KeyEquivalent("4"), modifiers: [.command, .control])
  46. }
  47. }
  48. private func openLink(_ url: String) {
  49. openURL(URL(string: url)!)
  50. }
  51. }
  52. extension NSNotification {
  53. static let NewVirtualMachine = NSNotification.Name("NewVirtualMachine")
  54. static let OpenVirtualMachine = NSNotification.Name("OpenVirtualMachine")
  55. static let ShowReleaseNotes = NSNotification.Name("ShowReleaseNotes")
  56. static let InstallGuestTools = NSNotification.Name("InstallGuestTools")
  57. }