Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
feat: almost support run task
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed Aug 10, 2023
1 parent 7b6efc3 commit 3e1d5a8
Show file tree
Hide file tree
Showing 11 changed files with 351 additions and 55 deletions.
2 changes: 1 addition & 1 deletion server/MaaJSLoader
84 changes: 78 additions & 6 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
<script setup lang="ts">
import { onMounted } from 'vue'
import { RouterView } from 'vue-router'
import { fs } from '@/filesystem'
import { loadFS } from '@/loader'
onMounted(async () => {
await loadFS()
window.onkeydown = ev => {
if (ev.ctrlKey && (ev.key === 'z' || ev.key === 'Z')) {
ev.stopPropagation()
ev.preventDefault()
if (ev.shiftKey) {
if (fs.history.canRedo.value) {
fs.history.redo()
}
} else {
if (fs.history.canUndo.value) {
fs.history.undo()
}
}
}
}
})
</script>

<template>
Expand Down
9 changes: 9 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ export async function controller() {
}
})
}

export async function instance() {
return new Promise<WebSocket>(resolve => {
const ws = new WebSocket('ws://' + window.location.host + '/api/instance')
ws.onopen = () => {
resolve(ws)
}
})
}
2 changes: 1 addition & 1 deletion src/components/atomic/ClearButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function clean() {
</script>

<template>
<NPopover trigger="hover">
<NPopover trigger="hover" :disabled="!propkey">
<template #trigger>
<NButton
secondary
Expand Down
2 changes: 1 addition & 1 deletion src/components/task/SingleNavigateEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const options = computed(() => {
</script>

<template>
<div class="flex gap-2">
<div class="flex gap-2 w-full">
<NButton
:disabled="!(value in taskIndex)"
@click="navigate(taskIndex[value])"
Expand Down
10 changes: 10 additions & 0 deletions src/layout/MainLayout.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<div class="flex flex-col gap-2 flex-1 min-h-0">
<div class="flex gap-2">
<slot name="action"></slot>
</div>
<div class="flex gap-2 flex-1 min-h-0">
<slot></slot>
</div>
</div>
</template>
5 changes: 5 additions & 0 deletions src/router/index.ts
Original file line number Diff line number Diff line change
@@ -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(),
Expand All @@ -12,6 +13,10 @@ const router = createRouter({
{
path: '/edit',
component: EditView
},
{
path: '/eval',
component: EvalView
}
]
})
Expand Down
15 changes: 15 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
83 changes: 37 additions & 46 deletions src/views/EditView.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import {
BuildOutlined,
FileDownloadOutlined,
FileUploadOutlined,
NavigateBeforeOutlined,
Expand All @@ -8,40 +9,32 @@ import {
UndoOutlined
} from '@vicons/material'
import { NButton, NCard, NIcon } from 'naive-ui'
import { onMounted, ref } from 'vue'
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { active, getTask, history, setTask } from '@/data'
import { type PathKey, fs } from '@/filesystem'
import { loadFS, saveFS } from '@/loader'
import TaskEdit from '@/components/TaskEdit.vue'
import TaskTree from '@/components/TaskTree.vue'
import MainLayout from '@/layout/MainLayout.vue'
const expands = ref<PathKey[]>(['/' as PathKey])
const router = useRouter()
onMounted(async () => {
await loadFS()
window.onkeydown = ev => {
if (ev.ctrlKey && (ev.key === 'z' || ev.key === 'Z')) {
ev.stopPropagation()
ev.preventDefault()
if (ev.shiftKey) {
if (fs.history.canRedo.value) {
fs.history.redo()
}
} else {
if (fs.history.canUndo.value) {
fs.history.undo()
}
}
}
}
})
const expands = ref<PathKey[]>(['/' as PathKey])
</script>

<template>
<div class="flex flex-col gap-2 flex-1 min-h-0">
<div class="flex gap-2">
<MainLayout>
<template #action>
<NButton @click="router.push('/eval')">
<template #icon>
<NIcon>
<BuildOutlined></BuildOutlined>
</NIcon>
</template>
</NButton>
<NButton :disabled="!fs.history.canUndo.value" @click="fs.history.undo">
<template #icon>
<NIcon>
Expand Down Expand Up @@ -90,28 +83,26 @@ onMounted(async () => {
</NIcon>
</template>
</NButton>
</div>
<div class="flex gap-2 flex-1 min-h-0">
<NCard
class="min-h-0"
style="max-width: 400px"
content-style="max-height: 100%; display: flex; flex-direction: column"
>
<TaskTree v-model:expand="expands"></TaskTree>
</NCard>
<NCard class="min-h-0" content-style="max-height: 100%">
<template v-if="active && getTask(active)">
<TaskEdit
:name="active"
:value="getTask(active)!"
@update:value="
task => {
setTask(active!, task)
}
"
></TaskEdit>
</template>
</NCard>
</div>
</div>
</template>
<NCard
class="min-h-0"
style="max-width: 400px"
content-style="max-height: 100%; display: flex; flex-direction: column"
>
<TaskTree v-model:expand="expands"></TaskTree>
</NCard>
<NCard class="min-h-0" content-style="max-height: 100%">
<template v-if="active && getTask(active)">
<TaskEdit
:name="active"
:value="getTask(active)!"
@update:value="
task => {
setTask(active!, task)
}
"
></TaskEdit>
</template>
</NCard>
</MainLayout>
</template>
Loading

0 comments on commit 3e1d5a8

Please sign in to comment.