diff --git a/server/MaaJSLoader b/server/MaaJSLoader index ba3909d..3f60ed2 160000 --- a/server/MaaJSLoader +++ b/server/MaaJSLoader @@ -1 +1 @@ -Subproject commit ba3909d03946345c9b420431d960d39e62bd8faf +Subproject commit 3f60ed24a82349d3e95a1fef6d4ed012b3558cb7 diff --git a/server/src/index.ts b/server/src/index.ts index b1ac028..1f2f5a4 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -9,7 +9,12 @@ import os from 'os' import path from 'path' import sms from 'source-map-support' -import { MaaController, MaaFrameworkLoader, MaaResource } from '../MaaJSLoader' +import { + MaaController, + MaaFrameworkLoader, + MaaInstance, + MaaResource +} from '../MaaJSLoader' import { MaaAdbControllerTypeEnum } from '../MaaJSLoader/src/framework/types' interface Config { @@ -105,17 +110,84 @@ async function main() { }) }) + app.ws('/api/instance', async (ws, req) => { + if (!controller) { + ws.close() + return + } + + const resource = await prepareResource() + if (!resource) { + ws.close() + return + } + + const instance = new MaaInstance(loader, (msg, detail) => { + ws.send( + JSON.stringify({ + type: 'callback', + msg, + detail + }) + ) + }) + + instance.bindController(controller) + instance.bindResource(resource) + + if (!instance.inited()) { + ws.close() + resource.destroy() + return + } + + ws.on('close', () => { + // instance.destroy() + resource.destroy() + }) + + ws.send( + JSON.stringify({ + type: 'inited' + }) + ) + + ws.on('message', async data => { + const action = JSON.parse(data.toString('utf-8')) as { + action: 'start' + task: string[] + } + if (controller) { + switch (action.action) { + case 'start': { + for (const task of action.task) { + instance.post(task, {}, status => { + ws.send( + JSON.stringify({ + type: 'status', + task, + status + }) + ) + }) + } + } + } + } + }) + }) + app.listen(config.port, () => { console.log(`server started: http://localhost:${config.port}/`) }) - loader = new MaaFrameworkLoader() - loader.load(path.join(config.maaframework.root, 'bin')) + if (config.maaframework.emulator) { + loader = new MaaFrameworkLoader() + loader.load(path.join(config.maaframework.root, 'bin')) - loader.setLogging(config.maaframework.log) - loader.setDebugMode(config.maaframework.debug) + loader.setLogging(config.maaframework.log) + loader.setDebugMode(config.maaframework.debug) - if (config.maaframework.emulator) { const ctrl = await prepareController() if (ctrl) { controller = ctrl diff --git a/src/App.vue b/src/App.vue index a740571..3ecd6fc 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,5 +1,28 @@ diff --git a/src/api.ts b/src/api.ts index d927eda..c1664f4 100644 --- a/src/api.ts +++ b/src/api.ts @@ -26,3 +26,12 @@ export async function controller() { } }) } + +export async function instance() { + return new Promise(resolve => { + const ws = new WebSocket('ws://' + window.location.host + '/api/instance') + ws.onopen = () => { + resolve(ws) + } + }) +} diff --git a/src/components/atomic/ClearButton.vue b/src/components/atomic/ClearButton.vue index 884c80c..ed4b3ed 100644 --- a/src/components/atomic/ClearButton.vue +++ b/src/components/atomic/ClearButton.vue @@ -30,7 +30,7 @@ function clean() { - + { - + + + + + + + + + + diff --git a/src/router/index.ts b/src/router/index.ts index a7d58ba..74ec3b3 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,6 +1,7 @@ import { createRouter, createWebHistory } from 'vue-router' import EditView from '@/views/EditView.vue' +import EvalView from '@/views/EvalView.vue' const router = createRouter({ history: createWebHistory(), @@ -12,6 +13,10 @@ const router = createRouter({ { path: '/edit', component: EditView + }, + { + path: '/eval', + component: EvalView } ] }) diff --git a/src/types.ts b/src/types.ts index 9d451aa..964c1d7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -156,3 +156,18 @@ export type Task = Recognition & export interface TaskData { [task: string]: Task } + +export interface TaskRunInfo { + task: string + enable: boolean + status: 'skipped' | 'pending' | 'running' | 'success' | 'error' +} + +export const enum DispatcherStatus { + Invalid, + Pending, + Started, + Completed, + Failed, + Stopped +} diff --git a/src/views/EditView.vue b/src/views/EditView.vue index 4314796..a6cc212 100644 --- a/src/views/EditView.vue +++ b/src/views/EditView.vue @@ -1,5 +1,6 @@ - - + + + + + + + + + @@ -90,28 +83,26 @@ onMounted(async () => { - - - - - - - - { - setTask(active!, task) - } - " - > - - - - + + + + + + + { + setTask(active!, task) + } + " + > + + + diff --git a/src/views/EvalView.vue b/src/views/EvalView.vue new file mode 100644 index 0000000..97b5d67 --- /dev/null +++ b/src/views/EvalView.vue @@ -0,0 +1,171 @@ + + + + + + + + + + + + + + + + + + + + + + + + + 任务列表 + + + + { + update({ + ...value, + enable: v + }) + } + " + > + + + + + + + + + + + + { + update({ + ...value, + task: v + }) + } + " + > + + + + + + + +