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

Commit

Permalink
Add the option to disable hardware acceleration (#8655)
Browse files Browse the repository at this point in the history
  • Loading branch information
novocaine authored May 23, 2022
1 parent 1535ff0 commit 4f95983
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/BasePlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@ export default abstract class BasePlatform {
throw new Error("Unimplemented");
}

public supportsTogglingHardwareAcceleration(): boolean {
return false;
}

public async getHardwareAccelerationEnabled(): Promise<boolean> {
return true;
}

public async setHardwareAccelerationEnabled(enabled: boolean): Promise<void> {
throw new Error("Unimplemented");
}

/**
* Get our platform specific EventIndexManager.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import dis from "../../../../../dispatcher/dispatcher";
import { UserTab } from "../../../dialogs/UserTab";
import { OpenToTabPayload } from "../../../../../dispatcher/payloads/OpenToTabPayload";
import { Action } from "../../../../../dispatcher/actions";
import SdkConfig from "../../../../../SdkConfig";

interface IProps {
closeSettingsFn(success: boolean): void;
Expand All @@ -43,6 +44,8 @@ interface IState {
alwaysShowMenuBar: boolean;
minimizeToTraySupported: boolean;
minimizeToTray: boolean;
togglingHardwareAccelerationSupported: boolean;
enableHardwareAcceleration: boolean;
autocompleteDelay: string;
readMarkerInViewThresholdMs: string;
readMarkerOutOfViewThresholdMs: string;
Expand Down Expand Up @@ -117,6 +120,8 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
alwaysShowMenuBarSupported: false,
minimizeToTray: true,
minimizeToTraySupported: false,
enableHardwareAcceleration: true,
togglingHardwareAccelerationSupported: false,
autocompleteDelay:
SettingsStore.getValueAt(SettingLevel.DEVICE, 'autocompleteDelay').toString(10),
readMarkerInViewThresholdMs:
Expand Down Expand Up @@ -153,6 +158,12 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
minimizeToTray = await platform.getMinimizeToTrayEnabled();
}

const togglingHardwareAccelerationSupported = platform.supportsTogglingHardwareAcceleration();
let enableHardwareAcceleration = true;
if (togglingHardwareAccelerationSupported) {
enableHardwareAcceleration = await platform.getHardwareAccelerationEnabled();
}

this.setState({
autoLaunch,
autoLaunchSupported,
Expand All @@ -162,6 +173,8 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
alwaysShowMenuBar,
minimizeToTraySupported,
minimizeToTray,
togglingHardwareAccelerationSupported,
enableHardwareAcceleration,
});
}

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

private onHardwareAccelerationChange = (checked: boolean) => {
PlatformPeg.get().setHardwareAccelerationEnabled(checked).then(
() => this.setState({ enableHardwareAcceleration: checked }));
};

private onAutocompleteDelayChange = (e: React.ChangeEvent<HTMLInputElement>) => {
this.setState({ autocompleteDelay: e.target.value });
SettingsStore.setValue("autocompleteDelay", null, SettingLevel.DEVICE, e.target.value);
Expand Down Expand Up @@ -246,6 +264,17 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
label={_t('Show tray icon and minimise window to it on close')} />;
}

let hardwareAccelerationOption = null;
if (this.state.togglingHardwareAccelerationSupported) {
const appName = SdkConfig.get().brand;
hardwareAccelerationOption = <LabelledToggleSwitch
value={this.state.enableHardwareAcceleration}
onChange={this.onHardwareAccelerationChange}
label={_t('Enable hardware acceleration (restart %(appName)s to take effect)', {
appName,
})} />;
}

return (
<div className="mx_SettingsTab mx_PreferencesUserSettingsTab">
<div className="mx_SettingsTab_heading">{ _t("Preferences") }</div>
Expand Down Expand Up @@ -303,6 +332,7 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
<span className="mx_SettingsTab_subheading">{ _t("General") }</span>
{ this.renderGroup(PreferencesUserSettingsTab.GENERAL_SETTINGS) }
{ minimizeToTrayOption }
{ hardwareAccelerationOption }
{ autoHideMenuOption }
{ autoLaunchOption }
{ warnBeforeExitOption }
Expand Down
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,7 @@
"Warn before quitting": "Warn before quitting",
"Always show the window menu bar": "Always show the window menu bar",
"Show tray icon and minimise window to it on close": "Show tray icon and minimise window to it on close",
"Enable hardware acceleration (restart %(appName)s to take effect)": "Enable hardware acceleration (restart %(appName)s to take effect)",
"Preferences": "Preferences",
"Room list": "Room list",
"Keyboard shortcuts": "Keyboard shortcuts",
Expand Down

0 comments on commit 4f95983

Please sign in to comment.