feat: add about panel customization on Windows (#19420)
This commit is contained in:
parent
ef03c4b7bb
commit
f654da9f56
4 changed files with 58 additions and 11 deletions
|
@ -1166,21 +1166,21 @@ This API must be called after the `ready` event is emitted.
|
||||||
|
|
||||||
**[Deprecated](modernization/property-updates.md)**
|
**[Deprecated](modernization/property-updates.md)**
|
||||||
|
|
||||||
### `app.showAboutPanel()` _macOS_ _Linux_
|
### `app.showAboutPanel()`
|
||||||
|
|
||||||
Show the app's about panel options. These options can be overridden with `app.setAboutPanelOptions(options)`.
|
Show the app's about panel options. These options can be overridden with `app.setAboutPanelOptions(options)`.
|
||||||
|
|
||||||
### `app.setAboutPanelOptions(options)` _macOS_ _Linux_
|
### `app.setAboutPanelOptions(options)`
|
||||||
|
|
||||||
* `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.
|
||||||
* `version` String (optional) _macOS_ - The app's build version number.
|
* `version` String (optional) _macOS_ - The app's build version number.
|
||||||
* `credits` String (optional) _macOS_ - Credit information.
|
* `credits` String (optional) _macOS_ _Windows_ - Credit information.
|
||||||
* `authors` String[] (optional) _Linux_ - List of app authors.
|
* `authors` String[] (optional) _Linux_ - List of app authors.
|
||||||
* `website` String (optional) _Linux_ - The app's website.
|
* `website` String (optional) _Linux_ - The app's website.
|
||||||
* `iconPath` String (optional) _Linux_ - Path to the app's icon. Will be shown as 64x64 pixels while retaining aspect ratio.
|
* `iconPath` String (optional) _Linux_ _Windows_ - Path to the app's icon. On Linux, will be shown as 64x64 pixels while retaining aspect ratio.
|
||||||
|
|
||||||
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 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.
|
`.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.
|
||||||
|
|
|
@ -1462,12 +1462,10 @@ void App::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("moveToApplicationsFolder", &App::MoveToApplicationsFolder)
|
.SetMethod("moveToApplicationsFolder", &App::MoveToApplicationsFolder)
|
||||||
.SetMethod("isInApplicationsFolder", &App::IsInApplicationsFolder)
|
.SetMethod("isInApplicationsFolder", &App::IsInApplicationsFolder)
|
||||||
#endif
|
#endif
|
||||||
#if defined(OS_MACOSX) || defined(OS_LINUX)
|
|
||||||
.SetMethod("setAboutPanelOptions",
|
.SetMethod("setAboutPanelOptions",
|
||||||
base::BindRepeating(&Browser::SetAboutPanelOptions, browser))
|
base::BindRepeating(&Browser::SetAboutPanelOptions, browser))
|
||||||
.SetMethod("showAboutPanel",
|
.SetMethod("showAboutPanel",
|
||||||
base::BindRepeating(&Browser::ShowAboutPanel, browser))
|
base::BindRepeating(&Browser::ShowAboutPanel, browser))
|
||||||
#endif
|
|
||||||
#if defined(OS_MACOSX) || defined(OS_WIN)
|
#if defined(OS_MACOSX) || defined(OS_WIN)
|
||||||
.SetMethod("showEmojiPanel",
|
.SetMethod("showEmojiPanel",
|
||||||
base::BindRepeating(&Browser::ShowEmojiPanel, browser))
|
base::BindRepeating(&Browser::ShowEmojiPanel, browser))
|
||||||
|
|
|
@ -186,10 +186,8 @@ class Browser : public WindowListObserver {
|
||||||
|
|
||||||
#endif // defined(OS_MACOSX)
|
#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
|
|
||||||
|
|
||||||
#if defined(OS_MACOSX) || defined(OS_WIN)
|
#if defined(OS_MACOSX) || defined(OS_WIN)
|
||||||
void ShowEmojiPanel();
|
void ShowEmojiPanel();
|
||||||
|
@ -305,7 +303,7 @@ class Browser : public WindowListObserver {
|
||||||
|
|
||||||
std::unique_ptr<util::Promise> ready_promise_;
|
std::unique_ptr<util::Promise> ready_promise_;
|
||||||
|
|
||||||
#if defined(OS_LINUX)
|
#if defined(OS_LINUX) || defined(OS_WIN)
|
||||||
base::Value about_panel_options_;
|
base::Value about_panel_options_;
|
||||||
#elif defined(OS_MACOSX)
|
#elif defined(OS_MACOSX)
|
||||||
base::DictionaryValue about_panel_options_;
|
base::DictionaryValue about_panel_options_;
|
||||||
|
|
|
@ -22,9 +22,11 @@
|
||||||
#include "base/win/win_util.h"
|
#include "base/win/win_util.h"
|
||||||
#include "base/win/windows_version.h"
|
#include "base/win/windows_version.h"
|
||||||
#include "electron/electron_version.h"
|
#include "electron/electron_version.h"
|
||||||
|
#include "shell/browser/ui/message_box.h"
|
||||||
#include "shell/browser/ui/win/jump_list.h"
|
#include "shell/browser/ui/win/jump_list.h"
|
||||||
#include "shell/common/application_info.h"
|
#include "shell/common/application_info.h"
|
||||||
#include "shell/common/native_mate_converters/string16_converter.h"
|
#include "shell/common/native_mate_converters/string16_converter.h"
|
||||||
|
#include "shell/common/skia_util.h"
|
||||||
#include "ui/events/keycodes/keyboard_code_conversion_win.h"
|
#include "ui/events/keycodes/keyboard_code_conversion_win.h"
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
@ -83,6 +85,16 @@ bool FormatCommandLineString(base::string16* exe,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<FileVersionInfo> FetchFileVersionInfo() {
|
||||||
|
base::FilePath path;
|
||||||
|
|
||||||
|
if (base::PathService::Get(base::FILE_EXE, &path)) {
|
||||||
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||||
|
return FileVersionInfo::CreateFileVersionInfo(path);
|
||||||
|
}
|
||||||
|
return std::unique_ptr<FileVersionInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Browser::UserTask::UserTask() = default;
|
Browser::UserTask::UserTask() = default;
|
||||||
|
@ -324,8 +336,7 @@ std::string Browser::GetExecutableFileVersion() const {
|
||||||
base::FilePath path;
|
base::FilePath path;
|
||||||
if (base::PathService::Get(base::FILE_EXE, &path)) {
|
if (base::PathService::Get(base::FILE_EXE, &path)) {
|
||||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||||
std::unique_ptr<FileVersionInfo> version_info(
|
std::unique_ptr<FileVersionInfo> version_info = FetchFileVersionInfo();
|
||||||
FileVersionInfo::CreateFileVersionInfo(path));
|
|
||||||
return base::UTF16ToUTF8(version_info->product_version());
|
return base::UTF16ToUTF8(version_info->product_version());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,4 +371,44 @@ void Browser::ShowEmojiPanel() {
|
||||||
::SendInput(4, input, sizeof(INPUT));
|
::SendInput(4, input, sizeof(INPUT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Browser::ShowAboutPanel() {
|
||||||
|
base::Value dict(base::Value::Type::DICTIONARY);
|
||||||
|
std::string aboutMessage = "";
|
||||||
|
gfx::ImageSkia image;
|
||||||
|
|
||||||
|
// grab defaults from Windows .EXE file
|
||||||
|
std::unique_ptr<FileVersionInfo> exe_info = FetchFileVersionInfo();
|
||||||
|
dict.SetStringKey("applicationName", exe_info->file_description());
|
||||||
|
dict.SetStringKey("applicationVersion", exe_info->product_version());
|
||||||
|
|
||||||
|
if (about_panel_options_.is_dict()) {
|
||||||
|
dict.MergeDictionary(&about_panel_options_);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> stringOptions = {
|
||||||
|
"applicationName", "applicationVersion", "copyright", "credits"};
|
||||||
|
|
||||||
|
const std::string* str;
|
||||||
|
for (std::string opt : stringOptions) {
|
||||||
|
if ((str = dict.FindStringKey(opt))) {
|
||||||
|
aboutMessage.append(*str).append("\r\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((str = dict.FindStringKey("iconPath"))) {
|
||||||
|
base::FilePath path = base::FilePath::FromUTF8Unsafe(*str);
|
||||||
|
electron::util::PopulateImageSkiaRepsFromPath(&image, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
electron::MessageBoxSettings settings = {};
|
||||||
|
settings.message = aboutMessage;
|
||||||
|
settings.icon = image;
|
||||||
|
settings.type = electron::MessageBoxType::kInformation;
|
||||||
|
electron::ShowMessageBoxSync(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Browser::SetAboutPanelOptions(const base::DictionaryValue& options) {
|
||||||
|
about_panel_options_ = options.Clone();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue