This commit is contained in:
2025-12-05 10:57:02 +08:00
parent da3958f8f0
commit db3334ec6c
9 changed files with 1129 additions and 38 deletions

View File

@@ -35,6 +35,7 @@
"@kevisual/query": "^0.0.29", "@kevisual/query": "^0.0.29",
"@kevisual/router": "0.0.33", "@kevisual/router": "0.0.33",
"@kevisual/use-config": "^1.0.19", "@kevisual/use-config": "^1.0.19",
"@nut-tree/nut-js": "^4.2.0",
"archiver": "^7.0.1", "archiver": "^7.0.1",
"dayjs": "^1.11.19", "dayjs": "^1.11.19",
"es-toolkit": "^1.42.0", "es-toolkit": "^1.42.0",

1030
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,21 +0,0 @@
import { App } from '@kevisual/router';
const app = new App();
app.route({
description: 'Demo route',
id: 'abc'
}).define(async (ctx) => {
ctx.body = 'Hello, Kevisual Router!';
}).addTo(app);
app.router.createRouteList()
app.call({
path: 'route',
key: 'list'
}).then((res) => {
console.log('Registered res:', res);
}).catch((error) => {
console.error('Error fetching res:', error);
});

View File

34
src/hot-api/index.ts Normal file
View File

@@ -0,0 +1,34 @@
type Hotkey = {
key: string,
description: string,
action: () => void,
}
type BrowserLink = {
url: string,
description: string,
action: () => void,
}
type AppProgram = {
path: string,
description: string,
action: () => void,
}
type HotApiItem = {
type: 'hotkey' | 'browser-link' | 'app-program',
hotkey?: Hotkey,
browserLink?: BrowserLink,
appProgram?: AppProgram,
}
export class HotApi {
private items: HotApiItem[] = [];
constructor() {
this.items = [];
}
addItem(item: HotApiItem) {
this.items.push(item);
}
getItems() {
return this.items;
}
}

View File

@@ -1,6 +1,6 @@
import { app } from './app.ts' import { app } from './app.ts'
import './router/index.ts'; import './router/index.ts';
import { HOME } from './config.ts'; import { HOME } from './module/config.ts';
import { proxyRoute, initProxy } from '@kevisual/local-proxy/proxy.ts'; import { proxyRoute, initProxy } from '@kevisual/local-proxy/proxy.ts';
export { app } export { app }

View File

@@ -1,7 +1,7 @@
import path from 'node:path'; import path from 'node:path';
import fs from 'node:fs'; import fs from 'node:fs';
export const HOME = 'daily-question'; export const HOME = 'hot-api';
export const ROOT_DIR = path.resolve(process.cwd(), 'storage', HOME); export const ROOT_DIR = path.resolve(process.cwd(), 'storage', HOME);

View File

@@ -1,15 +0,0 @@
// base
import { app } from '../app.ts';
const hasAuth = app.router.routes.some(r => r.id === 'auth');
if (!hasAuth) {
console.log('添加认证中间件路由');
app.route({
path: 'auth',
key: 'auth',
description: '用户认证',
id: 'auth'
}).define(async (ctx) => {
// 这里可以添加实际的认证逻辑
}).addTo(app);
}

62
src/test/test-h.ts Normal file
View File

@@ -0,0 +1,62 @@
import { keyboard, Key } from "@nut-tree/nut-js";
// 将快捷键字符串转换为 Key 枚举值
function parseHotkey(hotkey: string): Key[] {
const keyMap: Record<string, Key> = {
'ctrl': Key.LeftControl,
'leftctrl': Key.LeftControl,
'rightctrl': Key.RightControl,
'alt': Key.LeftAlt,
'leftalt': Key.LeftAlt,
'rightalt': Key.RightAlt,
'shift': Key.LeftShift,
'leftshift': Key.LeftShift,
'rightshift': Key.RightShift,
'meta': Key.LeftSuper,
'cmd': Key.LeftCmd,
'win': Key.LeftWin,
};
return hotkey
.toLowerCase()
.split('+')
.map(key => {
const trimmed = key.trim();
// 如果是修饰键,从映射表中获取
if (keyMap[trimmed]) {
return keyMap[trimmed];
}
// 如果是字母,转换为大写并查找对应的 Key
if (trimmed.length === 1 && /[a-z]/.test(trimmed)) {
const upperKey = trimmed.toUpperCase();
return Key[upperKey as keyof typeof Key] as Key;
}
// 其他情况直接查找
return Key[trimmed as keyof typeof Key] as Key;
})
.filter((key): key is Key => key !== undefined);
}
const hotkey = 'ctrl+h';
const keys = parseHotkey(hotkey);
console.log('准备模拟按下快捷键:', hotkey);
console.log('解析后的键:', keys);
// 同时按下所有键
keyboard.pressKey(...keys)
.then(() => {
console.log('快捷键已按下');
// 短暂延迟后释放
return new Promise(resolve => setTimeout(resolve, 100));
})
.then(() => {
// 释放所有键
return keyboard.releaseKey(...keys);
})
.then(() => {
console.log('快捷键已释放');
})
.catch((error) => {
console.error('模拟快捷键失败:', error);
});