Add some macOS menu & shortcuts

This commit is contained in:
Thomas Ricouard 2023-01-18 08:27:42 +01:00
parent 5ff0330fb7
commit 1b9d4e0247
3 changed files with 27 additions and 5 deletions

View file

@ -56,11 +56,7 @@ struct IceCubesApp: App {
})
}
.commands {
CommandGroup(replacing: CommandGroupPlacement.newItem) {
Button("New post") {
sidebarRouterPath.presentedSheet = .newStatusEditor(visibility: userPreferences.serverPreferences?.postVisibility ?? .pub)
}
}
appMenu
}
.onChange(of: scenePhase) { scenePhase in
handleScenePhase(scenePhase: scenePhase)
@ -172,6 +168,29 @@ struct IceCubesApp: App {
private func refreshPushSubs() {
PushNotificationsService.shared.requestPushNotifications()
}
@CommandsBuilder
private var appMenu: some Commands {
CommandGroup(replacing: .newItem) {
Button("New post") {
sidebarRouterPath.presentedSheet = .newStatusEditor(visibility: userPreferences.serverPreferences?.postVisibility ?? .pub)
}
}
CommandGroup(replacing: .textFormatting) {
Menu("Font") {
Button("Bigger") {
if userPreferences.fontSizeScale < 1.5 {
userPreferences.fontSizeScale += 0.1
}
}
Button("Smaller") {
if userPreferences.fontSizeScale > 0.5 {
userPreferences.fontSizeScale -= 0.1
}
}
}
}
}
}
class AppDelegate: NSObject, UIApplicationDelegate {

View file

@ -110,6 +110,7 @@ public struct StatusEditorView: View {
}
}
.disabled(!viewModel.canPost)
.keyboardShortcut(.return, modifiers: .command)
}
ToolbarItem(placement: .navigationBarLeading) {
Button {
@ -123,6 +124,7 @@ public struct StatusEditorView: View {
} label: {
Text("Cancel")
}
.keyboardShortcut(.cancelAction)
.confirmationDialog("",
isPresented: $isDismissAlertPresented,
actions: {

View file

@ -115,6 +115,7 @@ public struct TimelineView: View {
} label: {
Text(viewModel.pendingStatusesButtonTitle)
}
.keyboardShortcut("r", modifiers: .command)
.buttonStyle(.bordered)
.background(.thinMaterial)
.cornerRadius(8)