4
4
#include < unordered_set>
5
5
6
6
#include " MaaToolkit/Device/MaaToolkitDevice.h"
7
+ #include " ProjectInterface/Runner.h"
7
8
#include " Utils/Logger.h"
8
9
#include " Utils/Platform.h"
9
10
@@ -53,11 +54,13 @@ bool Interactor::load(const std::filesystem::path& project_dir)
53
54
LogFunc << VAR (project_dir);
54
55
55
56
if (!config_.load (project_dir)) {
57
+ mpause ();
56
58
return false ;
57
59
}
58
60
59
61
if (!config_.check_configuration ()) {
60
62
std::cout << " ### The interface has changed and incompatible configurations have been deleted. ###\n\n " ;
63
+ mpause ();
61
64
}
62
65
63
66
return true ;
@@ -72,16 +75,32 @@ void Interactor::interact()
72
75
73
76
while (true ) {
74
77
print_config ();
75
- if (interact_once ()) {
78
+ if (! interact_once ()) {
76
79
break ;
77
80
}
78
81
config_.save ();
79
82
}
80
83
}
81
84
82
- std::optional<MAA_PROJECT_INTERFACE_NS::RuntimeParam> Interactor::generate_runtime () const
85
+ bool Interactor::run ()
83
86
{
84
- return config_.generate_runtime ();
87
+ auto runtime = config_.generate_runtime ();
88
+ if (!runtime) {
89
+ LogError << " Failed to generate runtime" ;
90
+ return false ;
91
+ }
92
+
93
+ bool ret = MAA_PROJECT_INTERFACE_NS::Runner::run (runtime.value (), on_maafw_notify, this );
94
+
95
+ if (!ret) {
96
+ std::cout << " ### Failed to run tasks ###\n\n " ;
97
+ }
98
+ else {
99
+ std::cout << " ### All tasks have been completed ###\n\n " ;
100
+ }
101
+
102
+ mpause ();
103
+ return ret;
85
104
}
86
105
87
106
void Interactor::print_config () const
@@ -108,11 +127,12 @@ void Interactor::print_config() const
108
127
void Interactor::welcome () const
109
128
{
110
129
if (config_.interface_data ().message .empty ()) {
111
- std::cout << " Welcome to use Maa Project Interface CLI!\n\n " ;
130
+ std::cout << " Welcome to use Maa Project Interface CLI!\n " ;
112
131
}
113
132
else {
114
- std::cout << MaaNS::utf8_to_crt (config_.interface_data ().message ) << " \n\n " ;
133
+ std::cout << MaaNS::utf8_to_crt (config_.interface_data ().message ) << " \n " ;
115
134
}
135
+ std::cout << " MaaFramework: " << MAA_VERSION << " \n\n " ;
116
136
117
137
std::cout << " Version: " << MaaNS::utf8_to_crt (config_.interface_data ().version ) << " \n\n " ;
118
138
}
@@ -126,9 +146,10 @@ bool Interactor::interact_once()
126
146
std::cout << " \t 4. Move task\n " ;
127
147
std::cout << " \t 5. Delete task\n " ;
128
148
std::cout << " \t 6. Run tasks\n " ;
149
+ std::cout << " \t 7. Exit\n " ;
129
150
std::cout << " \n " ;
130
151
131
- int action = input (6 );
152
+ int action = input (7 );
132
153
133
154
switch (action) {
134
155
case 1 :
@@ -147,10 +168,13 @@ bool Interactor::interact_once()
147
168
delete_task ();
148
169
break ;
149
170
case 6 :
150
- return true ;
171
+ run ();
172
+ break ;
173
+ case 7 :
174
+ return false ;
151
175
}
152
176
153
- return false ;
177
+ return true ;
154
178
}
155
179
156
180
void Interactor::select_controller ()
@@ -394,3 +418,19 @@ void Interactor::print_config_tasks(bool with_index) const
394
418
}
395
419
std::cout << " \n " ;
396
420
}
421
+
422
+ void Interactor::mpause () const
423
+ {
424
+ std::cout << " \n Press Enter to continue..." ;
425
+ std::cin.sync ();
426
+ std::cin.get ();
427
+ }
428
+
429
+ void Interactor::on_maafw_notify (MaaStringView msg, MaaStringView details_json, MaaTransparentArg callback_arg)
430
+ {
431
+ Interactor* pthis = static_cast <Interactor*>(callback_arg);
432
+ std::ignore = pthis;
433
+
434
+ std::string entry = json::parse (details_json).value_or (json::value ())[" entry" ].as_string ();
435
+ std::cout << MaaNS::utf8_to_crt (std::format (" on_maafw_notify: {} {}" , msg, entry)) << std::endl;
436
+ }
0 commit comments