Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 4f95983

Browse files
authored
Add the option to disable hardware acceleration (#8655)
1 parent 1535ff0 commit 4f95983

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

src/BasePlatform.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,18 @@ export default abstract class BasePlatform {
291291
throw new Error("Unimplemented");
292292
}
293293

294+
public supportsTogglingHardwareAcceleration(): boolean {
295+
return false;
296+
}
297+
298+
public async getHardwareAccelerationEnabled(): Promise<boolean> {
299+
return true;
300+
}
301+
302+
public async setHardwareAccelerationEnabled(enabled: boolean): Promise<void> {
303+
throw new Error("Unimplemented");
304+
}
305+
294306
/**
295307
* Get our platform specific EventIndexManager.
296308
*

src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import dis from "../../../../../dispatcher/dispatcher";
2929
import { UserTab } from "../../../dialogs/UserTab";
3030
import { OpenToTabPayload } from "../../../../../dispatcher/payloads/OpenToTabPayload";
3131
import { Action } from "../../../../../dispatcher/actions";
32+
import SdkConfig from "../../../../../SdkConfig";
3233

3334
interface IProps {
3435
closeSettingsFn(success: boolean): void;
@@ -43,6 +44,8 @@ interface IState {
4344
alwaysShowMenuBar: boolean;
4445
minimizeToTraySupported: boolean;
4546
minimizeToTray: boolean;
47+
togglingHardwareAccelerationSupported: boolean;
48+
enableHardwareAcceleration: boolean;
4649
autocompleteDelay: string;
4750
readMarkerInViewThresholdMs: string;
4851
readMarkerOutOfViewThresholdMs: string;
@@ -117,6 +120,8 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
117120
alwaysShowMenuBarSupported: false,
118121
minimizeToTray: true,
119122
minimizeToTraySupported: false,
123+
enableHardwareAcceleration: true,
124+
togglingHardwareAccelerationSupported: false,
120125
autocompleteDelay:
121126
SettingsStore.getValueAt(SettingLevel.DEVICE, 'autocompleteDelay').toString(10),
122127
readMarkerInViewThresholdMs:
@@ -153,6 +158,12 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
153158
minimizeToTray = await platform.getMinimizeToTrayEnabled();
154159
}
155160

161+
const togglingHardwareAccelerationSupported = platform.supportsTogglingHardwareAcceleration();
162+
let enableHardwareAcceleration = true;
163+
if (togglingHardwareAccelerationSupported) {
164+
enableHardwareAcceleration = await platform.getHardwareAccelerationEnabled();
165+
}
166+
156167
this.setState({
157168
autoLaunch,
158169
autoLaunchSupported,
@@ -162,6 +173,8 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
162173
alwaysShowMenuBar,
163174
minimizeToTraySupported,
164175
minimizeToTray,
176+
togglingHardwareAccelerationSupported,
177+
enableHardwareAcceleration,
165178
});
166179
}
167180

@@ -181,6 +194,11 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
181194
PlatformPeg.get().setMinimizeToTrayEnabled(checked).then(() => this.setState({ minimizeToTray: checked }));
182195
};
183196

197+
private onHardwareAccelerationChange = (checked: boolean) => {
198+
PlatformPeg.get().setHardwareAccelerationEnabled(checked).then(
199+
() => this.setState({ enableHardwareAcceleration: checked }));
200+
};
201+
184202
private onAutocompleteDelayChange = (e: React.ChangeEvent<HTMLInputElement>) => {
185203
this.setState({ autocompleteDelay: e.target.value });
186204
SettingsStore.setValue("autocompleteDelay", null, SettingLevel.DEVICE, e.target.value);
@@ -246,6 +264,17 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
246264
label={_t('Show tray icon and minimise window to it on close')} />;
247265
}
248266

267+
let hardwareAccelerationOption = null;
268+
if (this.state.togglingHardwareAccelerationSupported) {
269+
const appName = SdkConfig.get().brand;
270+
hardwareAccelerationOption = <LabelledToggleSwitch
271+
value={this.state.enableHardwareAcceleration}
272+
onChange={this.onHardwareAccelerationChange}
273+
label={_t('Enable hardware acceleration (restart %(appName)s to take effect)', {
274+
appName,
275+
})} />;
276+
}
277+
249278
return (
250279
<div className="mx_SettingsTab mx_PreferencesUserSettingsTab">
251280
<div className="mx_SettingsTab_heading">{ _t("Preferences") }</div>
@@ -303,6 +332,7 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
303332
<span className="mx_SettingsTab_subheading">{ _t("General") }</span>
304333
{ this.renderGroup(PreferencesUserSettingsTab.GENERAL_SETTINGS) }
305334
{ minimizeToTrayOption }
335+
{ hardwareAccelerationOption }
306336
{ autoHideMenuOption }
307337
{ autoLaunchOption }
308338
{ warnBeforeExitOption }

src/i18n/strings/en_EN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,7 @@
15001500
"Warn before quitting": "Warn before quitting",
15011501
"Always show the window menu bar": "Always show the window menu bar",
15021502
"Show tray icon and minimise window to it on close": "Show tray icon and minimise window to it on close",
1503+
"Enable hardware acceleration (restart %(appName)s to take effect)": "Enable hardware acceleration (restart %(appName)s to take effect)",
15031504
"Preferences": "Preferences",
15041505
"Room list": "Room list",
15051506
"Keyboard shortcuts": "Keyboard shortcuts",

0 commit comments

Comments
 (0)