/* Copyright 2019-2021 The Matrix.org Foundation C.I.C. Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import React from 'react'; import { _t } from "../../../../../languageHandler"; import LabelledToggleSwitch from "../../../elements/LabelledToggleSwitch"; import SettingsStore from "../../../../../settings/SettingsStore"; import Field from "../../../elements/Field"; import PlatformPeg from "../../../../../PlatformPeg"; import { SettingLevel } from "../../../../../settings/SettingLevel"; import { replaceableComponent } from "../../../../../utils/replaceableComponent"; import SettingsFlag from '../../../elements/SettingsFlag'; import * as KeyboardShortcuts from "../../../../../accessibility/KeyboardShortcuts"; import AccessibleButton from "../../../elements/AccessibleButton"; interface IState { autoLaunch: boolean; autoLaunchSupported: boolean; warnBeforeExit: boolean; warnBeforeExitSupported: boolean; alwaysShowMenuBarSupported: boolean; alwaysShowMenuBar: boolean; minimizeToTraySupported: boolean; minimizeToTray: boolean; autocompleteDelay: string; readMarkerInViewThresholdMs: string; readMarkerOutOfViewThresholdMs: string; } @replaceableComponent("views.settings.tabs.user.PreferencesUserSettingsTab") export default class PreferencesUserSettingsTab extends React.Component<{}, IState> { static ROOM_LIST_SETTINGS = [ 'breadcrumbs', ]; static KEYBINDINGS_SETTINGS = [ 'ctrlFForSearch', ]; static COMPOSER_SETTINGS = [ 'MessageComposerInput.autoReplaceEmoji', 'MessageComposerInput.suggestEmoji', 'sendTypingNotifications', 'MessageComposerInput.ctrlEnterToSend', 'MessageComposerInput.showStickersButton', ]; static TIME_SETTINGS = [ 'showTwelveHourTimestamps', 'alwaysShowTimestamps', ]; static CODE_BLOCKS_SETTINGS = [ 'enableSyntaxHighlightLanguageDetection', 'expandCodeByDefault', 'showCodeLineNumbers', ]; static IMAGES_AND_VIDEOS_SETTINGS = [ 'urlPreviewsEnabled', 'autoplayGifsAndVideos', 'showImages', ]; static TIMELINE_SETTINGS = [ 'showTypingNotifications', 'showRedactions', 'showReadReceipts', 'showJoinLeaves', 'showDisplaynameChanges', 'showChatEffects', 'showAvatarChanges', 'Pill.shouldShowPillAvatar', 'TextualBody.enableBigEmoji', 'scrollToBottomOnMessageSent', ]; static GENERAL_SETTINGS = [ 'TagPanel.enableTagPanel', 'promptBeforeInviteUnknownUsers', // Start automatically after startup (electron-only) // Autocomplete delay (niche text box) ]; constructor(props) { super(props); this.state = { autoLaunch: false, autoLaunchSupported: false, warnBeforeExit: true, warnBeforeExitSupported: false, alwaysShowMenuBar: true, alwaysShowMenuBarSupported: false, minimizeToTray: true, minimizeToTraySupported: false, autocompleteDelay: SettingsStore.getValueAt(SettingLevel.DEVICE, 'autocompleteDelay').toString(10), readMarkerInViewThresholdMs: SettingsStore.getValueAt(SettingLevel.DEVICE, 'readMarkerInViewThresholdMs').toString(10), readMarkerOutOfViewThresholdMs: SettingsStore.getValueAt(SettingLevel.DEVICE, 'readMarkerOutOfViewThresholdMs').toString(10), }; } async componentDidMount() { const platform = PlatformPeg.get(); const autoLaunchSupported = await platform.supportsAutoLaunch(); let autoLaunch = false; if (autoLaunchSupported) { autoLaunch = await platform.getAutoLaunchEnabled(); } const warnBeforeExitSupported = await platform.supportsWarnBeforeExit(); let warnBeforeExit = false; if (warnBeforeExitSupported) { warnBeforeExit = await platform.shouldWarnBeforeExit(); } const alwaysShowMenuBarSupported = await platform.supportsAutoHideMenuBar(); let alwaysShowMenuBar = true; if (alwaysShowMenuBarSupported) { alwaysShowMenuBar = !await platform.getAutoHideMenuBarEnabled(); } const minimizeToTraySupported = await platform.supportsMinimizeToTray(); let minimizeToTray = true; if (minimizeToTraySupported) { minimizeToTray = await platform.getMinimizeToTrayEnabled(); } this.setState({ autoLaunch, autoLaunchSupported, warnBeforeExit, warnBeforeExitSupported, alwaysShowMenuBarSupported, alwaysShowMenuBar, minimizeToTraySupported, minimizeToTray, }); } private onAutoLaunchChange = (checked: boolean) => { PlatformPeg.get().setAutoLaunchEnabled(checked).then(() => this.setState({ autoLaunch: checked })); }; private onWarnBeforeExitChange = (checked: boolean) => { PlatformPeg.get().setWarnBeforeExit(checked).then(() => this.setState({ warnBeforeExit: checked })); }; private onAlwaysShowMenuBarChange = (checked: boolean) => { PlatformPeg.get().setAutoHideMenuBarEnabled(!checked).then(() => this.setState({ alwaysShowMenuBar: checked })); }; private onMinimizeToTrayChange = (checked: boolean) => { PlatformPeg.get().setMinimizeToTrayEnabled(checked).then(() => this.setState({ minimizeToTray: checked })); }; private onAutocompleteDelayChange = (e: React.ChangeEvent) => { this.setState({ autocompleteDelay: e.target.value }); SettingsStore.setValue("autocompleteDelay", null, SettingLevel.DEVICE, e.target.value); }; private onReadMarkerInViewThresholdMs = (e: React.ChangeEvent) => { this.setState({ readMarkerInViewThresholdMs: e.target.value }); SettingsStore.setValue("readMarkerInViewThresholdMs", null, SettingLevel.DEVICE, e.target.value); }; private onReadMarkerOutOfViewThresholdMs = (e: React.ChangeEvent) => { this.setState({ readMarkerOutOfViewThresholdMs: e.target.value }); SettingsStore.setValue("readMarkerOutOfViewThresholdMs", null, SettingLevel.DEVICE, e.target.value); }; private renderGroup(settingIds: string[]): React.ReactNodeArray { return settingIds.filter(SettingsStore.isEnabled).map(i => { return ; }); } render() { let autoLaunchOption = null; if (this.state.autoLaunchSupported) { autoLaunchOption = ; } let warnBeforeExitOption = null; if (this.state.warnBeforeExitSupported) { warnBeforeExitOption = ; } let autoHideMenuOption = null; if (this.state.alwaysShowMenuBarSupported) { autoHideMenuOption = ; } let minimizeToTrayOption = null; if (this.state.minimizeToTraySupported) { minimizeToTrayOption = ; } return (
{_t("Preferences")}
{_t("Room list")} {this.renderGroup(PreferencesUserSettingsTab.ROOM_LIST_SETTINGS)}
{_t("Keyboard shortcuts")} { _t("To view all keyboard shortcuts, click here.") } {this.renderGroup(PreferencesUserSettingsTab.KEYBINDINGS_SETTINGS)}
{_t("Displaying time")} {this.renderGroup(PreferencesUserSettingsTab.TIME_SETTINGS)}
{_t("Composer")} {this.renderGroup(PreferencesUserSettingsTab.COMPOSER_SETTINGS)}
{_t("Code blocks")} {this.renderGroup(PreferencesUserSettingsTab.CODE_BLOCKS_SETTINGS)}
{_t("Images, GIFs and videos")} {this.renderGroup(PreferencesUserSettingsTab.IMAGES_AND_VIDEOS_SETTINGS)}
{_t("Timeline")} {this.renderGroup(PreferencesUserSettingsTab.TIMELINE_SETTINGS)}
{_t("General")} {this.renderGroup(PreferencesUserSettingsTab.GENERAL_SETTINGS)} {minimizeToTrayOption} {autoHideMenuOption} {autoLaunchOption} {warnBeforeExitOption}
); } }