Skip to content

Commit da9b5ce

Browse files
feat(js): implement breeze.set_can_reload_js
1 parent 80417d5 commit da9b5ce

File tree

7 files changed

+18
-5
lines changed

7 files changed

+18
-5
lines changed

src/shell/contextmenu/hooks.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "Windows.h"
1616
#include "shlobj_core.h"
1717

18-
std::atomic_bool mb_shell::context_menu_hooks::has_active_menu = false;
18+
std::atomic_bool mb_shell::context_menu_hooks::block_js_reload = false;
1919

2020
static auto renderer_thread = mb_shell::task_queue{};
2121

@@ -67,7 +67,7 @@ mb_shell::track_popup_menu(mb_shell::menu menu, int x, int y,
6767
qjs::wait_with_msgloop([&]() { selected_menu_future.wait(); });
6868

6969
auto selected_menu = selected_menu_future.get();
70-
mb_shell::context_menu_hooks::has_active_menu = false;
70+
mb_shell::context_menu_hooks::block_js_reload = false;
7171

7272
return selected_menu;
7373
}
@@ -90,7 +90,7 @@ void mb_shell::context_menu_hooks::install_common_hook() {
9090
}
9191

9292
entry::main_window_loop_hook.install(hWnd);
93-
has_active_menu = true;
93+
block_js_reload = true;
9494

9595
perf_counter perf("TrackPopupMenuEx");
9696
menu menu = menu::construct_with_hmenu(hMenu, hWnd);

src/shell/contextmenu/hooks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace mb_shell {
66
struct context_menu_hooks {
7-
static std::atomic_bool has_active_menu;
7+
static std::atomic_bool block_js_reload;
88
static void install_common_hook();
99
static void install_SHCreateDefaultContextMenu_hook();
1010
}; // namespace context_menu_hooks

src/shell/entry.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void main() {
7373
std::filesystem::create_directories(script_dir);
7474

7575
ctx.watch_folder(script_dir, [&]() {
76-
return !context_menu_hooks::has_active_menu.load();
76+
return !context_menu_hooks::block_js_reload.load();
7777
});
7878
}).detach();
7979

src/shell/script/binding_qjs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,7 @@ template<> struct js_bind<mb_shell::js::breeze> {
11061106
.static_fun<&mb_shell::js::breeze::data_directory>("data_directory")
11071107
.static_fun<&mb_shell::js::breeze::is_light_theme>("is_light_theme")
11081108
.static_fun<&mb_shell::js::breeze::user_language>("user_language")
1109+
.static_fun<&mb_shell::js::breeze::set_can_reload_js>("set_can_reload_js")
11091110
;
11101111
}
11111112
};

src/shell/script/binding_types.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
// Compile Information
2222
#include "shell/build_info.h"
2323

24+
#include "shell/contextmenu/hooks.h"
25+
2426
#include "script.h"
2527
#include "winhttp.h"
2628

@@ -1439,4 +1441,7 @@ void menu_controller::show_at_cursor() {
14391441
show_at(p.x, p.y);
14401442
}
14411443
}
1444+
void breeze::set_can_reload_js(bool can) {
1445+
mb_shell::context_menu_hooks::block_js_reload.store(!can);
1446+
}
14421447
} // namespace mb_shell::js

src/shell/script/binding_types.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,12 @@ export class breeze {
10471047
static data_directory(): string
10481048
static is_light_theme(): boolean
10491049
static user_language(): string
1050+
/**
1051+
*
1052+
* @param can: boolean
1053+
* @returns void
1054+
*/
1055+
static set_can_reload_js(can: boolean): void
10501056
}
10511057
export class win32 {
10521058
/**

src/shell/script/binding_types.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ struct breeze {
624624
static std::string data_directory();
625625
static bool is_light_theme();
626626
static std::string user_language();
627+
static void set_can_reload_js(bool can);
627628
};
628629

629630
struct win32 {

0 commit comments

Comments
 (0)