3434#include < iostream>
3535#include < objbase.h>
3636#include < optional>
37+ #include < print>
3738#include < string>
3839#include < string_view>
3940#include < thread>
@@ -53,7 +54,6 @@ namespace mb_shell {
5354window_proc_hook entry::main_window_loop_hook{};
5455void main () {
5556 set_thread_locale_utf8 ();
56-
5757 AllocConsole ();
5858 freopen (" CONOUT$" , " w" , stdout);
5959 freopen (" CONOUT$" , " w" , stderr);
@@ -63,16 +63,15 @@ void main() {
6363 install_error_handlers ();
6464 config::run_config_loader ();
6565
66+ static script_context script_ctx;
6667 std::thread ([]() {
67- script_context ctx;
68-
6968 auto data_dir = config::data_directory ();
7069 auto script_dir = data_dir / " scripts" ;
7170
7271 if (!std::filesystem::exists (script_dir))
7372 std::filesystem::create_directories (script_dir);
7473
75- ctx .watch_folder (script_dir, [&]() {
74+ script_ctx .watch_folder (script_dir, [&]() {
7675 return !context_menu_hooks::block_js_reload.load ();
7776 });
7877 }).detach ();
@@ -132,43 +131,59 @@ void main() {
132131 }
133132
134133 if (filename == " rundll32.exe" ) {
135- SetProcessDPIAware ();
136- CoInitialize (nullptr );
137- std::thread ([]() {
138- CPPTRACE_TRY {
139- SetThreadDpiAwarenessContext (
140- DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
141- taskbar_render taskbar;
142- auto monitor =
143- MonitorFromPoint ({0 , 0 }, MONITOR_DEFAULTTOPRIMARY);
144- if (!monitor) {
145- MessageBoxW (NULL , L" Failed to get primary monitor" ,
146- L" Error" , MB_ICONERROR);
147- return ;
134+ auto command_line = std::wstring (GetCommandLineW ());
135+
136+ if (command_line.contains (L" -taskbar" )) {
137+ SetProcessDPIAware ();
138+ CoInitialize (nullptr );
139+ std::thread ([]() {
140+ CPPTRACE_TRY {
141+ SetThreadDpiAwarenessContext (
142+ DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
143+ taskbar_render taskbar;
144+ auto monitor =
145+ MonitorFromPoint ({0 , 0 }, MONITOR_DEFAULTTOPRIMARY);
146+ if (!monitor) {
147+ MessageBoxW (NULL , L" Failed to get primary monitor" ,
148+ L" Error" , MB_ICONERROR);
149+ return ;
150+ }
151+ taskbar.monitor .cbSize = sizeof (MONITORINFO);
152+ if (GetMonitorInfoW (monitor, &taskbar.monitor ) == 0 ) {
153+ MessageBoxW (NULL ,
154+ (L" Failed to get monitor info: " +
155+ std::to_wstring (GetLastError ()))
156+ .c_str (),
157+ L" Error" , MB_ICONERROR);
158+ return ;
159+ }
160+ taskbar.position = taskbar_render::menu_position::bottom;
161+ if (auto res = taskbar.init (); !res) {
162+ MessageBoxW (NULL , L" Failed to initialize taskbar" ,
163+ L" Error" , MB_ICONERROR);
164+ return ;
165+ }
166+
167+ taskbar.rt .start_loop ();
148168 }
149- taskbar.monitor .cbSize = sizeof (MONITORINFO);
150- if (GetMonitorInfoW (monitor, &taskbar.monitor ) == 0 ) {
151- MessageBoxW (NULL ,
152- (L" Failed to get monitor info: " +
153- std::to_wstring (GetLastError ()))
154- .c_str (),
155- L" Error" , MB_ICONERROR);
156- return ;
157- }
158- taskbar.position = taskbar_render::menu_position::bottom;
159- if (auto res = taskbar.init (); !res) {
160- MessageBoxW (NULL , L" Failed to initialize taskbar" , L" Error" ,
161- MB_ICONERROR);
162- return ;
169+ CPPTRACE_CATCH (const std::exception &e) {
170+ std::cerr << " Error in taskbar thread: " << e.what ()
171+ << std::endl;
172+ cpptrace::from_current_exception ().print ();
163173 }
174+ }).detach ();
175+ }
176+ }
164177
165- taskbar.rt .start_loop ();
166- }
167- CPPTRACE_CATCH (const std::exception &e) {
168- std::cerr << " Error in taskbar thread: " << e.what ()
169- << std::endl;
170- cpptrace::from_current_exception ().print ();
171- }
178+ if (filename == " asan_test.exe" ) {
179+ // ASAN environment
180+ init_render_global ();
181+ ShowWindow (GetConsoleWindow (), SW_SHOW);
182+ std::thread ([]() {
183+ script_ctx.js_ready_future .wait ();
184+ script_ctx.js ->enqueueJob ([]() {
185+ script_ctx.js ->eval (" globalThis.showConfigPage()" , " asan.js" );
186+ });
172187 }).detach ();
173188 }
174189}
@@ -177,10 +192,6 @@ void main() {
177192int APIENTRY DllMain (HINSTANCE hInstance, DWORD fdwReason, LPVOID lpvReserved) {
178193 switch (fdwReason) {
179194 case DLL_PROCESS_ATTACH: {
180- auto cmdline = std::string (GetCommandLineA ());
181-
182- std::ranges::transform (cmdline, cmdline.begin (), tolower);
183-
184195 mb_shell::main ();
185196 break ;
186197 }
0 commit comments