Merge pull request #3278 from matrix-org/t3chguy/electron_keep_alt_menu

Allow setting in electron whether or not to auto hide menu bar
This commit is contained in:
Michael Telatynski 2019-08-06 18:20:22 +01:00 committed by GitHub
commit c022f58f3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 12 deletions

View file

@ -128,6 +128,18 @@ export default class BasePlatform {
throw new Error("Unimplemented"); throw new Error("Unimplemented");
} }
supportsAutoHideMenuBar(): boolean {
return false;
}
async getAutoHideMenuBarEnabled(): boolean {
return false;
}
async setAutoHideMenuBarEnabled(enabled: boolean): void {
throw new Error("Unimplemented");
}
supportsMinimizeToTray(): boolean { supportsMinimizeToTray(): boolean {
return false; return false;
} }

View file

@ -1,5 +1,6 @@
/* /*
Copyright 2019 New Vector Ltd Copyright 2019 New Vector Ltd
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -20,8 +21,8 @@ import {SettingLevel} from "../../../../../settings/SettingsStore";
import LabelledToggleSwitch from "../../../elements/LabelledToggleSwitch"; import LabelledToggleSwitch from "../../../elements/LabelledToggleSwitch";
import SettingsStore from "../../../../../settings/SettingsStore"; import SettingsStore from "../../../../../settings/SettingsStore";
import Field from "../../../elements/Field"; import Field from "../../../elements/Field";
const sdk = require("../../../../.."); import sdk from "../../../../..";
const PlatformPeg = require("../../../../../PlatformPeg"); import PlatformPeg from "../../../../../PlatformPeg";
export default class PreferencesUserSettingsTab extends React.Component { export default class PreferencesUserSettingsTab extends React.Component {
static COMPOSER_SETTINGS = [ static COMPOSER_SETTINGS = [
@ -64,6 +65,8 @@ export default class PreferencesUserSettingsTab extends React.Component {
this.state = { this.state = {
autoLaunch: false, autoLaunch: false,
autoLaunchSupported: false, autoLaunchSupported: false,
alwaysShowMenuBar: true,
alwaysShowMenuBarSupported: false,
minimizeToTray: true, minimizeToTray: true,
minimizeToTraySupported: false, minimizeToTraySupported: false,
autocompleteDelay: SettingsStore.getValueAt(SettingLevel.DEVICE, 'autocompleteDelay').toString(10), autocompleteDelay: SettingsStore.getValueAt(SettingLevel.DEVICE, 'autocompleteDelay').toString(10),
@ -80,6 +83,13 @@ export default class PreferencesUserSettingsTab extends React.Component {
autoLaunch = await platform.getAutoLaunchEnabled(); autoLaunch = await platform.getAutoLaunchEnabled();
} }
const alwaysShowMenuBarSupported = await platform.supportsAutoHideMenuBar();
let alwaysShowMenuBar = true;
if (alwaysShowMenuBarSupported) {
alwaysShowMenuBar = !await platform.getAutoHideMenuBarEnabled();
}
const minimizeToTraySupported = await platform.supportsMinimizeToTray(); const minimizeToTraySupported = await platform.supportsMinimizeToTray();
let minimizeToTray = true; let minimizeToTray = true;
@ -87,13 +97,24 @@ export default class PreferencesUserSettingsTab extends React.Component {
minimizeToTray = await platform.getMinimizeToTrayEnabled(); minimizeToTray = await platform.getMinimizeToTrayEnabled();
} }
this.setState({autoLaunch, autoLaunchSupported, minimizeToTraySupported, minimizeToTray}); this.setState({
autoLaunch,
autoLaunchSupported,
alwaysShowMenuBarSupported,
alwaysShowMenuBar,
minimizeToTraySupported,
minimizeToTray,
});
} }
_onAutoLaunchChange = (checked) => { _onAutoLaunchChange = (checked) => {
PlatformPeg.get().setAutoLaunchEnabled(checked).then(() => this.setState({autoLaunch: checked})); PlatformPeg.get().setAutoLaunchEnabled(checked).then(() => this.setState({autoLaunch: checked}));
}; };
_onAlwaysShowMenuBarChange = (checked) => {
PlatformPeg.get().setAutoHideMenuBarEnabled(!checked).then(() => this.setState({alwaysShowMenuBar: checked}));
};
_onMinimizeToTrayChange = (checked) => { _onMinimizeToTrayChange = (checked) => {
PlatformPeg.get().setMinimizeToTrayEnabled(checked).then(() => this.setState({minimizeToTray: checked})); PlatformPeg.get().setMinimizeToTrayEnabled(checked).then(() => this.setState({minimizeToTray: checked}));
}; };
@ -111,14 +132,24 @@ export default class PreferencesUserSettingsTab extends React.Component {
render() { render() {
let autoLaunchOption = null; let autoLaunchOption = null;
if (this.state.autoLaunchSupported) { if (this.state.autoLaunchSupported) {
autoLaunchOption = <LabelledToggleSwitch value={this.state.autoLaunch} autoLaunchOption = <LabelledToggleSwitch
value={this.state.autoLaunch}
onChange={this._onAutoLaunchChange} onChange={this._onAutoLaunchChange}
label={_t('Start automatically after system login')} />; label={_t('Start automatically after system login')} />;
} }
let autoHideMenuOption = null;
if (this.state.alwaysShowMenuBarSupported) {
autoHideMenuOption = <LabelledToggleSwitch
value={this.state.alwaysShowMenuBar}
onChange={this._onAlwaysShowMenuBarChange}
label={_t('Always show the window menu bar')} />;
}
let minimizeToTrayOption = null; let minimizeToTrayOption = null;
if (this.state.minimizeToTraySupported) { if (this.state.minimizeToTraySupported) {
minimizeToTrayOption = <LabelledToggleSwitch value={this.state.minimizeToTray} minimizeToTrayOption = <LabelledToggleSwitch
value={this.state.minimizeToTray}
onChange={this._onMinimizeToTrayChange} onChange={this._onMinimizeToTrayChange}
label={_t('Close button should minimize window to tray')} />; label={_t('Close button should minimize window to tray')} />;
} }
@ -139,8 +170,12 @@ export default class PreferencesUserSettingsTab extends React.Component {
<span className="mx_SettingsTab_subheading">{_t("Advanced")}</span> <span className="mx_SettingsTab_subheading">{_t("Advanced")}</span>
{this._renderGroup(PreferencesUserSettingsTab.ADVANCED_SETTINGS)} {this._renderGroup(PreferencesUserSettingsTab.ADVANCED_SETTINGS)}
{minimizeToTrayOption} {minimizeToTrayOption}
{autoHideMenuOption}
{autoLaunchOption} {autoLaunchOption}
<Field id={"autocompleteDelay"} label={_t('Autocomplete delay (ms)')} type='number' <Field
id={"autocompleteDelay"}
label={_t('Autocomplete delay (ms)')}
type='number'
value={this.state.autocompleteDelay} value={this.state.autocompleteDelay}
onChange={this._onAutocompleteDelayChange} /> onChange={this._onAutocompleteDelayChange} />
</div> </div>

View file

@ -591,6 +591,7 @@
"Labs": "Labs", "Labs": "Labs",
"Notifications": "Notifications", "Notifications": "Notifications",
"Start automatically after system login": "Start automatically after system login", "Start automatically after system login": "Start automatically after system login",
"Always show the window menu bar": "Always show the window menu bar",
"Close button should minimize window to tray": "Close button should minimize window to tray", "Close button should minimize window to tray": "Close button should minimize window to tray",
"Preferences": "Preferences", "Preferences": "Preferences",
"Composer": "Composer", "Composer": "Composer",