Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-3316] Feature addition - Toggle Hardware Acceleration [Desktop] #5968

Merged
merged 9 commits into from
Mar 21, 2024
17 changes: 17 additions & 0 deletions apps/desktop/src/app/accounts/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,23 @@ <h2>
"enableBrowserIntegrationFingerprintDesc" | i18n
}}</small>
</div>
<div class="form-group">
<div class="checkbox">
<label for="enableHardwareAcceleration">
<input
id="enableHardwareAcceleration"
type="checkbox"
aria-describedby="enableHardwareAccelerationHelp"
formControlName="enableHardwareAcceleration"
(change)="saveHardwareAcceleration()"
/>
{{ "enableHardwareAcceleration" | i18n }}
</label>
</div>
<small id="enableHardwareAccelerationHelp" class="help-block">{{
"enableHardwareAccelerationDesc" | i18n
}}</small>
</div>
<div class="form-group" *ngIf="showDuckDuckGoIntegrationOption">
<div class="checkbox">
<label for="enableDuckDuckGoBrowserIntegration">
Expand Down
6 changes: 6 additions & 0 deletions apps/desktop/src/app/accounts/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export class SettingsComponent implements OnInit {
value: false,
disabled: true,
}),
enableHardwareAcceleration: true,
enableDuckDuckGoBrowserIntegration: false,
theme: [null as ThemeType | null],
locale: [null as string | null],
Expand Down Expand Up @@ -241,6 +242,7 @@ export class SettingsComponent implements OnInit {
enableBrowserIntegration: await this.stateService.getEnableBrowserIntegration(),
enableBrowserIntegrationFingerprint:
await this.stateService.getEnableBrowserIntegrationFingerprint(),
enableHardwareAcceleration: await this.stateService.getEnableHardwareAcceleration(),
enableDuckDuckGoBrowserIntegration:
await this.stateService.getEnableDuckDuckGoBrowserIntegration(),
theme: await this.stateService.getTheme(),
Expand Down Expand Up @@ -591,6 +593,10 @@ export class SettingsComponent implements OnInit {
);
}

async saveHardwareAcceleration() {
await this.stateService.setEnableHardwareAcceleration(this.form.value.enableHardwareAcceleration);
}

async updateApproveLoginRequests() {
await this.stateService.setApproveLoginRequests(this.form.value.approveLoginRequests);
}
Expand Down
6 changes: 6 additions & 0 deletions apps/desktop/src/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,12 @@
"enableBrowserIntegrationFingerprintDesc": {
"message": "Add an additional layer of security by requiring fingerprint phrase confirmation when establishing a link between your desktop and browser. This requires user action and verification each time a connection is created."
},
"enableHardwareAcceleration": {
"message": "Use hardware acceleration"
},
"enableHardwareAccelerationDesc": {
"message": "By default this setting is ON. Turn OFF only if you experience graphical issues. Restart is required."
},
"approve": {
"message": "Approve"
},
Expand Down
9 changes: 9 additions & 0 deletions apps/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class Main {
}

bootstrap() {
this.toggleHardwareAcceleration();
this.desktopCredentialStorageListener.init();
this.windowMain.init().then(
async () => {
Expand Down Expand Up @@ -217,4 +218,12 @@ export class Main {
}
});
}

private async toggleHardwareAcceleration(): Promise<void> {
const enableHardwareRendering =
await this.stateService.getEnableHardwareAcceleration();
if (!enableHardwareRendering) {
app.disableHardwareAcceleration();
}
}
}
2 changes: 2 additions & 0 deletions libs/common/src/platform/abstractions/state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ export abstract class StateService<T extends Account = Account> {
value: boolean,
options?: StorageOptions
) => Promise<void>;
getEnableHardwareAcceleration: (options?: StorageOptions) => Promise<boolean>;
setEnableHardwareAcceleration: (value: boolean, options?: StorageOptions) => Promise<void>;
getEnableCloseToTray: (options?: StorageOptions) => Promise<boolean>;
setEnableCloseToTray: (value: boolean, options?: StorageOptions) => Promise<void>;
getEnableDuckDuckGoBrowserIntegration: (options?: StorageOptions) => Promise<boolean>;
Expand Down
1 change: 1 addition & 0 deletions libs/common/src/platform/models/domain/global-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class GlobalState {
alwaysShowDock?: boolean;
enableBrowserIntegration?: boolean;
enableBrowserIntegrationFingerprint?: boolean;
enableHardwareAcceleration?: boolean;
enableDuckDuckGoBrowserIntegration?: boolean;
region?: string;
}
18 changes: 18 additions & 0 deletions libs/common/src/platform/services/state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,24 @@ export class StateService<
);
}

async getEnableHardwareAcceleration(options?: StorageOptions): Promise<boolean> {
return (
(await this.getGlobals(this.reconcileOptions(options, await this.defaultOnDiskOptions())))
?.enableHardwareAcceleration ?? true
);
}

async setEnableHardwareAcceleration(value: boolean, options?: StorageOptions): Promise<void> {
const globals = await this.getGlobals(
this.reconcileOptions(options, await this.defaultOnDiskOptions())
);
globals.enableHardwareAcceleration = value;
await this.saveGlobals(
globals,
this.reconcileOptions(options, await this.defaultOnDiskOptions())
);
}

async getOrganizationInvitation(options?: StorageOptions): Promise<any> {
return (
await this.getGlobals(this.reconcileOptions(options, await this.defaultInMemoryOptions()))
Expand Down