Skip to content

Commit aa77365

Browse files
committed
Simplify
1 parent 3d85d7e commit aa77365

6 files changed

Lines changed: 16 additions & 28 deletions

File tree

cardinal/src/App.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ function App() {
7171
const {
7272
isShortcutSettingsOpen,
7373
shortcuts,
74-
defaultShortcuts,
7574
openShortcutSettings,
7675
closeShortcutSettings,
7776
handleShortcutSettingsSave,
@@ -433,7 +432,6 @@ function App() {
433432
open={isShortcutSettingsOpen}
434433
onClose={closeShortcutSettings}
435434
shortcuts={shortcuts}
436-
defaultShortcuts={defaultShortcuts}
437435
onShortcutSettingsSave={handleShortcutSettingsSave}
438436
/>
439437
{showFullDiskAccessOverlay && (

cardinal/src/components/ShortcutSettingsOverlay.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import React, { useCallback, useEffect, useState } from 'react';
22
import { useTranslation } from 'react-i18next';
3-
import { SHORTCUT_DEFINITIONS, type ShortcutId, type ShortcutMap } from '../shortcuts';
3+
import {
4+
DEFAULT_SHORTCUTS,
5+
SHORTCUT_DEFINITIONS,
6+
type ShortcutId,
7+
type ShortcutMap,
8+
} from '../shortcuts';
49
import {
510
captureShortcutFromKeydown,
611
formatShortcutForDisplay,
@@ -11,7 +16,6 @@ type ShortcutSettingsOverlayProps = {
1116
open: boolean;
1217
onClose: () => void;
1318
shortcuts: ShortcutMap;
14-
defaultShortcuts: ShortcutMap;
1519
onShortcutSettingsSave: (shortcuts: ShortcutMap) => Promise<void>;
1620
};
1721

@@ -25,7 +29,6 @@ export function ShortcutSettingsOverlay({
2529
open,
2630
onClose,
2731
shortcuts,
28-
defaultShortcuts,
2932
onShortcutSettingsSave,
3033
}: ShortcutSettingsOverlayProps): React.JSX.Element | null {
3134
const { t } = useTranslation();
@@ -101,7 +104,7 @@ export function ShortcutSettingsOverlay({
101104
setCaptureError(null);
102105
setSubmitError(null);
103106
setRecordingShortcutId(null);
104-
setDraftShortcuts(defaultShortcuts);
107+
setDraftShortcuts(DEFAULT_SHORTCUTS);
105108
};
106109

107110
const handleCaptureButtonClick = useCallback((shortcutId: ShortcutId): void => {

cardinal/src/components/__tests__/ShortcutSettingsOverlay.test.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ describe('ShortcutSettingsOverlay', () => {
1717
open
1818
onClose={vi.fn()}
1919
shortcuts={DEFAULT_SHORTCUTS}
20-
defaultShortcuts={DEFAULT_SHORTCUTS}
2120
onShortcutSettingsSave={onShortcutSettingsSave}
2221
/>,
2322
);
@@ -44,7 +43,6 @@ describe('ShortcutSettingsOverlay', () => {
4443
open
4544
onClose={vi.fn()}
4645
shortcuts={DEFAULT_SHORTCUTS}
47-
defaultShortcuts={DEFAULT_SHORTCUTS}
4846
onShortcutSettingsSave={vi.fn().mockResolvedValue(undefined)}
4947
/>,
5048
);

cardinal/src/hooks/useShortcutSettingsController.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
import { useCallback, useEffect, useState } from 'react';
22
import { refreshAppMenu, setMenuShortcutsEnabled } from '../menu';
3-
import {
4-
DEFAULT_SHORTCUTS,
5-
getStoredShortcuts,
6-
persistShortcuts,
7-
type ShortcutMap,
8-
} from '../shortcuts';
3+
import { getStoredShortcuts, persistShortcuts, type ShortcutMap } from '../shortcuts';
94
import { refreshTrayMenu } from '../tray';
105
import { setGlobalShortcutsPaused, updateQuickLaunchShortcut } from '../utils/globalShortcuts';
116

127
type UseShortcutSettingsControllerResult = {
138
isShortcutSettingsOpen: boolean;
149
shortcuts: ShortcutMap;
15-
defaultShortcuts: ShortcutMap;
1610
openShortcutSettings: () => void;
1711
closeShortcutSettings: () => void;
1812
handleShortcutSettingsSave: (nextShortcuts: ShortcutMap) => Promise<void>;
@@ -51,7 +45,6 @@ export function useShortcutSettingsController(): UseShortcutSettingsControllerRe
5145
return {
5246
isShortcutSettingsOpen,
5347
shortcuts,
54-
defaultShortcuts: DEFAULT_SHORTCUTS,
5548
openShortcutSettings,
5649
closeShortcutSettings,
5750
handleShortcutSettingsSave,

cardinal/src/shortcuts.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,17 @@ export const getStoredShortcuts = (): ShortcutMap => {
7272
}
7373
};
7474

75-
export const getStoredShortcutAccelerators = () => {
76-
const { quickLaunch, openPreferences, hideWindow } = getStoredShortcuts();
75+
export const getShortcutAccelerators = (shortcuts: ShortcutMap) => {
76+
const { quickLaunch, openPreferences, hideWindow } = shortcuts;
7777
return {
7878
quickLaunch,
7979
openPreferences: toMenuAccelerator(openPreferences),
8080
hideWindow: toMenuAccelerator(hideWindow),
8181
};
8282
};
8383

84+
export const getStoredShortcutAccelerators = () => getShortcutAccelerators(getStoredShortcuts());
85+
8486
export const persistShortcuts = (shortcuts: ShortcutMap): void => {
8587
if (typeof window === 'undefined') {
8688
return;

cardinal/src/utils/globalShortcuts.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ const registerQuickLaunchShortcut = async (shortcut: string): Promise<void> => {
1616
registeredQuickLaunchShortcut = shortcut;
1717
};
1818

19-
const saveQuickLaunchShortcut = (shortcut: string): void => {
20-
persistShortcuts({
21-
...getStoredShortcuts(),
22-
quickLaunch: shortcut,
23-
});
24-
};
25-
2619
export async function initializeGlobalShortcuts(): Promise<void> {
2720
const preferredShortcut = getStoredShortcuts().quickLaunch;
2821

@@ -33,7 +26,10 @@ export async function initializeGlobalShortcuts(): Promise<void> {
3326
if (preferredShortcut !== DEFAULT_QUICK_LAUNCH_SHORTCUT) {
3427
try {
3528
await registerQuickLaunchShortcut(DEFAULT_QUICK_LAUNCH_SHORTCUT);
36-
saveQuickLaunchShortcut(DEFAULT_QUICK_LAUNCH_SHORTCUT);
29+
persistShortcuts({
30+
...getStoredShortcuts(),
31+
quickLaunch: DEFAULT_QUICK_LAUNCH_SHORTCUT,
32+
});
3733
} catch (fallbackError) {
3834
console.error('Failed to register fallback global shortcut', fallbackError);
3935
}
@@ -54,7 +50,6 @@ export async function updateQuickLaunchShortcut(shortcut: string): Promise<void>
5450

5551
if (globalShortcutsPaused) {
5652
registeredQuickLaunchShortcut = nextShortcut;
57-
saveQuickLaunchShortcut(nextShortcut);
5853
return;
5954
}
6055

@@ -64,7 +59,6 @@ export async function updateQuickLaunchShortcut(shortcut: string): Promise<void>
6459

6560
try {
6661
await registerQuickLaunchShortcut(nextShortcut);
67-
saveQuickLaunchShortcut(nextShortcut);
6862
} catch (error) {
6963
if (previousShortcut) {
7064
try {

0 commit comments

Comments
 (0)