From 71f520d0d83d89871662c0dbf305e2e57c5fcc9b Mon Sep 17 00:00:00 2001 From: LI Daobing Date: Sun, 12 May 2024 20:20:09 -0700 Subject: [PATCH 1/2] use g_app_info_launch_default_for_uri for open url/path --- src/iptux/UiHelper.cpp | 49 +++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/iptux/UiHelper.cpp b/src/iptux/UiHelper.cpp index 3c30f886..5008c22f 100644 --- a/src/iptux/UiHelper.cpp +++ b/src/iptux/UiHelper.cpp @@ -17,38 +17,43 @@ namespace iptux { static bool pop_disabled = false; +void iptux_open_path(const char* path) { + g_return_if_fail(!!path); + + GError* error = nullptr; + gchar* uri = g_filename_to_uri(path, nullptr, &error); + if (error) { + LOG_WARN(_("Can't convert path to uri: %s, reason: %s"), path, + error->message); + g_error_free(error); + return; + } + g_app_info_launch_default_for_uri(uri, nullptr, &error); + if (error) { + LOG_WARN(_("Can't open path: %s, reason: %s"), path, error->message); + g_error_free(error); + } + g_free(uri); +} + /** * 打开URL. * @param url url */ void iptux_open_url(const char* url) { - int fd; + g_return_if_fail(!!url); - if (pop_disabled) { - LOG_INFO(_("Open URL: %s\n"), url); + if (url[0] == '/') { + iptux_open_path(url); return; } - if (fork() != 0) - return; - - /* 关闭由iptux打开的所有可能的文件描述符 */ - fd = 3; - while (fd < FD_SETSIZE) { - close(fd); - fd++; + GError* error = nullptr; + g_app_info_launch_default_for_uri(url, nullptr, &error); + if (error) { + LOG_WARN(_("Can't open URL: %s, reason: %s"), url, error->message); + g_error_free(error); } - /* 脱离终端控制 */ - setsid(); - - /* 打开URL */ - execlp("xdg-open", "xdg-open", url, NULL); - /* 测试系统中所有可能被安装的浏览器 */ - execlp("firefox", "firefox", url, NULL); - execlp("opera", "opera", url, NULL); - execlp("konqueror", "konqueror", url, NULL); - execlp("open", "open", url, NULL); - LOG_WARN(_("Can't find any available web browser!\n")); } bool ValidateDragData(GtkSelectionData* data, From 68cf5b9e9ce4f8c02eff86597376994592d83b5e Mon Sep 17 00:00:00 2001 From: LI Daobing Date: Sun, 12 May 2024 20:26:46 -0700 Subject: [PATCH 2/2] more test --- src/iptux/ApplicationTest.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/iptux/ApplicationTest.cpp b/src/iptux/ApplicationTest.cpp index a796f559..2abd5b63 100644 --- a/src/iptux/ApplicationTest.cpp +++ b/src/iptux/ApplicationTest.cpp @@ -11,9 +11,10 @@ void do_action(Application* app, const string& name) { g_action_activate(g_action_map_lookup_action(m, name.c_str()), NULL); } - TEST(Application, Constructor) { Application* app = CreateApplication(); do_action(app, "help.whats_new"); + do_action(app, "tools.open_chat_log"); + do_action(app, "tools.open_system_log"); DestroyApplication(app); }