@maaxyz/maa-node 4.4.0-alpha.4 → 4.4.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/controller.d.ts +7 -18
- package/dist/index-client.js +48 -9
- package/dist/index-server.js +48 -9
- package/dist/resource.d.ts +6 -7
- package/dist/tasker.d.ts +12 -10
- package/dist/types.d.ts +1 -0
- package/dist/utils.d.ts +5 -0
- package/package.json +7 -7
- package/src/controller.ts +27 -35
- package/src/resource.ts +16 -12
- package/src/tasker.ts +20 -15
- package/src/types.ts +2 -0
- package/src/utils.ts +40 -0
package/dist/controller.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Job, JobSource } from './job';
|
|
2
2
|
import maa, { ImageData } from './maa';
|
|
3
|
+
import { ChainNotifyType } from './types';
|
|
4
|
+
import { chain_notify_impl } from './utils';
|
|
3
5
|
declare class ImageJob extends Job<maa.CtrlId, JobSource<maa.CtrlId>> {
|
|
4
6
|
#private;
|
|
5
7
|
constructor(ctrl: ControllerBase, source: JobSource<maa.CtrlId>, id: maa.CtrlId);
|
|
@@ -13,23 +15,9 @@ declare class ImageJob extends Job<maa.CtrlId, JobSource<maa.CtrlId>> {
|
|
|
13
15
|
get: () => Promise<ArrayBuffer | null>;
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
|
-
export type ControllerNotify =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} & ({
|
|
20
|
-
msg: 'UUIDGot';
|
|
21
|
-
uuid: string;
|
|
22
|
-
} | {
|
|
23
|
-
msg: 'UUIDGetFailed';
|
|
24
|
-
} | {
|
|
25
|
-
msg: 'ConnectSuccess';
|
|
26
|
-
} | {
|
|
27
|
-
msg: 'ConnectFailed';
|
|
28
|
-
why: 'ConnectFailed' | 'UUIDGetFailed';
|
|
29
|
-
} | {
|
|
30
|
-
msg: 'ScreencapInited' | 'ScreencapInitFailed' | 'TouchinputInited' | 'TouchinputInitFailed';
|
|
31
|
-
})) | {
|
|
32
|
-
msg: 'Action.Started' | 'Action.Completed' | 'Action.Failed';
|
|
18
|
+
export type ControllerNotify = {
|
|
19
|
+
msg: 'Action.Starting' | 'Action.Succeeded' | 'Action.Failed';
|
|
20
|
+
action: 'connect' | 'click' | 'swipe' | 'touch_down' | 'touch_move' | 'touch_up' | 'press_key' | 'input_text' | 'screencap' | 'start_app' | 'stop_app';
|
|
33
21
|
ctrl_id: maa.CtrlId;
|
|
34
22
|
uuid: string;
|
|
35
23
|
};
|
|
@@ -37,7 +25,8 @@ export declare class ControllerBase {
|
|
|
37
25
|
#private;
|
|
38
26
|
handle: maa.ControllerHandle;
|
|
39
27
|
notify(message: string, details_json: string): maa.MaybePromise<void>;
|
|
40
|
-
|
|
28
|
+
chain_notify: typeof chain_notify_impl;
|
|
29
|
+
chain_parsed_notify(cb: (msg: ControllerNotify) => maa.MaybePromise<void>, order?: ChainNotifyType): void;
|
|
41
30
|
constructor(handle: maa.ControllerHandle);
|
|
42
31
|
destroy(): void;
|
|
43
32
|
set screenshot_target_long_side(value: number);
|
package/dist/index-client.js
CHANGED
|
@@ -150,6 +150,42 @@ var Job = class {
|
|
|
150
150
|
|
|
151
151
|
// src/controller.ts
|
|
152
152
|
var import_maa = __toESM(require_maa());
|
|
153
|
+
|
|
154
|
+
// src/utils.ts
|
|
155
|
+
function chain_notify_impl(cb, order = "after") {
|
|
156
|
+
const old = this.notify;
|
|
157
|
+
switch (order) {
|
|
158
|
+
case "before":
|
|
159
|
+
this.notify = async (msg, details) => {
|
|
160
|
+
await cb(msg, details);
|
|
161
|
+
await old.call(this, msg, details);
|
|
162
|
+
};
|
|
163
|
+
break;
|
|
164
|
+
case "after":
|
|
165
|
+
this.notify = async (msg, details) => {
|
|
166
|
+
await old.call(this, msg, details);
|
|
167
|
+
await cb(msg, details);
|
|
168
|
+
};
|
|
169
|
+
break;
|
|
170
|
+
case "before-no-wait":
|
|
171
|
+
this.notify = async (msg, details) => {
|
|
172
|
+
cb(msg, details);
|
|
173
|
+
await old.call(this, msg, details);
|
|
174
|
+
};
|
|
175
|
+
break;
|
|
176
|
+
case "after-no-wait":
|
|
177
|
+
this.notify = async (msg, details) => {
|
|
178
|
+
await old.call(this, msg, details);
|
|
179
|
+
cb(msg, details);
|
|
180
|
+
};
|
|
181
|
+
break;
|
|
182
|
+
case "replace":
|
|
183
|
+
this.notify = cb;
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// src/controller.ts
|
|
153
189
|
var ImageJob = class extends Job {
|
|
154
190
|
#ctrl;
|
|
155
191
|
constructor(ctrl, source, id) {
|
|
@@ -181,13 +217,14 @@ var ControllerBase = class {
|
|
|
181
217
|
#source;
|
|
182
218
|
notify(message, details_json) {
|
|
183
219
|
}
|
|
184
|
-
|
|
185
|
-
|
|
220
|
+
chain_notify = chain_notify_impl;
|
|
221
|
+
chain_parsed_notify(cb, order = "after") {
|
|
222
|
+
this.chain_notify((msg, details) => {
|
|
186
223
|
return cb({
|
|
187
224
|
msg: msg.replace(/^Controller\./, ""),
|
|
188
225
|
...JSON.parse(details)
|
|
189
226
|
});
|
|
190
|
-
};
|
|
227
|
+
}, order);
|
|
191
228
|
}
|
|
192
229
|
constructor(handle) {
|
|
193
230
|
this.handle = handle;
|
|
@@ -433,13 +470,14 @@ var TaskerBase = class {
|
|
|
433
470
|
#source;
|
|
434
471
|
notify(message, details_json) {
|
|
435
472
|
}
|
|
436
|
-
|
|
437
|
-
|
|
473
|
+
chain_notify = chain_notify_impl;
|
|
474
|
+
chain_parsed_notify(cb, order = "after") {
|
|
475
|
+
this.chain_notify((msg, details) => {
|
|
438
476
|
return cb({
|
|
439
477
|
msg: msg.replace(/^(?:Tasker|Node)?\./, ""),
|
|
440
478
|
...JSON.parse(details)
|
|
441
479
|
});
|
|
442
|
-
};
|
|
480
|
+
}, order);
|
|
443
481
|
}
|
|
444
482
|
constructor(handle) {
|
|
445
483
|
this.handle = handle;
|
|
@@ -636,13 +674,14 @@ var ResourceBase = class {
|
|
|
636
674
|
#source;
|
|
637
675
|
notify(message, details_json) {
|
|
638
676
|
}
|
|
639
|
-
|
|
640
|
-
|
|
677
|
+
chain_notify = chain_notify_impl;
|
|
678
|
+
chain_parsed_notify(cb, order = "after") {
|
|
679
|
+
this.chain_notify((msg, details) => {
|
|
641
680
|
return cb({
|
|
642
681
|
msg: msg.replace(/^Resource\./, ""),
|
|
643
682
|
...JSON.parse(details)
|
|
644
683
|
});
|
|
645
|
-
};
|
|
684
|
+
}, order);
|
|
646
685
|
}
|
|
647
686
|
constructor(handle) {
|
|
648
687
|
this.handle = handle;
|
package/dist/index-server.js
CHANGED
|
@@ -150,6 +150,42 @@ var Job = class {
|
|
|
150
150
|
|
|
151
151
|
// src/controller.ts
|
|
152
152
|
var import_maa = __toESM(require_maa());
|
|
153
|
+
|
|
154
|
+
// src/utils.ts
|
|
155
|
+
function chain_notify_impl(cb, order = "after") {
|
|
156
|
+
const old = this.notify;
|
|
157
|
+
switch (order) {
|
|
158
|
+
case "before":
|
|
159
|
+
this.notify = async (msg, details) => {
|
|
160
|
+
await cb(msg, details);
|
|
161
|
+
await old.call(this, msg, details);
|
|
162
|
+
};
|
|
163
|
+
break;
|
|
164
|
+
case "after":
|
|
165
|
+
this.notify = async (msg, details) => {
|
|
166
|
+
await old.call(this, msg, details);
|
|
167
|
+
await cb(msg, details);
|
|
168
|
+
};
|
|
169
|
+
break;
|
|
170
|
+
case "before-no-wait":
|
|
171
|
+
this.notify = async (msg, details) => {
|
|
172
|
+
cb(msg, details);
|
|
173
|
+
await old.call(this, msg, details);
|
|
174
|
+
};
|
|
175
|
+
break;
|
|
176
|
+
case "after-no-wait":
|
|
177
|
+
this.notify = async (msg, details) => {
|
|
178
|
+
await old.call(this, msg, details);
|
|
179
|
+
cb(msg, details);
|
|
180
|
+
};
|
|
181
|
+
break;
|
|
182
|
+
case "replace":
|
|
183
|
+
this.notify = cb;
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// src/controller.ts
|
|
153
189
|
var ImageJob = class extends Job {
|
|
154
190
|
#ctrl;
|
|
155
191
|
constructor(ctrl, source, id) {
|
|
@@ -181,13 +217,14 @@ var ControllerBase = class {
|
|
|
181
217
|
#source;
|
|
182
218
|
notify(message, details_json) {
|
|
183
219
|
}
|
|
184
|
-
|
|
185
|
-
|
|
220
|
+
chain_notify = chain_notify_impl;
|
|
221
|
+
chain_parsed_notify(cb, order = "after") {
|
|
222
|
+
this.chain_notify((msg, details) => {
|
|
186
223
|
return cb({
|
|
187
224
|
msg: msg.replace(/^Controller\./, ""),
|
|
188
225
|
...JSON.parse(details)
|
|
189
226
|
});
|
|
190
|
-
};
|
|
227
|
+
}, order);
|
|
191
228
|
}
|
|
192
229
|
constructor(handle) {
|
|
193
230
|
this.handle = handle;
|
|
@@ -433,13 +470,14 @@ var TaskerBase = class {
|
|
|
433
470
|
#source;
|
|
434
471
|
notify(message, details_json) {
|
|
435
472
|
}
|
|
436
|
-
|
|
437
|
-
|
|
473
|
+
chain_notify = chain_notify_impl;
|
|
474
|
+
chain_parsed_notify(cb, order = "after") {
|
|
475
|
+
this.chain_notify((msg, details) => {
|
|
438
476
|
return cb({
|
|
439
477
|
msg: msg.replace(/^(?:Tasker|Node)?\./, ""),
|
|
440
478
|
...JSON.parse(details)
|
|
441
479
|
});
|
|
442
|
-
};
|
|
480
|
+
}, order);
|
|
443
481
|
}
|
|
444
482
|
constructor(handle) {
|
|
445
483
|
this.handle = handle;
|
|
@@ -636,13 +674,14 @@ var ResourceBase = class {
|
|
|
636
674
|
#source;
|
|
637
675
|
notify(message, details_json) {
|
|
638
676
|
}
|
|
639
|
-
|
|
640
|
-
|
|
677
|
+
chain_notify = chain_notify_impl;
|
|
678
|
+
chain_parsed_notify(cb, order = "after") {
|
|
679
|
+
this.chain_notify((msg, details) => {
|
|
641
680
|
return cb({
|
|
642
681
|
msg: msg.replace(/^Resource\./, ""),
|
|
643
682
|
...JSON.parse(details)
|
|
644
683
|
});
|
|
645
|
-
};
|
|
684
|
+
}, order);
|
|
646
685
|
}
|
|
647
686
|
constructor(handle) {
|
|
648
687
|
this.handle = handle;
|
package/dist/resource.d.ts
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { Job, JobSource } from './job';
|
|
2
2
|
import maa from './maa';
|
|
3
3
|
import { DumpTask } from './pipeline';
|
|
4
|
-
import { CustomActionCallback, CustomRecognizerCallback } from './types';
|
|
4
|
+
import { ChainNotifyType, CustomActionCallback, CustomRecognizerCallback } from './types';
|
|
5
|
+
import { chain_notify_impl } from './utils';
|
|
5
6
|
export type ResourceNotify = {
|
|
7
|
+
msg: 'Loading.Starting' | 'Loading.Succeeded' | 'Loading.Failed';
|
|
6
8
|
res_id: maa.ResId;
|
|
7
9
|
path: string;
|
|
8
|
-
} & ({
|
|
9
|
-
msg: 'StartLoading';
|
|
10
|
-
} | {
|
|
11
|
-
msg: 'LoadingCompleted' | 'LoadingFailed';
|
|
12
10
|
hash: string;
|
|
13
|
-
}
|
|
11
|
+
};
|
|
14
12
|
export declare class ResourceBase {
|
|
15
13
|
#private;
|
|
16
14
|
handle: maa.ResourceHandle;
|
|
17
15
|
notify(message: string, details_json: string): maa.MaybePromise<void>;
|
|
18
|
-
|
|
16
|
+
chain_notify: typeof chain_notify_impl;
|
|
17
|
+
chain_parsed_notify(cb: (msg: ResourceNotify) => maa.MaybePromise<void>, order?: ChainNotifyType): void;
|
|
19
18
|
constructor(handle: maa.ResourceHandle);
|
|
20
19
|
destroy(): void;
|
|
21
20
|
set inference_device(id: keyof typeof maa.InferenceDevice | number);
|
package/dist/tasker.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { ControllerBase } from './controller';
|
|
|
2
2
|
import { Job, JobSource } from './job';
|
|
3
3
|
import maa from './maa';
|
|
4
4
|
import { ResourceBase } from './resource';
|
|
5
|
+
import { ChainNotifyType } from './types';
|
|
6
|
+
import { chain_notify_impl } from './utils';
|
|
5
7
|
type TaskDetail = ReturnType<TaskerBase['task_detail']>;
|
|
6
8
|
type RecoDetailEntry = {
|
|
7
9
|
box: maa.FlatRect;
|
|
@@ -47,36 +49,36 @@ declare class TaskJob extends Job<maa.TaskId, JobSource<maa.TaskId>> {
|
|
|
47
49
|
};
|
|
48
50
|
}
|
|
49
51
|
export type TaskerNotify = {
|
|
52
|
+
msg: 'Task.Started' | 'Task.Completed' | 'Task.Failed';
|
|
50
53
|
task_id: maa.TaskId;
|
|
51
54
|
entry: string;
|
|
52
|
-
hash: string;
|
|
53
55
|
uuid: string;
|
|
54
|
-
|
|
55
|
-
msg: 'Task.Started' | 'Task.Completed' | 'Task.Failed';
|
|
56
|
+
hash: string;
|
|
56
57
|
} | {
|
|
57
58
|
msg: 'NextList.Starting' | 'NextList.Succeeded' | 'NextList.Failed';
|
|
58
|
-
task_id:
|
|
59
|
+
task_id: maa.TaskId;
|
|
59
60
|
name: string;
|
|
60
61
|
list: string[];
|
|
61
62
|
focus: unknown;
|
|
62
63
|
} | {
|
|
63
64
|
msg: 'Recognition.Starting' | 'Recognition.Succeeded' | 'Recognition.Failed';
|
|
64
|
-
task_id:
|
|
65
|
-
reco_id:
|
|
65
|
+
task_id: maa.TaskId;
|
|
66
|
+
reco_id: maa.RecoId;
|
|
66
67
|
name: string;
|
|
67
68
|
focus: unknown;
|
|
68
69
|
} | {
|
|
69
70
|
msg: 'Action.Starting' | 'Action.Succeeded' | 'Action.Failed';
|
|
70
|
-
task_id:
|
|
71
|
-
node_id:
|
|
71
|
+
task_id: maa.TaskId;
|
|
72
|
+
node_id: maa.NodeId;
|
|
72
73
|
name: string;
|
|
73
74
|
focus: unknown;
|
|
74
|
-
}
|
|
75
|
+
};
|
|
75
76
|
export declare class TaskerBase {
|
|
76
77
|
#private;
|
|
77
78
|
handle: maa.TaskerHandle;
|
|
78
79
|
notify(message: string, details_json: string): maa.MaybePromise<void>;
|
|
79
|
-
|
|
80
|
+
chain_notify: typeof chain_notify_impl;
|
|
81
|
+
chain_parsed_notify(cb: (msg: TaskerNotify) => maa.MaybePromise<void>, order?: ChainNotifyType): void;
|
|
80
82
|
constructor(handle: maa.TaskerHandle);
|
|
81
83
|
destroy(): void;
|
|
82
84
|
bind(slave: ControllerBase | ResourceBase): void;
|
package/dist/types.d.ts
CHANGED
|
@@ -24,4 +24,5 @@ export type CustomRecognizerCallback = CustomCallback<CustomRecognizerSelf, [
|
|
|
24
24
|
out_detail: string
|
|
25
25
|
] | null>;
|
|
26
26
|
export type CustomActionCallback = CustomCallback<CustomActionSelf, boolean>;
|
|
27
|
+
export type ChainNotifyType = 'before' | 'after' | 'before-no-wait' | 'after-no-wait' | 'replace';
|
|
27
28
|
export {};
|
package/dist/utils.d.ts
ADDED
package/package.json
CHANGED
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
"prettier": "^3.5.2",
|
|
26
26
|
"typescript": "^5.8.2"
|
|
27
27
|
},
|
|
28
|
-
"version": "4.4.0-
|
|
28
|
+
"version": "4.4.0-beta.2",
|
|
29
29
|
"optionalDependencies": {
|
|
30
|
-
"@maaxyz/maa-node-darwin-arm64": "4.4.0-
|
|
31
|
-
"@maaxyz/maa-node-darwin-x64": "4.4.0-
|
|
32
|
-
"@maaxyz/maa-node-linux-arm64": "4.4.0-
|
|
33
|
-
"@maaxyz/maa-node-linux-x64": "4.4.0-
|
|
34
|
-
"@maaxyz/maa-node-win32-arm64": "4.4.0-
|
|
35
|
-
"@maaxyz/maa-node-win32-x64": "4.4.0-
|
|
30
|
+
"@maaxyz/maa-node-darwin-arm64": "4.4.0-beta.2",
|
|
31
|
+
"@maaxyz/maa-node-darwin-x64": "4.4.0-beta.2",
|
|
32
|
+
"@maaxyz/maa-node-linux-arm64": "4.4.0-beta.2",
|
|
33
|
+
"@maaxyz/maa-node-linux-x64": "4.4.0-beta.2",
|
|
34
|
+
"@maaxyz/maa-node-win32-arm64": "4.4.0-beta.2",
|
|
35
|
+
"@maaxyz/maa-node-win32-x64": "4.4.0-beta.2"
|
|
36
36
|
}
|
|
37
37
|
}
|
package/src/controller.ts
CHANGED
|
@@ -2,6 +2,8 @@ import path from 'path'
|
|
|
2
2
|
|
|
3
3
|
import { Job, JobSource } from './job'
|
|
4
4
|
import maa, { ImageData } from './maa'
|
|
5
|
+
import { ChainNotifyType } from './types'
|
|
6
|
+
import { chain_notify_impl } from './utils'
|
|
5
7
|
|
|
6
8
|
class ImageJob extends Job<maa.CtrlId, JobSource<maa.CtrlId>> {
|
|
7
9
|
#ctrl: ControllerBase
|
|
@@ -36,38 +38,23 @@ class ImageJob extends Job<maa.CtrlId, JobSource<maa.CtrlId>> {
|
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
export type ControllerNotify =
|
|
40
|
-
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
why: 'ConnectFailed' | 'UUIDGetFailed'
|
|
57
|
-
}
|
|
58
|
-
| {
|
|
59
|
-
msg:
|
|
60
|
-
| 'ScreencapInited'
|
|
61
|
-
| 'ScreencapInitFailed'
|
|
62
|
-
| 'TouchinputInited'
|
|
63
|
-
| 'TouchinputInitFailed'
|
|
64
|
-
}
|
|
65
|
-
))
|
|
66
|
-
| {
|
|
67
|
-
msg: 'Action.Started' | 'Action.Completed' | 'Action.Failed'
|
|
68
|
-
ctrl_id: maa.CtrlId
|
|
69
|
-
uuid: string
|
|
70
|
-
}
|
|
41
|
+
export type ControllerNotify = {
|
|
42
|
+
msg: 'Action.Starting' | 'Action.Succeeded' | 'Action.Failed'
|
|
43
|
+
action:
|
|
44
|
+
| 'connect'
|
|
45
|
+
| 'click'
|
|
46
|
+
| 'swipe'
|
|
47
|
+
| 'touch_down'
|
|
48
|
+
| 'touch_move'
|
|
49
|
+
| 'touch_up'
|
|
50
|
+
| 'press_key'
|
|
51
|
+
| 'input_text'
|
|
52
|
+
| 'screencap'
|
|
53
|
+
| 'start_app'
|
|
54
|
+
| 'stop_app'
|
|
55
|
+
ctrl_id: maa.CtrlId
|
|
56
|
+
uuid: string
|
|
57
|
+
}
|
|
71
58
|
|
|
72
59
|
export class ControllerBase {
|
|
73
60
|
handle: maa.ControllerHandle
|
|
@@ -75,13 +62,18 @@ export class ControllerBase {
|
|
|
75
62
|
|
|
76
63
|
notify(message: string, details_json: string): maa.MaybePromise<void> {}
|
|
77
64
|
|
|
78
|
-
|
|
79
|
-
|
|
65
|
+
chain_notify = chain_notify_impl
|
|
66
|
+
|
|
67
|
+
chain_parsed_notify(
|
|
68
|
+
cb: (msg: ControllerNotify) => maa.MaybePromise<void>,
|
|
69
|
+
order: ChainNotifyType = 'after'
|
|
70
|
+
) {
|
|
71
|
+
this.chain_notify((msg: string, details: string) => {
|
|
80
72
|
return cb({
|
|
81
73
|
msg: msg.replace(/^Controller\./, '') as any,
|
|
82
74
|
...JSON.parse(details)
|
|
83
75
|
})
|
|
84
|
-
}
|
|
76
|
+
}, order)
|
|
85
77
|
}
|
|
86
78
|
|
|
87
79
|
constructor(handle: maa.ControllerHandle) {
|
package/src/resource.ts
CHANGED
|
@@ -3,21 +3,20 @@ import { Job, JobSource } from './job'
|
|
|
3
3
|
import maa from './maa'
|
|
4
4
|
import { DumpTask } from './pipeline'
|
|
5
5
|
import {
|
|
6
|
+
ChainNotifyType,
|
|
6
7
|
CustomActionCallback,
|
|
7
8
|
CustomActionSelf,
|
|
8
9
|
CustomRecognizerCallback,
|
|
9
10
|
CustomRecognizerSelf
|
|
10
11
|
} from './types'
|
|
12
|
+
import { chain_notify_impl } from './utils'
|
|
11
13
|
|
|
12
|
-
export type ResourceNotify = {
|
|
13
|
-
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
hash: string
|
|
19
|
-
}
|
|
20
|
-
)
|
|
14
|
+
export type ResourceNotify = {
|
|
15
|
+
msg: 'Loading.Starting' | 'Loading.Succeeded' | 'Loading.Failed'
|
|
16
|
+
res_id: maa.ResId
|
|
17
|
+
path: string
|
|
18
|
+
hash: string
|
|
19
|
+
}
|
|
21
20
|
|
|
22
21
|
export class ResourceBase {
|
|
23
22
|
handle: maa.ResourceHandle
|
|
@@ -25,13 +24,18 @@ export class ResourceBase {
|
|
|
25
24
|
|
|
26
25
|
notify(message: string, details_json: string): maa.MaybePromise<void> {}
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
chain_notify = chain_notify_impl
|
|
28
|
+
|
|
29
|
+
chain_parsed_notify(
|
|
30
|
+
cb: (msg: ResourceNotify) => maa.MaybePromise<void>,
|
|
31
|
+
order: ChainNotifyType = 'after'
|
|
32
|
+
) {
|
|
33
|
+
this.chain_notify((msg: string, details: string) => {
|
|
30
34
|
return cb({
|
|
31
35
|
msg: msg.replace(/^Resource\./, '') as any,
|
|
32
36
|
...JSON.parse(details)
|
|
33
37
|
})
|
|
34
|
-
}
|
|
38
|
+
}, order)
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
constructor(handle: maa.ResourceHandle) {
|
package/src/tasker.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { ControllerBase } from './controller'
|
|
|
2
2
|
import { Job, JobSource } from './job'
|
|
3
3
|
import maa from './maa'
|
|
4
4
|
import { ResourceBase } from './resource'
|
|
5
|
+
import { ChainNotifyType } from './types'
|
|
6
|
+
import { chain_notify_impl } from './utils'
|
|
5
7
|
|
|
6
8
|
type TaskDetail = ReturnType<TaskerBase['task_detail']>
|
|
7
9
|
|
|
@@ -54,37 +56,35 @@ class TaskJob extends Job<maa.TaskId, JobSource<maa.TaskId>> {
|
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
export type TaskerNotify =
|
|
58
|
-
task_id: maa.TaskId
|
|
59
|
-
entry: string
|
|
60
|
-
hash: string
|
|
61
|
-
uuid: string
|
|
62
|
-
} & (
|
|
59
|
+
export type TaskerNotify =
|
|
63
60
|
| {
|
|
64
61
|
msg: 'Task.Started' | 'Task.Completed' | 'Task.Failed'
|
|
62
|
+
task_id: maa.TaskId
|
|
63
|
+
entry: string
|
|
64
|
+
uuid: string
|
|
65
|
+
hash: string
|
|
65
66
|
}
|
|
66
67
|
| {
|
|
67
68
|
msg: 'NextList.Starting' | 'NextList.Succeeded' | 'NextList.Failed'
|
|
68
|
-
task_id:
|
|
69
|
+
task_id: maa.TaskId
|
|
69
70
|
name: string
|
|
70
71
|
list: string[]
|
|
71
72
|
focus: unknown
|
|
72
73
|
}
|
|
73
74
|
| {
|
|
74
75
|
msg: 'Recognition.Starting' | 'Recognition.Succeeded' | 'Recognition.Failed'
|
|
75
|
-
task_id:
|
|
76
|
-
reco_id:
|
|
76
|
+
task_id: maa.TaskId
|
|
77
|
+
reco_id: maa.RecoId
|
|
77
78
|
name: string
|
|
78
79
|
focus: unknown
|
|
79
80
|
}
|
|
80
81
|
| {
|
|
81
82
|
msg: 'Action.Starting' | 'Action.Succeeded' | 'Action.Failed'
|
|
82
|
-
task_id:
|
|
83
|
-
node_id:
|
|
83
|
+
task_id: maa.TaskId
|
|
84
|
+
node_id: maa.NodeId
|
|
84
85
|
name: string
|
|
85
86
|
focus: unknown
|
|
86
87
|
}
|
|
87
|
-
)
|
|
88
88
|
|
|
89
89
|
export class TaskerBase {
|
|
90
90
|
handle: maa.TaskerHandle
|
|
@@ -92,13 +92,18 @@ export class TaskerBase {
|
|
|
92
92
|
|
|
93
93
|
notify(message: string, details_json: string): maa.MaybePromise<void> {}
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
chain_notify = chain_notify_impl
|
|
96
|
+
|
|
97
|
+
chain_parsed_notify(
|
|
98
|
+
cb: (msg: TaskerNotify) => maa.MaybePromise<void>,
|
|
99
|
+
order: ChainNotifyType = 'after'
|
|
100
|
+
) {
|
|
101
|
+
this.chain_notify((msg: string, details: string) => {
|
|
97
102
|
return cb({
|
|
98
103
|
msg: msg.replace(/^(?:Tasker|Node)?\./, '') as any,
|
|
99
104
|
...JSON.parse(details)
|
|
100
105
|
})
|
|
101
|
-
}
|
|
106
|
+
}, order)
|
|
102
107
|
}
|
|
103
108
|
|
|
104
109
|
constructor(handle: maa.TaskerHandle) {
|
package/src/types.ts
CHANGED
package/src/utils.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import maa from './maa'
|
|
2
|
+
import { ChainNotifyType } from './types'
|
|
3
|
+
|
|
4
|
+
export function chain_notify_impl(
|
|
5
|
+
this: { notify: maa.NotificationCallback },
|
|
6
|
+
cb: maa.NotificationCallback,
|
|
7
|
+
order: ChainNotifyType = 'after'
|
|
8
|
+
) {
|
|
9
|
+
const old = this.notify
|
|
10
|
+
|
|
11
|
+
switch (order) {
|
|
12
|
+
case 'before':
|
|
13
|
+
this.notify = async (msg, details) => {
|
|
14
|
+
await cb(msg, details)
|
|
15
|
+
await old.call(this, msg, details)
|
|
16
|
+
}
|
|
17
|
+
break
|
|
18
|
+
case 'after':
|
|
19
|
+
this.notify = async (msg, details) => {
|
|
20
|
+
await old.call(this, msg, details)
|
|
21
|
+
await cb(msg, details)
|
|
22
|
+
}
|
|
23
|
+
break
|
|
24
|
+
case 'before-no-wait':
|
|
25
|
+
this.notify = async (msg, details) => {
|
|
26
|
+
cb(msg, details)
|
|
27
|
+
await old.call(this, msg, details)
|
|
28
|
+
}
|
|
29
|
+
break
|
|
30
|
+
case 'after-no-wait':
|
|
31
|
+
this.notify = async (msg, details) => {
|
|
32
|
+
await old.call(this, msg, details)
|
|
33
|
+
cb(msg, details)
|
|
34
|
+
}
|
|
35
|
+
break
|
|
36
|
+
case 'replace':
|
|
37
|
+
this.notify = cb
|
|
38
|
+
break
|
|
39
|
+
}
|
|
40
|
+
}
|