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

Commit

Permalink
feat: support custom action maay.yield
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed Nov 1, 2023
1 parent 8a32093 commit 9ffc23e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
node_modules
dist
assets
pkgs/loader

pnpm-lock.yaml

14 changes: 11 additions & 3 deletions app/main/src/components/maafw/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { FlatToStream, context, deinit, init, set_log_dir, set_save_draw } from '@maa/loader'
import {
FlatToStream,
context,
deinit,
init,
serverContext,
set_log_dir,
set_save_draw
} from '@maa/loader'
import { logger } from '@maa/logger'
import { shallowRef } from '@vue/reactivity'
import { ChildProcess, spawn } from 'child_process'
Expand Down Expand Up @@ -122,8 +130,8 @@ export class MaaFrameworkModule extends Module {
await set_log_dir(path.join(process.cwd(), 'debug'))
await set_save_draw(this.cfg.debug)
logger.info('maa configured')
const stream = FlatToStream(context, (id, msg, detail) => {
ipcMainSend('renderer.loader.callback', id, msg, detail)
const stream = FlatToStream(serverContext, (msg, id, ...args) => {
ipcMainSend('renderer.loader.callback', msg, id, ...args)
})
ipcMainHandle('main.loader.stream', async (_, cmd, args) => {
try {
Expand Down
8 changes: 8 additions & 0 deletions app/renderer/src/stores/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ async function run(
output: {
state: RunningState
current: number | null
log: (x: string) => void
}
) {
output.state = RunningState.Loading
Expand Down Expand Up @@ -270,6 +271,13 @@ 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
}
})

output.state = RunningState.Running

const globDiff = buildDiffConfig(
Expand Down
4 changes: 2 additions & 2 deletions app/renderer/src/utils/maa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function setupMaa() {
}
})
setContext(ctx)
window.ipcRenderer.on('renderer.loader.callback', (_, id, msg, detail) => {
recv(id, msg, detail)
window.ipcRenderer.on('renderer.loader.callback', (_, msg, id, ...args) => {
recv(msg, id, ...args)
})
}
5 changes: 4 additions & 1 deletion app/renderer/src/views/Instances/InstancesMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ async function run() {
curInstanceHandle.value,
reactive({
state: running,
current: null
current: null,
log: (x: string) => {
statusMessage.value.push(x)
}
})
)
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/ipc/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import type { SyncVarInterfaceList_M2R, SyncVarPullInterfaceList_R2M } from './s
export type ClientSideInterface = {
'renderer.core.log': (s: string) => void

'renderer.loader.callback': (id: string, msg: string, detail: string) => void
'renderer.loader.callback': (msg: string, id: string, ...args: any[]) => void
} & SyncVarInterfaceList_M2R &
SyncVarPullInterfaceList_R2M

0 comments on commit 9ffc23e

Please sign in to comment.