Skip to content

Commit

Permalink
Merge pull request #205 from MaaAssistantArknights/koffi
Browse files Browse the repository at this point in the history
迁移 ffi-napi 至 koffi
  • Loading branch information
bakashigure authored Oct 27, 2023
2 parents 3f33b71 + 4e5203a commit ae062a4
Show file tree
Hide file tree
Showing 11 changed files with 295 additions and 378 deletions.
2 changes: 1 addition & 1 deletion forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
}
return true
},
// asar: true,
asar: true,
},
rebuildConfig: {
buildPath: __dirname,
Expand Down
24 changes: 13 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
"templateBy": "草鞋没号 <[email protected]>",
"license": "AGPL-3.0-or-later",
"scripts": {
"dev": "node scripts/watch.mjs",
"prebuild": "vue-tsc --project packages/renderer/tsconfig.json --noEmit && node --max-old-space-size=4096 scripts/build.mjs",
"debug": "npm run prebuild && vite ./packages/renderer",
"lint": "eslint --ext .js,.ts,.vue --fix packages/main packages/renderer",
"make": "electron-forge make",
"start": "electron-forge start",
"package": "electron-forge package",
"publish": "electron-forge publish",
"format": "npx prettier -w ."
"dev": "cross-env NODE_OPTIONS=--max-old-space-size=8192 node scripts/watch.mjs",
"prebuild": "cross-env NODE_OPTIONS=--max-old-space-size=8192 vue-tsc --project packages/renderer/tsconfig.json --noEmit && node scripts/build.mjs",
"debug": "cross-env NODE_OPTIONS=--max-old-space-size=8192 npm run prebuild && vite ./packages/renderer",
"lint": "cross-env NODE_OPTIONS=--max-old-space-size=8192 eslint --ext .js,.ts,.vue --fix packages/main packages/renderer",
"make": "cross-env NODE_OPTIONS=--max-old-space-size=8192 electron-forge make",
"start": "cross-env NODE_OPTIONS=--max-old-space-size=8192 electron-forge start",
"package": "cross-env NODE_OPTIONS=--max-old-space-size=8192 electron-forge package",
"publish": "cross-env NODE_OPTIONS=--max-old-space-size=8192 electron-forge publish",
"format": "cross-env NODE_OPTIONS=--max-old-space-size=8192 npx prettier -w ."
},
"engines": {
"node": ">=18.12.0"
Expand Down Expand Up @@ -49,10 +49,13 @@
"clipboard": "^2.0.11",
"color2k": "^2.0.2",
"cron-parser": "^4.8.1",
"cross-env": "^7.0.3",
"date-fns": "^2.30.0",
"electron": "^26.0.0",
"electron-devtools-installer": "^3.2.0",
"electron-rebuild": "^3.2.9",
"exponential-backoff": "^3.1.1",
"fs-extra": "^11.1.1",
"less": "^4.1.3",
"lodash": "^4.17.21",
"naive-ui": "^2.34.4",
Expand Down Expand Up @@ -86,15 +89,14 @@
"arknights"
],
"dependencies": {
"@tigerconnect/ffi-napi": "4.0.3-tc3",
"@tigerconnect/ref-napi": "4.0.0-tc8",
"axios": "^1.4.0",
"chalk": "4",
"crypto-js": "^4.1.1",
"electron-squirrel-startup": "^1.0.0",
"electron-store": "^8.1.0",
"execa": "^7.1.1",
"iconv-lite": "^0.6.3",
"koffi": "^2.6.3",
"ps-list": "^8.1.1",
"rotating-file-stream": "^3.1.0",
"semver": "^7.5.1",
Expand Down
50 changes: 50 additions & 0 deletions packages/main/coreLoader/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import koffi from 'koffi'

import './types'

const protos = {
AsstSetUserDir: 'AsstBool AsstSetUserDir(str path)',
AsstLoadResource: 'AsstBool AsstLoadResource(str path)',
AsstSetStaticOption: 'AsstBool AsstSetStaticOption(AsstStaticOptionKey key, str value)',

AsstCreate: 'AsstHandle AsstCreate()',
AsstCreateEx: 'AsstHandle AsstCreateEx(AsstApiCallback callback, intptr custom_arg)',
AsstDestroy: 'void AsstDestroy(AsstHandle handle)',

AsstSetInstanceOption:
'AsstBool AsstSetInstanceOption(AsstHandle handle, AsstInstanceOptionKey key, str value)',

// AsstConnect
AsstAppendTask: 'AsstTaskId AsstAppendTask(AsstHandle handle, str type, str params)',
AsstSetTaskParams: 'AsstBool AsstSetTaskParams(AsstHandle handle, AsstTaskId id, str params)',

AsstStart: 'AsstBool AsstStart(AsstHandle handle)',
AsstStop: 'AsstBool AsstStop(AsstHandle handle)',
AsstRunning: 'AsstBool AsstRunning(AsstHandle handle)',
AsstConnected: 'AsstBool AsstConnected(AsstHandle handle)',

AsstAsyncConnect:
'AsstAsyncCallId AsstAsyncConnect(AsstHandle handle, str adb_path, str address, str config, AsstBool block)',
AsstAsyncClick:
'AsstAsyncCallId AsstAsyncClick(AsstHandle handle, int32 x, int32 y, AsstBool block)',
AsstAsyncScreencap: 'AsstAsyncCallId AsstAsyncScreencap(AsstHandle handle, AsstBool block)',

AsstGetImage: 'AsstSize AsstGetImage(AsstHandle, _Out_ void* buff, AsstSize buff_size)',
AsstGetUUID: 'AsstSize AsstGetUUID(AsstHandle, _Out_ char* buff, AsstSize buff_size)',
AsstGetTasksList:
'AsstSize AsstGetTasksList(AsstHandle, _Out_ AsstTaskId* buff, AsstSize buff_size)',
AsstGetNullSize: 'AsstSize AsstGetNullSize()',

AsstGetVersion: 'str AsstGetVersion()',
AsstLog: 'void AsstLog(str level, str message)'
}

export type MaaCoreExports = Record<keyof typeof protos, koffi.KoffiFunction>

export function load(lib: koffi.IKoffiLib) {
const result: Record<string, koffi.KoffiFunction> = {}
for (const key in protos) {
result[key] = lib.func(protos[key as keyof typeof protos])
}
return result as MaaCoreExports
}
13 changes: 3 additions & 10 deletions packages/main/coreLoader/callback.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import logger from '@main/utils/logger'
import ffi from '@tigerconnect/ffi-napi'
import ref from '@tigerconnect/ref-napi'
import type { AsstMsg } from '@type/task/callback'
import type { AsstApiCallback } from './types'

const callbackHandle = ffi.Callback(
'void',
['int', 'string', ref.refType(ref.types.void)],
(code: AsstMsg, data: string, customArgs) => {
export const callbackHandle: AsstApiCallback = (code, data, customArgs) => {
logger.silly(code)
logger.silly(data)
globalThis.renderer.CoreLoader.callback({
code,
data: JSON.parse(data),
})
}
)

export default callbackHandle
}
Loading

0 comments on commit ae062a4

Please sign in to comment.