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

Commit

Permalink
fix: some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed Aug 11, 2023
1 parent 60fa64f commit 41c8772
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 102 deletions.
23 changes: 10 additions & 13 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ let loader: MaaFrameworkLoader
let controller: MaaController
let resource: MaaResource
let instance: MaaInstance
let loaded = false
const instanceListener: ((msg: string, detail: unknown) => void)[] = []

sms.install()
Expand Down Expand Up @@ -75,6 +76,7 @@ async function main() {
res.send({
success: true
})
loaded = await prepareResource()
} else {
res.send({
success: false
Expand Down Expand Up @@ -120,6 +122,7 @@ async function main() {
})

let pending = false
let quit = false

const timer = setInterval(async () => {
if (controller) {
Expand All @@ -129,7 +132,10 @@ async function main() {
return
}
pending = true
if (await controller.screencap()) {
if (!quit && (await controller.screencap())) {
if (quit) {
return
}
console.log(`/api/controller ${id} get image`)
const buffer = controller.image()
pending = false
Expand All @@ -141,24 +147,14 @@ async function main() {
}
}, 1000)
ws.on('close', () => {
quit = true
console.log(`/api/controller ${id} closed`)
clearInterval(timer)
})
})

app.ws('/api/instance', async (ws, req) => {
if (!controller) {
ws.close()
return
}

const loaded = await prepareResource()
if (!loaded) {
ws.close()
return
}

if (!instance.inited()) {
if (!loaded || !instance.inited()) {
ws.close()
return
}
Expand Down Expand Up @@ -216,6 +212,7 @@ async function main() {

controller = ctrl
resource = new MaaResource(loader)
loaded = await prepareResource()
instance = new MaaInstance(loader, (msg, detail) => {
detail = JSON.parse(detail)
for (const cb of instanceListener) {
Expand Down
1 change: 0 additions & 1 deletion src/components/ConfigEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const config = useVModel(props, 'value', emits, {
const fw = wrapProp(config, 'maaframework')
const adb = wrapProp(fw, 'adb')
const address = wrapProp(fw, 'address')
console.log(adb)
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion src/components/atomic/RectEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function handleOverflow(s: string, i: number) {
.split(/[^\d]+/)
.filter(x => x)
.map(x => parseInt(x))
while (i < 3 && ns.length > 0) {
while (i < 4 && ns.length > 0) {
value.value[i] = ns.shift()!
i += 1
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/atomic/SwitchButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const value = useVModel(props, 'value', emits, {
})
const realValue = computed(() => {
return props.inverse ? props.value : !props.value
return props.inverse ? !props.value : props.value
})
</script>

Expand Down
16 changes: 14 additions & 2 deletions src/components/framework/MonitorView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { onMounted, onUnmounted, ref } from 'vue'
import * as api from '@/api'
defineProps<{
width: number
height: number
}>()
const imageData = ref<ArrayBuffer | null>(null)
const imageURL = ref<string | null>(null)
Expand Down Expand Up @@ -59,12 +64,19 @@ function handleClick(ev: MouseEvent) {
<template>
<div>
<img
id="monitor"
v-if="imageURL"
:width="width"
:height="height"
:src="imageURL"
width="1280"
height="720"
@click="handleClick"
/>
<span v-else> no data </span>
</div>
</template>

<style scoped>
#monitor {
max-width: inherit;
}
</style>
2 changes: 1 addition & 1 deletion src/components/task/ArrayNavigateEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const value = useVModel(props, 'value', emits, {
<template #edit="{ value, update }">
<SingleNavigateEdit
:value="value"
@value:update="update"
@update:value="update"
:readonly="readonly"
></SingleNavigateEdit>
</template>
Expand Down
133 changes: 69 additions & 64 deletions src/views/EvalView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { DispatcherStatus, type TaskRunInfo } from '@/types'
import ConfigEdit from '@/components/ConfigEdit.vue'
import ArrayEdit from '@/components/array/ArrayEdit.vue'
import ClearButton from '@/components/atomic/ClearButton.vue'
import MonitorView from '@/components/framework/MonitorView.vue'
import SingleNavigateEdit from '@/components/task/SingleNavigateEdit.vue'
import FormLayout from '@/layout/FormLayout.vue'
import MainLayout from '@/layout/MainLayout.vue'
Expand Down Expand Up @@ -113,69 +114,73 @@ async function tryStart() {
</NButton>
</template>

<NCard>
<div class="flex flex-col gap-2 items-start">
<ConfigEdit v-if="config" v-model:value="config"></ConfigEdit>
<FormLayout>
<ClearButton propkey="" :value="null"> 任务列表 </ClearButton>
<ArrayEdit
v-model:value="runInfo"
type="multi"
:nullable="true"
:def="() => ({ task: '', enable: true, status: 'skipped' })"
:is-t="v => !(v instanceof Array)"
>
<template #edit="{ value, update }">
<div class="flex gap-2 items-center">
<NCheckbox
:checked="value.enable"
@update:checked="
v => {
update({
...value,
enable: v
})
}
"
></NCheckbox>
<NButton :disabled="value.status === 'skipped'" text>
<!-- 'skipped' | 'pending' | 'running' | 'success' | 'error' -->
<template #icon>
<NIcon>
<PendingOutlined
v-if="
value.status === 'skipped' ||
value.status === 'pending'
"
></PendingOutlined>
<ChangeCircleOutlined
v-else-if="value.status === 'running'"
></ChangeCircleOutlined>
<CheckOutlined
v-else-if="value.status === 'success'"
></CheckOutlined>
<CloseOutlined
v-else-if="value.status === 'error'"
></CloseOutlined>
</NIcon>
</template>
</NButton>
<SingleNavigateEdit
:value="value.task"
@update:value="
v => {
update({
...value,
task: v
})
}
"
></SingleNavigateEdit>
</div>
</template>
</ArrayEdit>
</FormLayout>
</div>
</NCard>
<div class="flex gap-2">
<NCard>
<div class="flex flex-col gap-2 items-start">
<ConfigEdit v-if="config" v-model:value="config"></ConfigEdit>
<FormLayout>
<ClearButton propkey="" :value="null"> 任务列表 </ClearButton>
<ArrayEdit
v-model:value="runInfo"
type="multi"
:nullable="true"
:def="() => ({ task: '', enable: true, status: 'skipped' })"
:is-t="v => !(v instanceof Array)"
>
<template #edit="{ value, update }">
<div class="flex gap-2 items-center">
<NCheckbox
:checked="value.enable"
@update:checked="
v => {
update({
...value,
enable: v
})
}
"
></NCheckbox>
<NButton :disabled="value.status === 'skipped'" text>
<!-- 'skipped' | 'pending' | 'running' | 'success' | 'error' -->
<template #icon>
<NIcon>
<PendingOutlined
v-if="
value.status === 'skipped' ||
value.status === 'pending'
"
></PendingOutlined>
<ChangeCircleOutlined
v-else-if="value.status === 'running'"
></ChangeCircleOutlined>
<CheckOutlined
v-else-if="value.status === 'success'"
></CheckOutlined>
<CloseOutlined
v-else-if="value.status === 'error'"
></CloseOutlined>
</NIcon>
</template>
</NButton>
<SingleNavigateEdit
:value="value.task"
@update:value="
v => {
update({
...value,
task: v
})
}
"
></SingleNavigateEdit>
</div>
</template>
</ArrayEdit>
</FormLayout>
</div>
</NCard>

<MonitorView :width="640" :height="360"></MonitorView>
</div>
</MainLayout>
</template>
Loading

0 comments on commit 41c8772

Please sign in to comment.