зеркало из https://github.com/electron/electron.git
fix: set supported scale factors on startup (#38836)
This commit is contained in:
Родитель
2b3902e526
Коммит
f6bbc34658
|
@ -203,13 +203,6 @@ void Browser::DidFinishLaunching(base::Value::Dict launch_info) {
|
||||||
}
|
}
|
||||||
for (BrowserObserver& observer : observers_)
|
for (BrowserObserver& observer : observers_)
|
||||||
observer.OnFinishLaunching(launch_info.Clone());
|
observer.OnFinishLaunching(launch_info.Clone());
|
||||||
|
|
||||||
#if BUILDFLAG(IS_MAC)
|
|
||||||
if (dock_icon_) {
|
|
||||||
DockSetIconImage(*dock_icon_);
|
|
||||||
dock_icon_.reset();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> Browser::WhenReady(v8::Isolate* isolate) {
|
v8::Local<v8::Value> Browser::WhenReady(v8::Isolate* isolate) {
|
||||||
|
|
|
@ -25,9 +25,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if BUILDFLAG(IS_MAC)
|
#if BUILDFLAG(IS_MAC)
|
||||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
|
||||||
#include "ui/base/cocoa/secure_password_input.h"
|
#include "ui/base/cocoa/secure_password_input.h"
|
||||||
#include "ui/gfx/image/image.h"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
|
@ -341,10 +339,6 @@ class Browser : public WindowListObserver {
|
||||||
void OnWindowCloseCancelled(NativeWindow* window) override;
|
void OnWindowCloseCancelled(NativeWindow* window) override;
|
||||||
void OnWindowAllClosed() override;
|
void OnWindowAllClosed() override;
|
||||||
|
|
||||||
#if BUILDFLAG(IS_MAC)
|
|
||||||
void DockSetIconImage(gfx::Image const& icon);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Observers of the browser.
|
// Observers of the browser.
|
||||||
base::ObserverList<BrowserObserver> observers_;
|
base::ObserverList<BrowserObserver> observers_;
|
||||||
|
|
||||||
|
@ -370,10 +364,6 @@ class Browser : public WindowListObserver {
|
||||||
#if BUILDFLAG(IS_MAC)
|
#if BUILDFLAG(IS_MAC)
|
||||||
std::unique_ptr<ui::ScopedPasswordInputEnabler> password_input_enabler_;
|
std::unique_ptr<ui::ScopedPasswordInputEnabler> password_input_enabler_;
|
||||||
base::Time last_dock_show_;
|
base::Time last_dock_show_;
|
||||||
|
|
||||||
// DockSetIcon() can't set the icon if is_ready_ is false.
|
|
||||||
// This field caches it until the browser is ready. (#26604)
|
|
||||||
absl::optional<gfx::Image> dock_icon_;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
base::Value::Dict about_panel_options_;
|
base::Value::Dict about_panel_options_;
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "shell/common/gin_helper/error_thrower.h"
|
#include "shell/common/gin_helper/error_thrower.h"
|
||||||
#include "shell/common/gin_helper/promise.h"
|
#include "shell/common/gin_helper/promise.h"
|
||||||
#include "shell/common/platform_util.h"
|
#include "shell/common/platform_util.h"
|
||||||
|
#include "ui/base/resource/resource_scale_factor.h"
|
||||||
#include "ui/gfx/image/image.h"
|
#include "ui/gfx/image/image.h"
|
||||||
#include "url/gurl.h"
|
#include "url/gurl.h"
|
||||||
|
|
||||||
|
@ -501,14 +502,12 @@ void Browser::DockSetIcon(v8::Isolate* isolate, v8::Local<v8::Value> icon) {
|
||||||
image = native_image->image();
|
image = native_image->image();
|
||||||
}
|
}
|
||||||
|
|
||||||
DockSetIconImage(image);
|
// This is needed to avoid a hard CHECK when this fn is called
|
||||||
}
|
// before the browser process is ready, since supported scales
|
||||||
|
// are normally set by ui::ResourceBundle::InitSharedInstance
|
||||||
void Browser::DockSetIconImage(gfx::Image const& image) {
|
// during browser process startup.
|
||||||
if (!is_ready_) {
|
if (!is_ready())
|
||||||
dock_icon_ = image;
|
ui::SetSupportedResourceScaleFactors({ui::k100Percent});
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[AtomApplication sharedApplication]
|
[[AtomApplication sharedApplication]
|
||||||
setApplicationIconImage:image.AsNSImage()];
|
setApplicationIconImage:image.AsNSImage()];
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "gin/per_isolate_data.h"
|
#include "gin/per_isolate_data.h"
|
||||||
#include "gin/wrappable.h"
|
#include "gin/wrappable.h"
|
||||||
#include "net/base/data_url.h"
|
#include "net/base/data_url.h"
|
||||||
|
#include "shell/browser/browser.h"
|
||||||
#include "shell/common/asar/asar_util.h"
|
#include "shell/common/asar/asar_util.h"
|
||||||
#include "shell/common/gin_converters/file_path_converter.h"
|
#include "shell/common/gin_converters/file_path_converter.h"
|
||||||
#include "shell/common/gin_converters/gfx_converter.h"
|
#include "shell/common/gin_converters/gfx_converter.h"
|
||||||
|
@ -29,12 +30,14 @@
|
||||||
#include "shell/common/gin_helper/function_template_extensions.h"
|
#include "shell/common/gin_helper/function_template_extensions.h"
|
||||||
#include "shell/common/gin_helper/object_template_builder.h"
|
#include "shell/common/gin_helper/object_template_builder.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
#include "shell/common/process_util.h"
|
||||||
#include "shell/common/skia_util.h"
|
#include "shell/common/skia_util.h"
|
||||||
#include "shell/common/thread_restrictions.h"
|
#include "shell/common/thread_restrictions.h"
|
||||||
#include "third_party/skia/include/core/SkBitmap.h"
|
#include "third_party/skia/include/core/SkBitmap.h"
|
||||||
#include "third_party/skia/include/core/SkImageInfo.h"
|
#include "third_party/skia/include/core/SkImageInfo.h"
|
||||||
#include "third_party/skia/include/core/SkPixelRef.h"
|
#include "third_party/skia/include/core/SkPixelRef.h"
|
||||||
#include "ui/base/layout.h"
|
#include "ui/base/layout.h"
|
||||||
|
#include "ui/base/resource/resource_scale_factor.h"
|
||||||
#include "ui/base/webui/web_ui_util.h"
|
#include "ui/base/webui/web_ui_util.h"
|
||||||
#include "ui/gfx/codec/jpeg_codec.h"
|
#include "ui/gfx/codec/jpeg_codec.h"
|
||||||
#include "ui/gfx/codec/png_codec.h"
|
#include "ui/gfx/codec/png_codec.h"
|
||||||
|
@ -53,6 +56,18 @@ namespace electron::api {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
// This is needed to avoid a hard CHECK when certain aspects of
|
||||||
|
// ImageSkia are invoked before the browser process is ready,
|
||||||
|
// since supported scales are normally set by
|
||||||
|
// ui::ResourceBundle::InitSharedInstance during browser process startup.
|
||||||
|
void EnsureSupportedScaleFactors() {
|
||||||
|
if (!electron::IsBrowserProcess())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!Browser::Get()->is_ready())
|
||||||
|
ui::SetSupportedResourceScaleFactors({ui::k100Percent});
|
||||||
|
}
|
||||||
|
|
||||||
// Get the scale factor from options object at the first argument
|
// Get the scale factor from options object at the first argument
|
||||||
float GetScaleFactorFromOptions(gin::Arguments* args) {
|
float GetScaleFactorFromOptions(gin::Arguments* args) {
|
||||||
float scale_factor = 1.0f;
|
float scale_factor = 1.0f;
|
||||||
|
@ -108,12 +123,15 @@ base::win::ScopedHICON ReadICOFromPath(int size, const base::FilePath& path) {
|
||||||
|
|
||||||
NativeImage::NativeImage(v8::Isolate* isolate, const gfx::Image& image)
|
NativeImage::NativeImage(v8::Isolate* isolate, const gfx::Image& image)
|
||||||
: image_(image), isolate_(isolate) {
|
: image_(image), isolate_(isolate) {
|
||||||
|
EnsureSupportedScaleFactors();
|
||||||
UpdateExternalAllocatedMemoryUsage();
|
UpdateExternalAllocatedMemoryUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if BUILDFLAG(IS_WIN)
|
#if BUILDFLAG(IS_WIN)
|
||||||
NativeImage::NativeImage(v8::Isolate* isolate, const base::FilePath& hicon_path)
|
NativeImage::NativeImage(v8::Isolate* isolate, const base::FilePath& hicon_path)
|
||||||
: hicon_path_(hicon_path), isolate_(isolate) {
|
: hicon_path_(hicon_path), isolate_(isolate) {
|
||||||
|
EnsureSupportedScaleFactors();
|
||||||
|
|
||||||
// Use the 256x256 icon as fallback icon.
|
// Use the 256x256 icon as fallback icon.
|
||||||
gfx::ImageSkia image_skia;
|
gfx::ImageSkia image_skia;
|
||||||
electron::util::ReadImageSkiaFromICO(&image_skia, GetHICON(256));
|
electron::util::ReadImageSkiaFromICO(&image_skia, GetHICON(256));
|
||||||
|
|
Загрузка…
Ссылка в новой задаче