From dc5ada1c04c9d1b459c14361463b7131610a429b Mon Sep 17 00:00:00 2001 From: antelle Date: Wed, 14 Apr 2021 21:31:29 +0200 Subject: [PATCH] etter error handling --- .../src/native-messaging-host.cpp | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/extension/native-messaging-host/src/native-messaging-host.cpp b/extension/native-messaging-host/src/native-messaging-host.cpp index 14593631..368b57a5 100644 --- a/extension/native-messaging-host/src/native-messaging-host.cpp +++ b/extension/native-messaging-host/src/native-messaging-host.cpp @@ -39,27 +39,6 @@ struct State { State state{}; -std::string keeweb_pipe_name() { - std::string pipe_name; - - uv_passwd_t user_info; - auto err = uv_os_get_passwd(&user_info); - - if (err) { - std::cerr << "Error getting user: " << uv_err_name(err) << std::endl; - } else { -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) - pipe_name = "\\\\.\\pipe\\keeweb-browser-" + std::string{user_info.username}; -#else - pipe_name = std::filesystem::temp_directory_path() / - ("keeweb-browser-" + std::to_string(user_info.uid) + ".sock"); -#endif - uv_os_free_passwd(&user_info); - } - - return pipe_name; -} - void process_keeweb_queue(); void process_stdout_queue(); void close_keeweb_pipe(); @@ -214,10 +193,35 @@ void keeweb_pipe_connect_cb(uv_connect_t *req, int status) { } } +std::string keeweb_pipe_name() { + std::string pipe_name; + + uv_passwd_t user_info; + auto err = uv_os_get_passwd(&user_info); + + if (err) { + std::cerr << "Error getting user info: " << uv_err_name(err) << std::endl; + } else { +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) + pipe_name = "\\\\.\\pipe\\keeweb-browser-" + std::string{user_info.username}; +#else + pipe_name = std::filesystem::temp_directory_path() / + ("keeweb-browser-" + std::to_string(user_info.uid) + ".sock"); +#endif + uv_os_free_passwd(&user_info); + } + + return pipe_name; +} + void connect_keeweb_pipe() { state.keeweb_connect_attempts++; auto pipe_name = keeweb_pipe_name(); + if (pipe_name.empty()) { + quit_on_error(); + return; + } auto keeweb_pipe = new uv_pipe_t{}; uv_pipe_init(uv_default_loop(), keeweb_pipe, false);