Skip to content

Commit 7335201

Browse files
fix: add set_text/get_text to clipboard and stop evtloop
1 parent 50aacce commit 7335201

5 files changed

Lines changed: 23 additions & 12 deletions

File tree

src/shell/entry.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050

5151
#include "logger.h"
5252

53+
#include "async_simple/coro/SyncAwait.h"
54+
5355
namespace mb_shell {
5456
window_proc_hook entry::main_window_loop_hook{};
5557

@@ -198,11 +200,12 @@ void main() {
198200
std::thread([]() {
199201
script_ctx.is_js_ready.wait(false);
200202
spdlog::info("Is js ready: %d", script_ctx.is_js_ready.load());
201-
if (auto res =
202-
script_ctx.eval_string("globalThis.showConfigPage()",
203-
"asan.js");
204-
!res) {
205-
spdlog::error("Failed to show config page: {}", res.error());
203+
try {
204+
auto res = syncAwait(script_ctx.eval_string("throw new Error('Hello from ASAN environment!');",
205+
"asan.js")->await());
206+
spdlog::info("ASAN eval result: {}", res.as<std::string>());
207+
} catch (const std::exception &e) {
208+
spdlog::error("Error in ASAN test thread: {}", e.what());
206209
}
207210
}).detach();
208211
}

src/shell/script/binding_qjs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,8 +1118,11 @@ template<> struct js_bind<mb_shell::js::clipboard> {
11181118
static void bind(qjs::Context::Module &mod) {
11191119
mod.class_<mb_shell::js::clipboard>("clipboard")
11201120
.constructor<>()
1121+
.static_property<&mb_shell::js::clipboard::get_text, &mb_shell::js::clipboard::set_text>("text")
11211122
.static_fun<&mb_shell::js::clipboard::read_text>("read_text")
1123+
.static_fun<&mb_shell::js::clipboard::get_text>("get_text")
11221124
.static_fun<&mb_shell::js::clipboard::write_text>("write_text")
1125+
.static_fun<&mb_shell::js::clipboard::set_text>("set_text")
11231126
;
11241127
}
11251128
};

src/shell/script/binding_types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,8 @@ export class menu_controller {
885885
show_at_cursor(): void
886886
}
887887
export class clipboard {
888+
static get text(): string;
889+
static set text(value: string);
888890
/**
889891
* 从剪贴板获取文本
890892
* Get text from clipboard

src/shell/script/binding_types.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,13 @@ struct menu_item_controller {
294294
std::variant<std::weak_ptr<mb_shell::menu_widget>,
295295
std::weak_ptr<mb_shell::menu_item_parent_widget>>
296296
$parent;
297-
int get_position() const;
298-
void set_position(int new_index);
299-
void set_data(js_menu_data data);
300-
void update_data(js_menu_data data);
301-
js_menu_data data();
302-
void remove();
303-
bool valid();
297+
int get_position() const;
298+
void set_position(int new_index);
299+
void set_data(js_menu_data data);
300+
void update_data(js_menu_data data);
301+
js_menu_data data();
302+
void remove();
303+
bool valid();
304304
};
305305

306306
struct menu_item_parent_item_controller {
@@ -474,10 +474,12 @@ struct clipboard {
474474
// 从剪贴板获取文本
475475
// Get text from clipboard
476476
static std::string read_text();
477+
static std::string get_text() { return read_text(); }
477478

478479
// 设置文本到剪贴板
479480
// Set text to clipboard
480481
static void write_text(std::string text);
482+
static void set_text(std::string text) { write_text(text); }
481483
};
482484

483485
// 网络操作

src/shell/script/script.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ void script_context::watch_folder(const std::filesystem::path &path,
5252
menu_callbacks_js.clear();
5353
is_js_ready.store(false);
5454
module_base = path;
55+
stop_event_loop_in_time(std::chrono::milliseconds(500));
5556
reset_runtime();
5657

5758
std::vector<std::filesystem::path> files;

0 commit comments

Comments
 (0)