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

Commit

Permalink
fix: still fixing problem
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed Nov 6, 2023
1 parent b2ab32b commit 5062fef
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/renderer/src/components/Respack/ViewResource.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function testLoad() {
testLoading.value = true
testLoadMsg.value = []
const res = await Resource.init()
res.onCallback = (msg, detail) => {
res.onCallback = async (msg, detail) => {
testLoadMsg.value.push(translateCallback(msg, detail))
}
for (const p of resolvedPaths.value ?? []) {
Expand Down
3 changes: 2 additions & 1 deletion app/renderer/src/stores/controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
type AdbControllerConfig,
type Callback,
Controller,
type ControllerHandle,
type DeviceInfo
Expand All @@ -15,7 +16,7 @@ function reload_init() {
})
}

async function connect(cfg: DeviceInfo, cb: (msg: string, detail: string) => void) {
async function connect(cfg: DeviceInfo, cb: Callback) {
const { name, adb_path: path, adb_serial: serial, adb_type: type, adb_config: config } = cfg
const ctrl = await Controller.init_adb({
path,
Expand Down
51 changes: 37 additions & 14 deletions app/renderer/src/stores/instance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Controller, Instance, type InstanceHandle, Resource } from '@maa/loader'
import {
Controller,
CustomActionBase,
Instance,
type InstanceHandle,
type Rect,
Resource,
type SyncCtxHandle
} from '@maa/loader'
import type {
InstanceHandleInfo,
InstanceSaveInfo,
Expand Down Expand Up @@ -234,14 +242,34 @@ function init_from(handle: InstanceHandle) {
return Instance.init_from(handle, ii.cb, ii.ci)
}

async function run(
handle: InstanceHandle,
output: {
state: RunningState
current: number | null
log: (x: string) => void
type Output = {
state: RunningState
current: number | null
log: (x: string) => void
}

class MaayYieldAction extends CustomActionBase {
out: Output

constructor(out: Output) {
super()

this.out = out
}
) {

run(
ctx: SyncCtxHandle,
task: string,
param: string,
box: Rect,
detail: string
): boolean | Promise<boolean> {
this.out.log(`task ${task} yield ${param}`)
return true
}
}

async function run(handle: InstanceHandle, output: Output) {
output.state = RunningState.Loading
output.current = null

Expand Down Expand Up @@ -274,12 +302,7 @@ async function run(
await hinst.bind_resource(hres)
await hinst.bind_controller(hctrl)

hinst.register_custom_action('maay.yield', {
run(_1, task, param, box, detail) {
output.log(`task ${task} yield ${param}`)
return true
}
})
hinst.register_custom_action('maay.yield', new MaayYieldAction(output))

output.state = RunningState.Running

Expand Down
8 changes: 3 additions & 5 deletions app/renderer/src/views/Devices/DevicesMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ const loading = ref(false)
async function requestConnect() {
if (info.value) {
loading.value = true
await connect(info.value, processControllerCallback)
await connect(info.value, async (msg, detail) => {
loggerEl.value?.add(translateCallback(msg, detail))
})
loading.value = false
}
}
Expand All @@ -52,10 +54,6 @@ async function requestDisconnect() {
loading.value = false
}
}
function processControllerCallback(msg: string, detail: string) {
loggerEl.value?.add(translateCallback(msg, detail))
}
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/src/views/Instances/InstancesMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const entryOption = computed(() => {
: []
})
function processCallback(msg: string, detail: string) {
async function processCallback(msg: string, detail: string) {
loggerEl.value?.add(translateCallback(msg, detail))
}
Expand Down

0 comments on commit 5062fef

Please sign in to comment.