MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / main_daemon_ctl_open_browser

Function main_daemon_ctl_open_browser

src/main.c:2443–2477  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2441}
2442
2443static void main_daemon_ctl_open_browser(int port) {
2444 char url[64];
2445 (void)snprintf(url, sizeof(url), "http://127.0.0.1:%d", port);
2446#ifdef CBM_ENABLE_TEST_SEAMS
2447 char marker_path[MAIN_PATH_CAP];
2448 if (cbm_safe_getenv("CBM_TEST_DAEMON_OPEN_MARKER", marker_path, sizeof(marker_path), NULL)) {
2449 FILE *marker = cbm_fopen(marker_path, "wb");
2450 bool opened = marker && fwrite(url, 1, strlen(url), marker) == strlen(url);
2451 if (marker && fclose(marker) != 0) {
2452 opened = false;
2453 }
2454 if (!opened) {
2455 (void)fprintf(stderr, "hint: could not record the test browser request\n");
2456 }
2457 return;
2458 }
2459#endif
2460#if defined(_WIN32)
2461 /* ShellExecuteW resolves the http protocol association directly — no
2462 * command shell interprets the argument. Values > 32 signal success. */
2463 wchar_t *wide_url = cbm_utf8_to_wide(url);
2464 bool opened =
2465 wide_url && (INT_PTR)ShellExecuteW(NULL, L"open", wide_url, NULL, NULL, SW_SHOWNORMAL) > 32;
2466 free(wide_url);
2467#elif defined(__APPLE__)
2468 const char *open_argv[] = {"open", url, NULL};
2469 bool opened = cbm_exec_no_shell(open_argv) == 0;
2470#else
2471 const char *open_argv[] = {"xdg-open", url, NULL};
2472 bool opened = cbm_exec_no_shell(open_argv) == 0;
2473#endif
2474 if (!opened) {
2475 (void)fprintf(stderr, "hint: could not open a browser automatically; visit %s\n", url);
2476 }
2477}
2478
2479/* Ask the daemon to enable the UI on `port`; true when it accepted.
2480 *

Callers 1

Calls 5

cbm_safe_getenvFunction · 0.85
cbm_fopenFunction · 0.85
fwriteFunction · 0.85
cbm_utf8_to_wideFunction · 0.85
cbm_exec_no_shellFunction · 0.85

Tested by

no test coverage detected