feat: show optional authors in gtk about panel (#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
This commit is contained in:
parent
ab5ec0af33
commit
c87394ee25
3 changed files with 42 additions and 25 deletions
|
@ -1178,8 +1178,9 @@ Show the app's about panel options. These options can be overridden with `app.se
|
||||||
* `applicationName` String (optional) - The app's name.
|
* `applicationName` String (optional) - The app's name.
|
||||||
* `applicationVersion` String (optional) - The app's version.
|
* `applicationVersion` String (optional) - The app's version.
|
||||||
* `copyright` String (optional) - Copyright information.
|
* `copyright` String (optional) - Copyright information.
|
||||||
* `version` String (optional) - The app's build version number. _macOS_
|
* `version` String (optional) - The app's build version number.
|
||||||
* `credits` String (optional) - Credit information. _macOS_
|
* `credits` String (optional) - Credit information. _macOS_
|
||||||
|
* `authors` String[] (optional) - List of app authors. _Linux_
|
||||||
* `website` String (optional) - The app's website. _Linux_
|
* `website` String (optional) - The app's website. _Linux_
|
||||||
* `iconPath` String (optional) - Path to the app's icon. _Linux_
|
* `iconPath` String (optional) - Path to the app's icon. _Linux_
|
||||||
|
|
||||||
|
|
|
@ -159,9 +159,9 @@ class Browser : public WindowListObserver {
|
||||||
const base::DictionaryValue& user_info);
|
const base::DictionaryValue& user_info);
|
||||||
|
|
||||||
// Bounce the dock icon.
|
// Bounce the dock icon.
|
||||||
enum class BounceType {
|
enum class BounceType{
|
||||||
CRITICAL = 0, // NSCriticalRequest
|
CRITICAL = 0, // NSCriticalRequest
|
||||||
INFORMATIONAL = 10, // NSInformationalRequest
|
INFORMATIONAL = 10, // NSInformationalRequest
|
||||||
};
|
};
|
||||||
int DockBounce(BounceType type);
|
int DockBounce(BounceType type);
|
||||||
void DockCancelBounce(int request_id);
|
void DockCancelBounce(int request_id);
|
||||||
|
@ -305,7 +305,9 @@ class Browser : public WindowListObserver {
|
||||||
|
|
||||||
std::unique_ptr<util::Promise> ready_promise_;
|
std::unique_ptr<util::Promise> ready_promise_;
|
||||||
|
|
||||||
#if defined(OS_LINUX) || defined(OS_MACOSX)
|
#if defined(OS_LINUX)
|
||||||
|
base::Value about_panel_options_;
|
||||||
|
#elif defined(OS_MACOSX)
|
||||||
base::DictionaryValue about_panel_options_;
|
base::DictionaryValue about_panel_options_;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -147,21 +147,27 @@ bool Browser::IsEmojiPanelSupported() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::ShowAboutPanel() {
|
void Browser::ShowAboutPanel() {
|
||||||
std::string app_name, version, copyright, icon_path, website;
|
|
||||||
|
|
||||||
GtkAboutDialog* dialog = GTK_ABOUT_DIALOG(gtk_about_dialog_new());
|
GtkAboutDialog* dialog = GTK_ABOUT_DIALOG(gtk_about_dialog_new());
|
||||||
|
|
||||||
if (about_panel_options_.GetString("applicationName", &app_name))
|
const auto& opts = about_panel_options_;
|
||||||
gtk_about_dialog_set_program_name(dialog, app_name.c_str());
|
const std::string* str;
|
||||||
if (about_panel_options_.GetString("applicationVersion", &version))
|
const base::Value* val;
|
||||||
gtk_about_dialog_set_version(dialog, version.c_str());
|
|
||||||
if (about_panel_options_.GetString("copyright", ©right))
|
if ((str = opts.FindStringKey("applicationName"))) {
|
||||||
gtk_about_dialog_set_copyright(dialog, copyright.c_str());
|
gtk_about_dialog_set_program_name(dialog, str->c_str());
|
||||||
if (about_panel_options_.GetString("website", &website))
|
}
|
||||||
gtk_about_dialog_set_website(dialog, website.c_str());
|
if ((str = opts.FindStringKey("applicationVersion"))) {
|
||||||
if (about_panel_options_.GetString("iconPath", &icon_path)) {
|
gtk_about_dialog_set_version(dialog, str->c_str());
|
||||||
|
}
|
||||||
|
if ((str = opts.FindStringKey("copyright"))) {
|
||||||
|
gtk_about_dialog_set_copyright(dialog, str->c_str());
|
||||||
|
}
|
||||||
|
if ((str = opts.FindStringKey("website"))) {
|
||||||
|
gtk_about_dialog_set_website(dialog, str->c_str());
|
||||||
|
}
|
||||||
|
if ((str = opts.FindStringKey("iconPath"))) {
|
||||||
GError* error = nullptr;
|
GError* error = nullptr;
|
||||||
GdkPixbuf* icon = gdk_pixbuf_new_from_file(icon_path.c_str(), &error);
|
GdkPixbuf* icon = gdk_pixbuf_new_from_file(str->c_str(), &error);
|
||||||
if (error != nullptr) {
|
if (error != nullptr) {
|
||||||
g_warning("%s", error->message);
|
g_warning("%s", error->message);
|
||||||
g_clear_error(&error);
|
g_clear_error(&error);
|
||||||
|
@ -171,19 +177,27 @@ void Browser::ShowAboutPanel() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((val = opts.FindListKey("authors"))) {
|
||||||
|
std::vector<const char*> cstrs;
|
||||||
|
for (const auto& authorVal : val->GetList()) {
|
||||||
|
if (authorVal.is_string()) {
|
||||||
|
cstrs.push_back(authorVal.GetString().c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cstrs.empty()) {
|
||||||
|
LOG(WARNING) << "No author strings found in 'authors' array";
|
||||||
|
} else {
|
||||||
|
cstrs.push_back(nullptr); // null-terminated char* array
|
||||||
|
gtk_about_dialog_set_authors(dialog, cstrs.data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gtk_dialog_run(GTK_DIALOG(dialog));
|
gtk_dialog_run(GTK_DIALOG(dialog));
|
||||||
g_clear_object(&dialog);
|
g_clear_object(&dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::SetAboutPanelOptions(const base::DictionaryValue& options) {
|
void Browser::SetAboutPanelOptions(const base::DictionaryValue& options) {
|
||||||
about_panel_options_.Clear();
|
about_panel_options_ = options.Clone();
|
||||||
|
|
||||||
for (const auto& pair : options) {
|
|
||||||
const std::string& key = pair.first;
|
|
||||||
const auto& val = pair.second;
|
|
||||||
if (!key.empty() && val->is_string())
|
|
||||||
about_panel_options_.SetString(key, val->GetString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue