From 5e055136d68fae3581bbd83800f8e69688c30534 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 8 Jun 2022 21:41:52 +0100 Subject: [PATCH 1/7] Remove unused method `BasePlatform::screenCaptureErrorString` --- src/BasePlatform.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/BasePlatform.ts b/src/BasePlatform.ts index 630d56f06b3..6ee7d2396aa 100644 --- a/src/BasePlatform.ts +++ b/src/BasePlatform.ts @@ -225,15 +225,6 @@ export default abstract class BasePlatform { */ public abstract getAppVersion(): Promise; - /* - * If it's not expected that capturing the screen will work - * with getUserMedia, return a string explaining why not. - * Otherwise, return null. - */ - public screenCaptureErrorString(): string { - return "Not implemented"; - } - /** * Restarts the application, without necessarily reloading * any application code From 28f35a733271b0889b38f276afb4e1f562fdf611 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 8 Jun 2022 22:00:18 +0100 Subject: [PATCH 2/7] Improve platform typescripting --- src/BasePlatform.ts | 11 +++++++++++ src/dispatcher/payloads/CheckUpdatesPayload.ts | 14 ++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/BasePlatform.ts b/src/BasePlatform.ts index 6ee7d2396aa..beed1f8f7e4 100644 --- a/src/BasePlatform.ts +++ b/src/BasePlatform.ts @@ -46,6 +46,17 @@ export enum UpdateCheckStatus { Ready = "READY", } +export interface UpdateStatus { + /** + * The current phase of the manual update check. + */ + status: UpdateCheckStatus; + /** + * Detail string relating to the current status, typically for error details. + */ + detail?: string; +} + const UPDATE_DEFER_KEY = "mx_defer_update"; /** diff --git a/src/dispatcher/payloads/CheckUpdatesPayload.ts b/src/dispatcher/payloads/CheckUpdatesPayload.ts index 66a4df0fd02..44e7fd034d7 100644 --- a/src/dispatcher/payloads/CheckUpdatesPayload.ts +++ b/src/dispatcher/payloads/CheckUpdatesPayload.ts @@ -16,18 +16,8 @@ limitations under the License. import { ActionPayload } from "../payloads"; import { Action } from "../actions"; -import { UpdateCheckStatus } from "../../BasePlatform"; +import { UpdateStatus } from "../../BasePlatform"; -export interface CheckUpdatesPayload extends ActionPayload { +export interface CheckUpdatesPayload extends ActionPayload, UpdateStatus { action: Action.CheckUpdates; - - /** - * The current phase of the manual update check. - */ - status: UpdateCheckStatus; - - /** - * Detail string relating to the current status, typically for error details. - */ - detail?: string; } From 65c3c1422868d797ca3cfcc642e7acf8604f3461 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 8 Jun 2022 22:14:13 +0100 Subject: [PATCH 3/7] Remove redundant awaits --- .../settings/tabs/user/PreferencesUserSettingsTab.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx b/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx index 64f052b1ace..0f2b4a9bc3e 100644 --- a/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx @@ -134,25 +134,25 @@ export default class PreferencesUserSettingsTab extends React.Component Date: Wed, 8 Jun 2022 22:52:28 +0100 Subject: [PATCH 4/7] Abstract electron settings properly to avoid boilerplate-hell --- src/BasePlatform.ts | 57 +------ .../views/elements/SettingsFlag.tsx | 3 + .../tabs/user/PreferencesUserSettingsTab.tsx | 152 ++---------------- src/settings/SettingLevel.ts | 1 + src/settings/Settings.tsx | 28 ++++ src/settings/SettingsStore.ts | 2 + .../handlers/PlatformSettingsHandler.ts | 40 +++++ 7 files changed, 92 insertions(+), 191 deletions(-) create mode 100644 src/settings/handlers/PlatformSettingsHandler.ts diff --git a/src/BasePlatform.ts b/src/BasePlatform.ts index beed1f8f7e4..3c83229755f 100644 --- a/src/BasePlatform.ts +++ b/src/BasePlatform.ts @@ -242,64 +242,15 @@ export default abstract class BasePlatform { */ public abstract reload(): void; - public supportsAutoLaunch(): boolean { + public supportsSetting(settingName?: string): boolean { return false; } - // XXX: Surely this should be a setting like any other? - public async getAutoLaunchEnabled(): Promise { - return false; - } - - public async setAutoLaunchEnabled(enabled: boolean): Promise { - throw new Error("Unimplemented"); - } - - public supportsWarnBeforeExit(): boolean { - return false; - } - - public async shouldWarnBeforeExit(): Promise { - return false; - } - - public async setWarnBeforeExit(enabled: boolean): Promise { - throw new Error("Unimplemented"); - } - - public supportsAutoHideMenuBar(): boolean { - return false; - } - - public async getAutoHideMenuBarEnabled(): Promise { - return false; - } - - public async setAutoHideMenuBarEnabled(enabled: boolean): Promise { - throw new Error("Unimplemented"); - } - - public supportsMinimizeToTray(): boolean { - return false; - } - - public async getMinimizeToTrayEnabled(): Promise { - return false; - } - - public async setMinimizeToTrayEnabled(enabled: boolean): Promise { - throw new Error("Unimplemented"); - } - - public supportsTogglingHardwareAcceleration(): boolean { - return false; - } - - public async getHardwareAccelerationEnabled(): Promise { - return true; + public getSettingValue(settingName: string): Promise { + return undefined; } - public async setHardwareAccelerationEnabled(enabled: boolean): Promise { + public setSettingValue(settingName: string, value: any): Promise { throw new Error("Unimplemented"); } diff --git a/src/components/views/elements/SettingsFlag.tsx b/src/components/views/elements/SettingsFlag.tsx index 3437440f00f..f433613a77f 100644 --- a/src/components/views/elements/SettingsFlag.tsx +++ b/src/components/views/elements/SettingsFlag.tsx @@ -33,6 +33,7 @@ interface IProps { // XXX: once design replaces all toggles make this the default useCheckbox?: boolean; disabled?: boolean; + hideIfCannotSet?: boolean; onChange?(checked: boolean): void; } @@ -76,6 +77,8 @@ export default class SettingsFlag extends React.Component { public render() { const canChange = SettingsStore.canSetValue(this.props.name, this.props.roomId, this.props.level); + if (!canChange && this.props.hideIfCannotSet) return null; + const label = this.props.label ? _t(this.props.label) : SettingsStore.getDisplayName(this.props.name, this.props.level); diff --git a/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx b/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx index 0f2b4a9bc3e..ce698c35197 100644 --- a/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx @@ -18,10 +18,8 @@ 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 SettingsFlag from '../../../elements/SettingsFlag'; import AccessibleButton from "../../../elements/AccessibleButton"; @@ -36,16 +34,6 @@ interface IProps { } interface IState { - autoLaunch: boolean; - autoLaunchSupported: boolean; - warnBeforeExit: boolean; - warnBeforeExitSupported: boolean; - alwaysShowMenuBarSupported: boolean; - alwaysShowMenuBar: boolean; - minimizeToTraySupported: boolean; - minimizeToTray: boolean; - togglingHardwareAccelerationSupported: boolean; - enableHardwareAcceleration: boolean; autocompleteDelay: string; readMarkerInViewThresholdMs: string; readMarkerOutOfViewThresholdMs: string; @@ -112,16 +100,6 @@ export default class PreferencesUserSettingsTab extends React.Component { - 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 onHardwareAccelerationChange = (checked: boolean) => { - PlatformPeg.get().setHardwareAccelerationEnabled(checked).then( - () => this.setState({ enableHardwareAcceleration: checked })); - }; - private onAutocompleteDelayChange = (e: React.ChangeEvent) => { this.setState({ autocompleteDelay: e.target.value }); SettingsStore.setValue("autocompleteDelay", null, SettingLevel.DEVICE, e.target.value); @@ -232,49 +142,6 @@ export default class PreferencesUserSettingsTab extends React.Component; - } - - let warnBeforeExitOption = null; - if (this.state.warnBeforeExitSupported) { - warnBeforeExitOption = ; - } - - let autoHideMenuOption = null; - if (this.state.alwaysShowMenuBarSupported) { - autoHideMenuOption = ; - } - - let minimizeToTrayOption = null; - if (this.state.minimizeToTraySupported) { - minimizeToTrayOption = ; - } - - let hardwareAccelerationOption = null; - if (this.state.togglingHardwareAccelerationSupported) { - const appName = SdkConfig.get().brand; - hardwareAccelerationOption = ; - } - return (
{ _t("Preferences") }
@@ -331,11 +198,20 @@ export default class PreferencesUserSettingsTab extends React.Component { _t("General") } { this.renderGroup(PreferencesUserSettingsTab.GENERAL_SETTINGS) } - { minimizeToTrayOption } - { hardwareAccelerationOption } - { autoHideMenuOption } - { autoLaunchOption } - { warnBeforeExitOption } + + ; + ; + ; + ; + ; + { + return PlatformPeg.get().setSettingValue(settingName, newValue); + } + + public isSupported(): boolean { + return PlatformPeg.get().supportsSetting(); + } +} From 6fbb163f1abbe9159ccf26e44bdff318ebe01371 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 8 Jun 2022 22:57:31 +0100 Subject: [PATCH 5/7] i18n --- src/i18n/strings/en_EN.json | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index b87d30d8ece..2c0e7d92cdf 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -971,6 +971,11 @@ "Automatically send debug logs on any error": "Automatically send debug logs on any error", "Automatically send debug logs on decryption errors": "Automatically send debug logs on decryption errors", "Automatically send debug logs when key backup is not functioning": "Automatically send debug logs when key backup is not functioning", + "Start automatically after system login": "Start automatically after system login", + "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": "Enable hardware acceleration", "Partial Support for Threads": "Partial Support for Threads", "Your homeserver does not currently support threads, so this feature may be unreliable. Some threaded messages may not be reliably available. Learn more.": "Your homeserver does not currently support threads, so this feature may be unreliable. Some threaded messages may not be reliably available. Learn more.", "Do you want to enable threads anyway?": "Do you want to enable threads anyway?", @@ -1499,11 +1504,6 @@ "If this isn't what you want, please use a different tool to ignore users.": "If this isn't what you want, please use a different tool to ignore users.", "Room ID or address of ban list": "Room ID or address of ban list", "Subscribe": "Subscribe", - "Start automatically after system login": "Start automatically after system login", - "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", @@ -1513,6 +1513,7 @@ "Code blocks": "Code blocks", "Images, GIFs and videos": "Images, GIFs and videos", "Timeline": "Timeline", + "Enable hardware acceleration (restart %(appName)s to take effect)": "Enable hardware acceleration (restart %(appName)s to take effect)", "Autocomplete delay (ms)": "Autocomplete delay (ms)", "Read Marker lifetime (ms)": "Read Marker lifetime (ms)", "Read Marker off-screen lifetime (ms)": "Read Marker off-screen lifetime (ms)", From d42a5eb1545d80c5df3e7b9b78c3173290db92ec Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 10 Jun 2022 16:19:00 +0100 Subject: [PATCH 6/7] Fix stray semi-colons --- .../settings/tabs/user/PreferencesUserSettingsTab.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx b/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx index ce698c35197..2b67d22c0df 100644 --- a/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx @@ -199,7 +199,7 @@ export default class PreferencesUserSettingsTab extends React.Component{ _t("General") } { this.renderGroup(PreferencesUserSettingsTab.GENERAL_SETTINGS) } - ; + ; - ; - ; - ; + /> + + + Date: Fri, 10 Jun 2022 16:22:41 +0100 Subject: [PATCH 7/7] Fix setting level order for Platform settings --- src/settings/SettingsStore.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/settings/SettingsStore.ts b/src/settings/SettingsStore.ts index fbaf31528ac..4f81ad3be62 100644 --- a/src/settings/SettingsStore.ts +++ b/src/settings/SettingsStore.ts @@ -77,6 +77,14 @@ export const LEVEL_ORDER = [ SettingLevel.DEFAULT, ]; +function getLevelOrder(setting: ISetting): SettingLevel[] { + // Settings which support only a single setting level are inherently ordered + if (setting.supportedLevelsAreOrdered || setting.supportedLevels.length === 1) { + return setting.supportedLevels; + } + return LEVEL_ORDER; +} + export type CallbackFn = ( settingName: string, roomId: string, @@ -318,7 +326,7 @@ export default class SettingsStore { } const setting = SETTINGS[settingName]; - const levelOrder = (setting.supportedLevelsAreOrdered ? setting.supportedLevels : LEVEL_ORDER); + const levelOrder = getLevelOrder(setting); return SettingsStore.getValueAt(levelOrder[0], settingName, roomId, false, excludeDefault); } @@ -347,7 +355,7 @@ export default class SettingsStore { throw new Error("Setting '" + settingName + "' does not appear to be a setting."); } - const levelOrder = (setting.supportedLevelsAreOrdered ? setting.supportedLevels : LEVEL_ORDER); + const levelOrder = getLevelOrder(setting); if (!levelOrder.includes(SettingLevel.DEFAULT)) levelOrder.push(SettingLevel.DEFAULT); // always include default const minIndex = levelOrder.indexOf(level); @@ -520,7 +528,7 @@ export default class SettingsStore { throw new Error("Setting '" + settingName + "' does not appear to be a setting."); } - const levelOrder = (setting.supportedLevelsAreOrdered ? setting.supportedLevels : LEVEL_ORDER); + const levelOrder = getLevelOrder(setting); if (!levelOrder.includes(SettingLevel.DEFAULT)) levelOrder.push(SettingLevel.DEFAULT); // always include default const handlers = SettingsStore.getHandlers(settingName);