diff --git a/apps/desktop/src-tauri/src/core/system/shortcut.rs b/apps/desktop/src-tauri/src/core/system/shortcut.rs index 83baa11e..2f9155d0 100644 --- a/apps/desktop/src-tauri/src/core/system/shortcut.rs +++ b/apps/desktop/src-tauri/src/core/system/shortcut.rs @@ -49,20 +49,28 @@ pub fn register_global_shortcut( ) -> Result<(), String> { let new_shortcut = parse_shortcut(&shortcut)?; - // 注销旧快捷键 - if let Ok(current) = CURRENT_SHORTCUT.lock() { - if let Some(old_shortcut) = *current { - let _ = app.global_shortcut().unregister(old_shortcut); + let old_shortcut = CURRENT_SHORTCUT.lock().ok().and_then(|current| *current); + if let Some(old_shortcut) = old_shortcut { + if let Err(error) = app.global_shortcut().unregister(old_shortcut) { + let message = format!("Failed to unregister previous shortcut: {}", error); + if let Ok(mut status) = REGISTRATION_STATUS.lock() { + *status = (true, Some(message.clone())); + } + return Err(message); } } - // 尝试注册新快捷键 let result = app .global_shortcut() .register(new_shortcut) .map_err(|e| format!("Failed to register shortcut: {}", e)); - // 更新状态 + if result.is_err() { + if let Some(old_shortcut) = old_shortcut { + let _ = app.global_shortcut().register(old_shortcut); + } + } + match result { Ok(_) => { if let Ok(mut current) = CURRENT_SHORTCUT.lock() { diff --git a/apps/desktop/src/components/CustomSelect.vue b/apps/desktop/src/components/CustomSelect.vue index e70bb2b5..c67047cb 100644 --- a/apps/desktop/src/components/CustomSelect.vue +++ b/apps/desktop/src/components/CustomSelect.vue @@ -8,7 +8,7 @@ SelectTrigger, SelectValue, } from '@components/ui/select'; - import type { AcceptableValue } from 'reka-ui'; + import type { AcceptableValue, SelectTriggerProps } from 'reka-ui'; import { computed, ref, useAttrs } from 'vue'; import { type MessageKey, t, tt } from '@/i18n'; @@ -29,22 +29,48 @@ placeholderKey?: MessageKey; disabled?: boolean; protectOptionText?: boolean; + open?: boolean; + displayLabel?: string; + triggerTestId?: string; + contentTestId?: string; + optionTestIdPrefix?: string; + disablePortal?: boolean; + triggerAs?: SelectTriggerProps['as']; } interface Emits { (e: 'update:modelValue', value: T): void; + (e: 'update:open', value: boolean): void; + (e: 'focus', event: FocusEvent): void; + (e: 'blur', event: FocusEvent): void; } const props = withDefaults(defineProps(), { placeholder: '', disabled: false, protectOptionText: false, + open: undefined, + displayLabel: '', + triggerTestId: '', + contentTestId: '', + optionTestIdPrefix: '', + disablePortal: false, + triggerAs: 'button', }); const emit = defineEmits(); + defineSlots<{ + trigger?(props: { + option: Option | undefined; + open: boolean; + displayLabel: string; + }): unknown; + }>(); const attrs = useAttrs(); - const isOpen = ref(false); + const localOpen = ref(false); + + const isOpen = computed(() => props.open ?? localOpen.value); const selectedOption = computed(() => { return props.options.find((opt) => opt.value === props.modelValue); @@ -66,6 +92,11 @@ selectOption(value as T); } }; + + const updateOpen = (open: boolean) => { + localOpen.value = open; + emit('update:open', open); + };