summarylogtreecommitdiffstats
path: root/gtk4-fix-broken-alert-dialog-on-failure.patch
blob: 54892ae966da62fded47cbda48ecef0865e83c66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
From e3176c3fd87d41a74833d40e8cb3f0040c10cd15 Mon Sep 17 00:00:00 2001
From: Keeyou <keeyou-cn@outlook.com>
Date: Mon, 22 Apr 2024 13:51:47 +0800
Subject: [PATCH] gtk4: fix broken alert dialog on failure

---
 src/gtk/yass.cpp           |  1 -
 src/gtk/yass_window.cpp    |  2 +-
 src/gtk4/yass.cpp          |  1 -
 src/gtk4/yass_en.po        |  8 ++++++++
 src/gtk4/yass_window.cpp   | 20 ++++++++++++++++----
 src/gtk4/yass_zh_CN.po     |  8 ++++++++
 src/mac/YassAppDelegate.mm |  1 -
 src/win32/yass.cpp         |  2 --
 8 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/src/gtk/yass.cpp b/src/gtk/yass.cpp
index 3402a9b7..dd6b4ad8 100644
--- a/src/gtk/yass.cpp
+++ b/src/gtk/yass.cpp
@@ -267,7 +267,6 @@ void YASSApp::OnStartFailed(const std::string& error_msg) {
   state_ = START_FAILED;
 
   error_msg_ = error_msg;
-  LOG(ERROR) << "worker failed due to: " << error_msg_;
   main_window_->StartFailed();
 }
 
diff --git a/src/gtk/yass_window.cpp b/src/gtk/yass_window.cpp
index ec3fda60..848e2318 100644
--- a/src/gtk/yass_window.cpp
+++ b/src/gtk/yass_window.cpp
@@ -377,7 +377,7 @@ void YASSWindow::StartFailed() {
   gtk_widget_set_sensitive(GTK_WIDGET(dot_host_), true);
   gtk_widget_set_sensitive(GTK_WIDGET(timeout_), true);
 
-  GtkDialog* alert_dialog = GTK_DIALOG(gtk_message_dialog_new(impl_, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+  GtkDialog* alert_dialog = GTK_DIALOG(gtk_message_dialog_new(impl_, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
                                                               GTK_BUTTONS_OK, "%s", mApp->GetStatus().c_str()));
 
   gtk_dialog_run(GTK_DIALOG(alert_dialog));
diff --git a/src/gtk4/yass.cpp b/src/gtk4/yass.cpp
index 9d3708f7..f3ec143c 100644
--- a/src/gtk4/yass.cpp
+++ b/src/gtk4/yass.cpp
@@ -310,7 +310,6 @@ void YASSApp::OnStartFailed(const std::string& error_msg) {
   state_ = START_FAILED;
 
   error_msg_ = error_msg;
-  LOG(ERROR) << "worker failed due to: " << error_msg_;
   main_window_->StartFailed();
 }
 
diff --git a/src/gtk4/yass_en.po b/src/gtk4/yass_en.po
index 183df608..7b992203 100644
--- a/src/gtk4/yass_en.po
+++ b/src/gtk4/yass_en.po
@@ -89,6 +89,14 @@ msgstr "DNS over HTTPS URL:"
 msgid "DNS over TLS Host:"
 msgstr "DNS over TLS Host:"
 
+#: yass_window.cpp:298
+msgid "Start Failed"
+msgstr "Start Failed"
+
+#: yass_window.cpp:298
+msgid "OK"
+msgstr "OK"
+
 #: yass_window.ui:101
 msgid "Timeout:"
 msgstr "Timeout:"
diff --git a/src/gtk4/yass_window.cpp b/src/gtk4/yass_window.cpp
index bb72c913..b3b3ea69 100644
--- a/src/gtk4/yass_window.cpp
+++ b/src/gtk4/yass_window.cpp
@@ -295,10 +295,22 @@ void YASSWindow::StartFailed() {
   gtk_widget_set_sensitive(impl_->dot_host, true);
   gtk_widget_set_sensitive(impl_->timeout, true);
 
-  GtkDialog* dialog = GTK_DIALOG(gtk_message_dialog_new(GTK_WINDOW(impl_), GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
-                                                        GTK_BUTTONS_CLOSE, "%s", mApp->GetStatus().c_str()));
-
-  g_signal_connect(dialog, "response", G_CALLBACK(gtk_window_destroy), NULL);
+  // Gtk4 Message Dialog is deprecated since 4.10
+#if GTK_CHECK_VERSION(4, 10, 0)
+  GtkAlertDialog* dialog = gtk_alert_dialog_new("%s", _("Start Failed"));
+  const char* buttons[] = {_("OK"), nullptr};
+  gtk_alert_dialog_set_detail(dialog, mApp->GetStatus().c_str());
+  gtk_alert_dialog_set_buttons(dialog, buttons);
+  gtk_window_present(GTK_WINDOW(impl_));
+  gtk_alert_dialog_choose(dialog, GTK_WINDOW(impl_), nullptr, nullptr, nullptr);
+#else
+  GtkDialogFlags flags = (GtkDialogFlags)(GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL);
+  GtkDialog* dialog = GTK_DIALOG(gtk_message_dialog_new(GTK_WINDOW(impl_), flags, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
+                                                        "%s", mApp->GetStatus().c_str()));
+
+  g_signal_connect(dialog, "response", G_CALLBACK(gtk_window_destroy), nullptr);
+  gtk_widget_show(GTK_WIDGET(dialog));
+#endif
 }
 
 void YASSWindow::Stopped() {
diff --git a/src/gtk4/yass_zh_CN.po b/src/gtk4/yass_zh_CN.po
index 3715169f..cb59cb8c 100644
--- a/src/gtk4/yass_zh_CN.po
+++ b/src/gtk4/yass_zh_CN.po
@@ -90,6 +90,14 @@ msgstr "基于 HTTPS 的 DNS (DoH) URL:"
 msgid "DNS over TLS Host:"
 msgstr "基于 TLS 的 DNS (DoT) 域名:"
 
+#: yass_window.cpp:298
+msgid "Start Failed"
+msgstr "启动失败"
+
+#: yass_window.cpp:298
+msgid "OK"
+msgstr "确认"
+
 #: yass_window.ui:101
 msgid "Timeout:"
 msgstr "超时时间:"
diff --git a/src/mac/YassAppDelegate.mm b/src/mac/YassAppDelegate.mm
index d594dd69..15893c52 100644
--- a/src/mac/YassAppDelegate.mm
+++ b/src/mac/YassAppDelegate.mm
@@ -168,7 +168,6 @@
   state_ = START_FAILED;
 
   error_msg_ = error_msg;
-  LOG(ERROR) << "worker failed due to: " << error_msg_;
   YassWindowController* windowController =
       (YassWindowController*)NSApplication.sharedApplication.mainWindow.windowController;
   [windowController StartFailed];
diff --git a/src/win32/yass.cpp b/src/win32/yass.cpp
index abc32569..0ec4adf9 100644
--- a/src/win32/yass.cpp
+++ b/src/win32/yass.cpp
@@ -365,8 +365,6 @@ void CYassApp::OnStartFailed(WPARAM w, LPARAM l) {
   std::unique_ptr<std::string> message_ptr(reinterpret_cast<std::string*>(l));
 
   error_msg_ = std::move(message_ptr.operator*());
-
-  LOG(ERROR) << "worker failed due to: " << error_msg_;
   frame_->OnStartFailed();
 }
 
-- 
2.44.0