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

Source from the content-addressed store, hash-verified

2099}
2100
2101static void main_daemon_ctl_open_browser(int port) {
2102 char url[64];
2103 (void)snprintf(url, sizeof(url), "http://127.0.0.1:%d", port);
2104#ifdef CBM_ENABLE_TEST_SEAMS
2105 char marker_path[MAIN_PATH_CAP];
2106 if (cbm_safe_getenv("CBM_TEST_DAEMON_OPEN_MARKER", marker_path, sizeof(marker_path), NULL)) {
2107 FILE *marker = cbm_fopen(marker_path, "wb");
2108 bool opened = marker && fwrite(url, 1, strlen(url), marker) == strlen(url);
2109 if (marker && fclose(marker) != 0) {
2110 opened = false;
2111 }
2112 if (!opened) {
2113 (void)fprintf(stderr, "hint: could not record the test browser request\n");
2114 }
2115 return;
2116 }
2117#endif
2118#if defined(_WIN32)
2119 /* ShellExecuteW resolves the http protocol association directly — no
2120 * command shell interprets the argument. Values > 32 signal success. */
2121 wchar_t *wide_url = cbm_utf8_to_wide(url);
2122 bool opened =
2123 wide_url && (INT_PTR)ShellExecuteW(NULL, L"open", wide_url, NULL, NULL, SW_SHOWNORMAL) > 32;
2124 free(wide_url);
2125#elif defined(__APPLE__)
2126 const char *open_argv[] = {"open", url, NULL};
2127 bool opened = cbm_exec_no_shell(open_argv) == 0;
2128#else
2129 const char *open_argv[] = {"xdg-open", url, NULL};
2130 bool opened = cbm_exec_no_shell(open_argv) == 0;
2131#endif
2132 if (!opened) {
2133 (void)fprintf(stderr, "hint: could not open a browser automatically; visit %s\n", url);
2134 }
2135}
2136
2137static int main_daemon_ctl_finish_ui_open(cbm_daemon_runtime_client_t **client_io, int port,
2138 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