aboutsummaryrefslogtreecommitdiff
path: root/src/zen/cmds/ui_cmd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zen/cmds/ui_cmd.cpp')
-rw-r--r--src/zen/cmds/ui_cmd.cpp51
1 files changed, 8 insertions, 43 deletions
diff --git a/src/zen/cmds/ui_cmd.cpp b/src/zen/cmds/ui_cmd.cpp
index 4846b4d18..53dbb22da 100644
--- a/src/zen/cmds/ui_cmd.cpp
+++ b/src/zen/cmds/ui_cmd.cpp
@@ -2,6 +2,9 @@
#include "ui_cmd.h"
+#include "browser_launcher.h"
+#include "zenserviceclient.h"
+
#include <zencore/except_fmt.h>
#include <zencore/fmtutils.h>
#include <zencore/logging.h>
@@ -9,11 +12,6 @@
#include <zenutil/consoletui.h>
#include <zenutil/zenserverprocess.h>
-#if ZEN_PLATFORM_WINDOWS
-# include <zencore/windows.h>
-# include <shellapi.h>
-#endif
-
namespace zen {
namespace {
@@ -83,40 +81,10 @@ UiCommand::OpenBrowser(std::string_view HostName)
}
}
- bool Success = false;
-
ExtendableStringBuilder<256> FullUrl;
FullUrl << HostName << m_DashboardPath;
-#if ZEN_PLATFORM_WINDOWS
- HINSTANCE Result = ShellExecuteA(nullptr, "open", FullUrl.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
- Success = reinterpret_cast<intptr_t>(Result) > 32;
-#else
- // Validate URL doesn't contain shell metacharacters that could lead to command injection
- std::string_view FullUrlView = FullUrl;
- constexpr std::string_view DangerousChars = ";|&$`\\\"'<>(){}[]!#*?~\n\r";
- if (FullUrlView.find_first_of(DangerousChars) != std::string_view::npos)
- {
- throw OptionParseException(fmt::format("URL contains invalid characters: '{}'", FullUrl), m_Options.help());
- }
-
-# if ZEN_PLATFORM_MAC
- std::string Command = fmt::format("open \"{}\"", FullUrl);
-# elif ZEN_PLATFORM_LINUX
- std::string Command = fmt::format("xdg-open \"{}\"", FullUrl);
-# else
- ZEN_NOT_IMPLEMENTED("Browser launching not implemented on this platform");
-# endif
-
- Success = system(Command.c_str()) == 0;
-#endif
-
- if (!Success)
- {
- throw zen::runtime_error("Failed to launch browser for '{}'", FullUrl);
- }
-
- ZEN_CONSOLE("Web browser launched for '{}' successfully", FullUrl);
+ LaunchBrowser(std::string_view(FullUrl));
}
void
@@ -162,7 +130,7 @@ UiCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
Labels.push_back(fmt::format("(all {} instances)", Servers.size()));
const int32_t Cols = static_cast<int32_t>(TuiConsoleColumns());
- constexpr int32_t kIndicator = 3; // " ▶ " or " " prefix
+ constexpr int32_t kIndicator = 3; // " > " or " " prefix
constexpr int32_t kSeparator = 2; // " " before cmdline
constexpr int32_t kEllipsis = 3; // "..."
@@ -225,17 +193,14 @@ UiCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
m_HostName = ResolveTargetHostSpec(m_HostName, ServerPort);
}
- if (m_HostName.empty())
- {
- throw OptionParseException("Unable to resolve server specification", m_Options.help());
- }
+ ZenServiceClient Service({.HostSpec = m_HostName, .CommandName = Name});
- if (IsUnixSocketSpec(m_HostName))
+ if (IsUnixSocketSpec(Service.HostSpec()))
{
throw std::runtime_error("Cannot open browser for a Unix domain socket connection");
}
- OpenBrowser(m_HostName);
+ OpenBrowser(Service.HostSpec());
}
} // namespace zen