diff --git a/ishare/Util/AppState.swift b/ishare/Util/AppState.swift index 5d1d0c7..de253f9 100644 --- a/ishare/Util/AppState.swift +++ b/ishare/Util/AppState.swift @@ -11,10 +11,14 @@ import KeyboardShortcuts final class AppState: ObservableObject { @Default(.showMainMenu) var showMainMenu + @Default(.uploadHistory) var uploadHistory init() { - KeyboardShortcuts.onKeyUp(for: .toggleMainMenu) { - self.showMainMenu = true + KeyboardShortcuts.onKeyUp(for: .toggleMainMenu) { [self] in + showMainMenu = true + } + KeyboardShortcuts.onKeyUp(for: .openHistoryWindow) { [self] in + openHistoryWindow(uploadHistory: uploadHistory) } KeyboardShortcuts.onKeyUp(for: .captureRegion) { captureScreen(type: .REGION) diff --git a/ishare/Util/Constants.swift b/ishare/Util/Constants.swift index df7e106..b8c8538 100644 --- a/ishare/Util/Constants.swift +++ b/ishare/Util/Constants.swift @@ -24,6 +24,7 @@ extension KeyboardShortcuts.Name { static let captureScreen = Self("captureScreen", default: .init(.x, modifiers: [.option, .command])) static let recordScreen = Self("recordScreen", default: .init(.z, modifiers: [.control, .option])) static let recordGif = Self("recordGif", default: .init(.g, modifiers: [.control, .option])) + static let openHistoryWindow = Self("openHistoryWindow", default: .init(.k, modifiers: [.command, .option])) } extension Defaults.Keys { diff --git a/ishare/Views/MainMenuView.swift b/ishare/Views/MainMenuView.swift index 75fe1f0..98f2617 100644 --- a/ishare/Views/MainMenuView.swift +++ b/ishare/Views/MainMenuView.swift @@ -38,6 +38,23 @@ class WindowHolder { var historyWindowController: HistoryWindowController? } +func openHistoryWindow(uploadHistory: [HistoryItem]) { + if WindowHolder.shared.historyWindowController == nil { + let historyView = HistoryGridView(uploadHistory: uploadHistory) + let hostingController = NSHostingController(rootView: historyView) + let windowController = HistoryWindowController(contentView: hostingController.view) + windowController.window?.title = "History" + + windowController.showWindow(nil) + NSApp.activate(ignoringOtherApps: true) + + WindowHolder.shared.historyWindowController = windowController + } else { + WindowHolder.shared.historyWindowController?.window?.makeKeyAndOrderFront(nil) + NSApp.activate(ignoringOtherApps: true) + } +} + struct MainMenuView: View { @Default(.copyToClipboard) var copyToClipboard @Default(.openInFinder) var openInFinder @@ -52,23 +69,6 @@ struct MainMenuView: View { @StateObject private var availableContentProvider = AvailableContentProvider() - private func openHistoryWindow() { - if WindowHolder.shared.historyWindowController == nil { - let historyView = HistoryGridView(uploadHistory: uploadHistory) - let hostingController = NSHostingController(rootView: historyView) - let windowController = HistoryWindowController(contentView: hostingController.view) - windowController.window?.title = "History" - - windowController.showWindow(nil) - NSApp.activate(ignoringOtherApps: true) - - WindowHolder.shared.historyWindowController = windowController - } else { - WindowHolder.shared.historyWindowController?.window?.makeKeyAndOrderFront(nil) - NSApp.activate(ignoringOtherApps: true) - } - } - var body: some View { VStack { Menu { @@ -250,11 +250,11 @@ struct MainMenuView: View { if !uploadHistory.isEmpty { Menu { Button { - openHistoryWindow() + openHistoryWindow(uploadHistory: uploadHistory) } label: { Image(systemName: "clock.arrow.circlepath") Label("Open History Window", image: String()) - } + }.keyboardShortcut(.openHistoryWindow) Divider() diff --git a/ishare/Views/SettingsMenuView.swift b/ishare/Views/SettingsMenuView.swift index b25025b..0fa0f62 100644 --- a/ishare/Views/SettingsMenuView.swift +++ b/ishare/Views/SettingsMenuView.swift @@ -100,6 +100,7 @@ struct KeybindSettingsView: View { VStack { Form { KeyboardShortcuts.Recorder("Open Main Menu:", name: .toggleMainMenu) + KeyboardShortcuts.Recorder("Open History Window:", name: .openHistoryWindow) KeyboardShortcuts.Recorder("Capture Region:", name: .captureRegion) KeyboardShortcuts.Recorder("Capture Window:", name: .captureWindow) KeyboardShortcuts.Recorder("Capture Screen:", name: .captureScreen) @@ -107,7 +108,7 @@ struct KeybindSettingsView: View { KeyboardShortcuts.Recorder("Record GIF:", name: .recordGif) } Button("Reset") { - KeyboardShortcuts.reset([.toggleMainMenu, .captureRegion, .captureWindow, .captureScreen, .recordScreen, .recordGif]) + KeyboardShortcuts.reset([.toggleMainMenu,.openHistoryWindow, .captureRegion, .captureWindow, .captureScreen, .recordScreen, .recordGif]) BezelNotification.show(messageText: "Reset keybinds", icon: ToastIcon) } }