feat: add about panel customization on linux (#15658)
This commit is contained in:
		
					parent
					
						
							
								bc9a7806a5
							
						
					
				
			
			
				commit
				
					
						787dbbe610
					
				
			
		
					 5 changed files with 63 additions and 20 deletions
				
			
		| 
						 | 
					@ -1290,6 +1290,11 @@ void App::BuildPrototype(v8::Isolate* isolate,
 | 
				
			||||||
                 base::Bind(&Browser::InvalidateCurrentActivity, browser))
 | 
					                 base::Bind(&Browser::InvalidateCurrentActivity, browser))
 | 
				
			||||||
      .SetMethod("updateCurrentActivity",
 | 
					      .SetMethod("updateCurrentActivity",
 | 
				
			||||||
                 base::Bind(&Browser::UpdateCurrentActivity, browser))
 | 
					                 base::Bind(&Browser::UpdateCurrentActivity, browser))
 | 
				
			||||||
 | 
					      // TODO(juturu): Remove in 2.0, deprecate before then with warnings
 | 
				
			||||||
 | 
					      .SetMethod("moveToApplicationsFolder", &App::MoveToApplicationsFolder)
 | 
				
			||||||
 | 
					      .SetMethod("isInApplicationsFolder", &App::IsInApplicationsFolder)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#if defined(OS_MACOSX) || defined(OS_LINUX)
 | 
				
			||||||
      .SetMethod("setAboutPanelOptions",
 | 
					      .SetMethod("setAboutPanelOptions",
 | 
				
			||||||
                 base::Bind(&Browser::SetAboutPanelOptions, browser))
 | 
					                 base::Bind(&Browser::SetAboutPanelOptions, browser))
 | 
				
			||||||
      .SetMethod("showAboutPanel",
 | 
					      .SetMethod("showAboutPanel",
 | 
				
			||||||
| 
						 | 
					@ -1329,11 +1334,6 @@ void App::BuildPrototype(v8::Isolate* isolate,
 | 
				
			||||||
      .SetMethod("getAppMetrics", &App::GetAppMetrics)
 | 
					      .SetMethod("getAppMetrics", &App::GetAppMetrics)
 | 
				
			||||||
      .SetMethod("getGPUFeatureStatus", &App::GetGPUFeatureStatus)
 | 
					      .SetMethod("getGPUFeatureStatus", &App::GetGPUFeatureStatus)
 | 
				
			||||||
      .SetMethod("getGPUInfo", &App::GetGPUInfo)
 | 
					      .SetMethod("getGPUInfo", &App::GetGPUInfo)
 | 
				
			||||||
// TODO(juturu): Remove in 2.0, deprecate before then with warnings
 | 
					 | 
				
			||||||
#if defined(OS_MACOSX)
 | 
					 | 
				
			||||||
      .SetMethod("moveToApplicationsFolder", &App::MoveToApplicationsFolder)
 | 
					 | 
				
			||||||
      .SetMethod("isInApplicationsFolder", &App::IsInApplicationsFolder)
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
#if defined(MAS_BUILD)
 | 
					#if defined(MAS_BUILD)
 | 
				
			||||||
      .SetMethod("startAccessingSecurityScopedResource",
 | 
					      .SetMethod("startAccessingSecurityScopedResource",
 | 
				
			||||||
                 &App::StartAccessingSecurityScopedResource)
 | 
					                 &App::StartAccessingSecurityScopedResource)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -180,9 +180,12 @@ class Browser : public WindowListObserver {
 | 
				
			||||||
  // Set docks' icon.
 | 
					  // Set docks' icon.
 | 
				
			||||||
  void DockSetIcon(const gfx::Image& image);
 | 
					  void DockSetIcon(const gfx::Image& image);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  // defined(OS_MACOSX)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined(OS_MACOSX) || defined(OS_LINUX)
 | 
				
			||||||
  void ShowAboutPanel();
 | 
					  void ShowAboutPanel();
 | 
				
			||||||
  void SetAboutPanelOptions(const base::DictionaryValue& options);
 | 
					  void SetAboutPanelOptions(const base::DictionaryValue& options);
 | 
				
			||||||
#endif  // defined(OS_MACOSX)
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(OS_WIN)
 | 
					#if defined(OS_WIN)
 | 
				
			||||||
  struct UserTask {
 | 
					  struct UserTask {
 | 
				
			||||||
| 
						 | 
					@ -288,7 +291,7 @@ class Browser : public WindowListObserver {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  util::Promise* ready_promise_ = nullptr;
 | 
					  util::Promise* ready_promise_ = nullptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(OS_MACOSX)
 | 
					#if defined(OS_LINUX) || defined(OS_MACOSX)
 | 
				
			||||||
  base::DictionaryValue about_panel_options_;
 | 
					  base::DictionaryValue about_panel_options_;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -142,4 +142,44 @@ bool Browser::IsUnityRunning() {
 | 
				
			||||||
  return unity::IsRunning();
 | 
					  return unity::IsRunning();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Browser::ShowAboutPanel() {
 | 
				
			||||||
 | 
					  std::string app_name, version, copyright, icon_path, website;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  GtkAboutDialog* dialog = GTK_ABOUT_DIALOG(gtk_about_dialog_new());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (about_panel_options_.GetString("applicationName", &app_name))
 | 
				
			||||||
 | 
					    gtk_about_dialog_set_program_name(dialog, app_name.c_str());
 | 
				
			||||||
 | 
					  if (about_panel_options_.GetString("applicationVersion", &version))
 | 
				
			||||||
 | 
					    gtk_about_dialog_set_version(dialog, version.c_str());
 | 
				
			||||||
 | 
					  if (about_panel_options_.GetString("copyright", ©right))
 | 
				
			||||||
 | 
					    gtk_about_dialog_set_copyright(dialog, copyright.c_str());
 | 
				
			||||||
 | 
					  if (about_panel_options_.GetString("website", &website))
 | 
				
			||||||
 | 
					    gtk_about_dialog_set_website(dialog, website.c_str());
 | 
				
			||||||
 | 
					  if (about_panel_options_.GetString("iconPath", &icon_path)) {
 | 
				
			||||||
 | 
					    GError* error = nullptr;
 | 
				
			||||||
 | 
					    GdkPixbuf* icon = gdk_pixbuf_new_from_file(icon_path.c_str(), &error);
 | 
				
			||||||
 | 
					    if (error != nullptr) {
 | 
				
			||||||
 | 
					      g_warning("%s", error->message);
 | 
				
			||||||
 | 
					      g_clear_error(&error);
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      gtk_about_dialog_set_logo(dialog, icon);
 | 
				
			||||||
 | 
					      g_clear_object(&icon);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  gtk_dialog_run(GTK_DIALOG(dialog));
 | 
				
			||||||
 | 
					  g_clear_object(&dialog);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Browser::SetAboutPanelOptions(const base::DictionaryValue& options) {
 | 
				
			||||||
 | 
					  about_panel_options_.Clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  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 atom
 | 
					}  // namespace atom
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -392,13 +392,12 @@ void Browser::ShowAboutPanel() {
 | 
				
			||||||
void Browser::SetAboutPanelOptions(const base::DictionaryValue& options) {
 | 
					void Browser::SetAboutPanelOptions(const base::DictionaryValue& options) {
 | 
				
			||||||
  about_panel_options_.Clear();
 | 
					  about_panel_options_.Clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Upper case option keys for orderFrontStandardAboutPanelWithOptions format
 | 
					  for (const auto& pair : options) {
 | 
				
			||||||
  for (base::DictionaryValue::Iterator iter(options); !iter.IsAtEnd();
 | 
					    std::string key = pair.first;
 | 
				
			||||||
       iter.Advance()) {
 | 
					    const auto& val = pair.second;
 | 
				
			||||||
    std::string key = iter.key();
 | 
					    if (!key.empty() && val->is_string()) {
 | 
				
			||||||
    if (!key.empty() && iter.value().is_string()) {
 | 
					 | 
				
			||||||
      key[0] = base::ToUpperASCII(key[0]);
 | 
					      key[0] = base::ToUpperASCII(key[0]);
 | 
				
			||||||
      about_panel_options_.SetString(key, iter.value().GetString());
 | 
					      about_panel_options_.SetString(key, val->GetString());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1064,22 +1064,23 @@ details. Disabled by default.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
**Note:** Rendering accessibility tree can significantly affect the performance of your app. It should not be enabled by default.
 | 
					**Note:** Rendering accessibility tree can significantly affect the performance of your app. It should not be enabled by default.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### `app.showAboutPanel()` _macOS_
 | 
					### `app.showAboutPanel` _macOS_ _Linux_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Show the about panel with the values defined in the app's
 | 
					Show the app's about panel options. These options can be overridden with `app.setAboutPanelOptions(options)`.
 | 
				
			||||||
`.plist` file or with the options set via `app.setAboutPanelOptions(options)`.
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
### `app.setAboutPanelOptions(options)` _macOS_
 | 
					### `app.setAboutPanelOptions(options)` _macOS_ _Linux_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* `options` Object
 | 
					* `options` Object
 | 
				
			||||||
  * `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.
 | 
				
			||||||
  * `credits` String (optional) - Credit 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_
 | 
				
			||||||
 | 
					  * `website` String (optional) - The app's website. _Linux_
 | 
				
			||||||
 | 
					  * `iconPath` String (optional) - Path to the app's icon. _Linux_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Set the about panel options. This will override the values defined in the app's
 | 
					Set the about panel options. This will override the values defined in the app's
 | 
				
			||||||
`.plist` file. See the [Apple docs][about-panel-options] for more details.
 | 
					`.plist` file on MacOS. See the [Apple docs][about-panel-options] for more details. On Linux, values must be set in order to be shown; there are no defaults.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### `app.startAccessingSecurityScopedResource(bookmarkData)` _macOS (mas)_
 | 
					### `app.startAccessingSecurityScopedResource(bookmarkData)` _macOS (mas)_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue