diff --git a/docs/api/app.md b/docs/api/app.md index 8b1d7117db..283f826028 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -1214,6 +1214,13 @@ Disables hardware acceleration for current app. This method can only be called before app is ready. +### `app.isHardwareAccelerationEnabled()` + +Returns `boolean` - whether hardware acceleration is currently disabled. + + > [!NOTE] + > This information is only usable after the `gpu-info-update` event is emitted. + ### `app.disableDomainBlockingFor3DAPIs()` By default, Chromium disables 3D APIs (e.g. WebGL) until restart on a per diff --git a/shell/browser/api/electron_api_app.cc b/shell/browser/api/electron_api_app.cc index ec2cdf6e4b..8386f12004 100644 --- a/shell/browser/api/electron_api_app.cc +++ b/shell/browser/api/electron_api_app.cc @@ -1135,6 +1135,10 @@ void App::DisableHardwareAcceleration(gin_helper::ErrorThrower thrower) { "before app is ready"); return; } + + // If the GpuDataManager is already initialized, disable hardware + // acceleration immediately. Otherwise, set a flag to disable it in + // OnPreCreateThreads(). if (content::GpuDataManager::Initialized()) { content::GpuDataManager::GetInstance()->DisableHardwareAcceleration(); } else { @@ -1142,6 +1146,13 @@ void App::DisableHardwareAcceleration(gin_helper::ErrorThrower thrower) { } } +bool App::IsHardwareAccelerationEnabled() { + if (content::GpuDataManager::Initialized()) + return content::GpuDataManager::GetInstance() + ->HardwareAccelerationEnabled(); + return !disable_hw_acceleration_; +} + void App::DisableDomainBlockingFor3DAPIs(gin_helper::ErrorThrower thrower) { if (Browser::Get()->is_ready()) { thrower.ThrowError( @@ -1909,6 +1920,8 @@ gin::ObjectTemplateBuilder App::GetObjectTemplateBuilder(v8::Isolate* isolate) { &App::SetAccessibilitySupportEnabled) .SetMethod("disableHardwareAcceleration", &App::DisableHardwareAcceleration) + .SetMethod("isHardwareAccelerationEnabled", + &App::IsHardwareAccelerationEnabled) .SetMethod("disableDomainBlockingFor3DAPIs", &App::DisableDomainBlockingFor3DAPIs) .SetMethod("getFileIcon", &App::GetFileIcon) diff --git a/shell/browser/api/electron_api_app.h b/shell/browser/api/electron_api_app.h index be43d7ad47..f828e622ed 100644 --- a/shell/browser/api/electron_api_app.h +++ b/shell/browser/api/electron_api_app.h @@ -207,6 +207,7 @@ class App final : public ElectronBrowserClient::Delegate, void ReleaseSingleInstanceLock(); bool Relaunch(gin::Arguments* args); void DisableHardwareAcceleration(gin_helper::ErrorThrower thrower); + bool IsHardwareAccelerationEnabled(); void DisableDomainBlockingFor3DAPIs(gin_helper::ErrorThrower thrower); bool IsAccessibilitySupportEnabled(); v8::Local GetAccessibilitySupportFeatures(); diff --git a/spec/api-app-spec.ts b/spec/api-app-spec.ts index 30e5e96abc..81ab51f10e 100644 --- a/spec/api-app-spec.ts +++ b/spec/api-app-spec.ts @@ -149,6 +149,12 @@ describe('app module', () => { }); }); + describe('app.isHardwareAccelerationEnabled()', () => { + it('should be a boolean', () => { + expect(app.isHardwareAccelerationEnabled()).to.be.a('boolean'); + }); + }); + describe('app.isPackaged', () => { it('should be false during tests', () => { expect(app.isPackaged).to.equal(false);