X Tutup
Skip to content

Commit c87394e

Browse files
authored
feat: show optional authors in gtk about panel (electron#18964)
* feat: show optional authors in gtk about panel * chore: use a base::Value for about dialog options on Linux * docs: mark 'version' as supported on Linux too
1 parent ab5ec0a commit c87394e

File tree

3 files changed

+42
-25
lines changed

3 files changed

+42
-25
lines changed

docs/api/app.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,8 +1178,9 @@ Show the app's about panel options. These options can be overridden with `app.se
11781178
* `applicationName` String (optional) - The app's name.
11791179
* `applicationVersion` String (optional) - The app's version.
11801180
* `copyright` String (optional) - Copyright information.
1181-
* `version` String (optional) - The app's build version number. _macOS_
1181+
* `version` String (optional) - The app's build version number.
11821182
* `credits` String (optional) - Credit information. _macOS_
1183+
* `authors` String[] (optional) - List of app authors. _Linux_
11831184
* `website` String (optional) - The app's website. _Linux_
11841185
* `iconPath` String (optional) - Path to the app's icon. _Linux_
11851186

shell/browser/browser.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ class Browser : public WindowListObserver {
159159
const base::DictionaryValue& user_info);
160160

161161
// Bounce the dock icon.
162-
enum class BounceType {
163-
CRITICAL = 0, // NSCriticalRequest
164-
INFORMATIONAL = 10, // NSInformationalRequest
162+
enum class BounceType{
163+
CRITICAL = 0, // NSCriticalRequest
164+
INFORMATIONAL = 10, // NSInformationalRequest
165165
};
166166
int DockBounce(BounceType type);
167167
void DockCancelBounce(int request_id);
@@ -305,7 +305,9 @@ class Browser : public WindowListObserver {
305305

306306
std::unique_ptr<util::Promise> ready_promise_;
307307

308-
#if defined(OS_LINUX) || defined(OS_MACOSX)
308+
#if defined(OS_LINUX)
309+
base::Value about_panel_options_;
310+
#elif defined(OS_MACOSX)
309311
base::DictionaryValue about_panel_options_;
310312
#endif
311313

shell/browser/browser_linux.cc

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -147,21 +147,27 @@ bool Browser::IsEmojiPanelSupported() {
147147
}
148148

149149
void Browser::ShowAboutPanel() {
150-
std::string app_name, version, copyright, icon_path, website;
151-
152150
GtkAboutDialog* dialog = GTK_ABOUT_DIALOG(gtk_about_dialog_new());
153151

154-
if (about_panel_options_.GetString("applicationName", &app_name))
155-
gtk_about_dialog_set_program_name(dialog, app_name.c_str());
156-
if (about_panel_options_.GetString("applicationVersion", &version))
157-
gtk_about_dialog_set_version(dialog, version.c_str());
158-
if (about_panel_options_.GetString("copyright", &copyright))
159-
gtk_about_dialog_set_copyright(dialog, copyright.c_str());
160-
if (about_panel_options_.GetString("website", &website))
161-
gtk_about_dialog_set_website(dialog, website.c_str());
162-
if (about_panel_options_.GetString("iconPath", &icon_path)) {
152+
const auto& opts = about_panel_options_;
153+
const std::string* str;
154+
const base::Value* val;
155+
156+
if ((str = opts.FindStringKey("applicationName"))) {
157+
gtk_about_dialog_set_program_name(dialog, str->c_str());
158+
}
159+
if ((str = opts.FindStringKey("applicationVersion"))) {
160+
gtk_about_dialog_set_version(dialog, str->c_str());
161+
}
162+
if ((str = opts.FindStringKey("copyright"))) {
163+
gtk_about_dialog_set_copyright(dialog, str->c_str());
164+
}
165+
if ((str = opts.FindStringKey("website"))) {
166+
gtk_about_dialog_set_website(dialog, str->c_str());
167+
}
168+
if ((str = opts.FindStringKey("iconPath"))) {
163169
GError* error = nullptr;
164-
GdkPixbuf* icon = gdk_pixbuf_new_from_file(icon_path.c_str(), &error);
170+
GdkPixbuf* icon = gdk_pixbuf_new_from_file(str->c_str(), &error);
165171
if (error != nullptr) {
166172
g_warning("%s", error->message);
167173
g_clear_error(&error);
@@ -171,19 +177,27 @@ void Browser::ShowAboutPanel() {
171177
}
172178
}
173179

180+
if ((val = opts.FindListKey("authors"))) {
181+
std::vector<const char*> cstrs;
182+
for (const auto& authorVal : val->GetList()) {
183+
if (authorVal.is_string()) {
184+
cstrs.push_back(authorVal.GetString().c_str());
185+
}
186+
}
187+
if (cstrs.empty()) {
188+
LOG(WARNING) << "No author strings found in 'authors' array";
189+
} else {
190+
cstrs.push_back(nullptr); // null-terminated char* array
191+
gtk_about_dialog_set_authors(dialog, cstrs.data());
192+
}
193+
}
194+
174195
gtk_dialog_run(GTK_DIALOG(dialog));
175196
g_clear_object(&dialog);
176197
}
177198

178199
void Browser::SetAboutPanelOptions(const base::DictionaryValue& options) {
179-
about_panel_options_.Clear();
180-
181-
for (const auto& pair : options) {
182-
const std::string& key = pair.first;
183-
const auto& val = pair.second;
184-
if (!key.empty() && val->is_string())
185-
about_panel_options_.SetString(key, val->GetString());
186-
}
200+
about_panel_options_ = options.Clone();
187201
}
188202

189203
} // namespace electron

0 commit comments

Comments
 (0)
X Tutup