This commit is contained in:
2025-12-06 19:29:34 +08:00
parent fa24a82568
commit 7b99bc0b54
8 changed files with 340 additions and 53 deletions

58
src/apps/hotkeys/store.ts Normal file
View File

@@ -0,0 +1,58 @@
import { create } from 'zustand';
import { query } from '../../modules/query'
// --- Types ---
export interface CardItem {
id: string;
title: string;
iconUrl?: string;
description?: string;
data?: any;
}
export interface StoreState {
items: CardItem[];
isLoading: boolean;
fetchItems: () => Promise<void>;
sendEvent: (item: CardItem) => Promise<void>;
}
// --- Store ---
export const useStore = create<StoreState>((set) => ({
items: [],
isLoading: false,
fetchItems: async () => {
set({ isLoading: true });
// TODO: Replace with actual API call
// const response = await fetch('/api/hotkeys');
// const data = await response.json();
// Mock data for demonstration
const mockData: CardItem[] = Array.from({ length: 12 }).map((_, i) => ({
id: `item-${i}`,
title: i % 4 === 0 ? `工具 ${i + 1}` : `Application Long Name ${i + 1}`,
iconUrl: i % 3 === 0 ? `https://api.dicebear.com/7.x/icons/svg?seed=${i}` : undefined,
description: `Description for item ${i + 1}`
}));
mockData.unshift({
id: 'item-search',
title: 'win+d 显示桌面',
iconUrl: 'https://api.dicebear.com/7.x/icons/svg?seed=search',
description: '显示桌面'
})
// Simulate network delay
await new Promise(resolve => setTimeout(resolve, 800));
set({ items: mockData, isLoading: false });
},
sendEvent: async (item: CardItem) => {
// client/router?path=key-sender&keys=win+d
const res = await query.post({
path: 'key-sender',
keys: 'win+d'
});
console.log('Event sent for item:', item, 'Response:', res);
if (res.code !== 200) {
alert('Failed to send event');
}
}
}));