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:2086–2120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2084}
2085
2086static void main_daemon_ctl_open_browser(int port) {
2087 char url[64];
2088 (void)snprintf(url, sizeof(url), "http://127.0.0.1:%d", port);
2089#ifdef CBM_ENABLE_TEST_SEAMS
2090 char marker_path[MAIN_PATH_CAP];
2091 if (cbm_safe_getenv("CBM_TEST_DAEMON_OPEN_MARKER", marker_path, sizeof(marker_path), NULL)) {
2092 FILE *marker = cbm_fopen(marker_path, "wb");
2093 bool opened = marker && fwrite(url, 1, strlen(url), marker) == strlen(url);
2094 if (marker && fclose(marker) != 0) {
2095 opened = false;
2096 }
2097 if (!opened) {
2098 (void)fprintf(stderr, "hint: could not record the test browser request\n");
2099 }
2100 return;
2101 }
2102#endif
2103#if defined(_WIN32)
2104 /* ShellExecuteW resolves the http protocol association directly — no
2105 * command shell interprets the argument. Values > 32 signal success. */
2106 wchar_t *wide_url = cbm_utf8_to_wide(url);
2107 bool opened =
2108 wide_url && (INT_PTR)ShellExecuteW(NULL, L"open", wide_url, NULL, NULL, SW_SHOWNORMAL) > 32;
2109 free(wide_url);
2110#elif defined(__APPLE__)
2111 const char *open_argv[] = {"open", url, NULL};
2112 bool opened = cbm_exec_no_shell(open_argv) == 0;
2113#else
2114 const char *open_argv[] = {"xdg-open", url, NULL};
2115 bool opened = cbm_exec_no_shell(open_argv) == 0;
2116#endif
2117 if (!opened) {
2118 (void)fprintf(stderr, "hint: could not open a browser automatically; visit %s\n", url);
2119 }
2120}
2121
2122static int main_daemon_ctl_finish_ui_open(cbm_daemon_runtime_client_t **client_io, int port,
2123 bool open_browser) {

Callers 1

Calls 4

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

Tested by

no test coverage detected