Show all labs even if incompatible, with appropriate tooltip explaining requirements (#10369)

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
Michael Telatynski 2023-03-15 08:37:41 +00:00 committed by GitHub
parent 209b65243a
commit e3930fb8b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 156 additions and 120 deletions

View file

@ -227,9 +227,13 @@ export const SETTINGS: { [setting: string]: ISetting } = {
displayName: _td("Explore public spaces in the new search dialog"),
supportedLevels: LEVELS_FEATURE,
default: false,
controller: new ServerSupportUnstableFeatureController("feature_exploring_public_spaces", defaultWatchManager, [
"org.matrix.msc3827.stable",
]),
controller: new ServerSupportUnstableFeatureController(
"feature_exploring_public_spaces",
defaultWatchManager,
["org.matrix.msc3827.stable"],
undefined,
_td("Requires your server to support the stable version of MSC3827"),
),
},
"feature_msc3531_hide_messages_pending_moderation": {
isFeature: true,
@ -373,9 +377,13 @@ export const SETTINGS: { [setting: string]: ISetting } = {
displayName: _td("Jump to date (adds /jumptodate and jump to date headers)"),
supportedLevels: LEVELS_FEATURE,
default: false,
controller: new ServerSupportUnstableFeatureController("feature_jump_to_date", defaultWatchManager, [
"org.matrix.msc3030",
]),
controller: new ServerSupportUnstableFeatureController(
"feature_jump_to_date",
defaultWatchManager,
["org.matrix.msc3030"],
undefined,
_td("Requires your server to support MSC3030"),
),
},
"RoomList.backgroundImage": {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
@ -385,6 +393,14 @@ export const SETTINGS: { [setting: string]: ISetting } = {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
displayName: _td("Send read receipts"),
default: true,
controller: new ServerSupportUnstableFeatureController(
"sendReadReceipts",
defaultWatchManager,
["org.matrix.msc2285.stable"],
"v1.4",
_td("Your server doesn't support disabling sending read receipts."),
true,
),
},
"feature_sliding_sync": {
isFeature: true,
@ -482,7 +498,7 @@ export const SETTINGS: { [setting: string]: ISetting } = {
labsGroup: LabGroup.Developer,
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
displayName: _td("Rust cryptography implementation"),
description: _td("Under active development. Can currently only be enabled via config.json"),
description: _td("Under active development."),
// shouldWarn: true,
default: false,
controller: new RustCryptoSdkController(),

View file

@ -325,7 +325,9 @@ export default class SettingsStore {
/**
* Determines if a setting is enabled.
* If a setting is disabled then it should be hidden from the user.
* If a setting is disabled then it should normally be hidden from the user to de-clutter the user interface.
* This rule is intentionally ignored for labs flags to unveil what features are available with
* the right server support.
* @param {string} settingName The setting to look up.
* @return {boolean} True if the setting is enabled.
*/
@ -334,6 +336,18 @@ export default class SettingsStore {
return !SETTINGS[settingName].controller?.settingDisabled ?? true;
}
/**
* Retrieves the reason a setting is disabled if one is assigned.
* If a setting is not disabled, or no reason is given by the `SettingController`,
* this will return undefined.
* @param {string} settingName The setting to look up.
* @return {string} The reason the setting is disabled.
*/
public static disabledMessage(settingName: string): string | undefined {
const disabled = SETTINGS[settingName].controller?.settingDisabled;
return typeof disabled === "string" ? disabled : undefined;
}
/**
* Gets the value of a setting. The room ID is optional if the setting is not to
* be applied to any particular room, otherwise it should be supplied.

View file

@ -14,12 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { _t } from "../../languageHandler";
import SettingController from "./SettingController";
export default class RustCryptoSdkController extends SettingController {
public get settingDisabled(): boolean {
public get settingDisabled(): boolean | string {
// Currently this can only be changed via config.json. In future, we'll allow the user to *enable* this setting
// via labs, which will migrate their existing device to the rust-sdk implementation.
return true;
return _t("Can currently only be enabled via config.json");
}
}

View file

@ -32,6 +32,8 @@ export default class ServerSupportUnstableFeatureController extends MatrixClient
private readonly settingName: string,
private readonly watchers: WatchManager,
private readonly unstableFeatures: string[],
private readonly stableVersion?: string,
private readonly disabledMessage?: string,
private readonly forcedValue: any = false,
) {
super();
@ -53,10 +55,16 @@ export default class ServerSupportUnstableFeatureController extends MatrixClient
protected async initMatrixClient(oldClient: MatrixClient, newClient: MatrixClient): Promise<void> {
this.disabled = true;
let supported = true;
if (this.stableVersion && (await this.client.isVersionSupported(this.stableVersion))) {
this.disabled = false;
return;
}
for (const feature of this.unstableFeatures) {
supported = await this.client.doesServerSupportUnstableFeature(feature);
if (!supported) break;
}
this.disabled = !supported;
}
@ -72,7 +80,10 @@ export default class ServerSupportUnstableFeatureController extends MatrixClient
return null; // no override
}
public get settingDisabled(): boolean {
return this.disabled;
public get settingDisabled(): boolean | string {
if (this.disabled) {
return this.disabledMessage ?? true;
}
return false;
}
}

View file

@ -69,8 +69,9 @@ export default abstract class SettingController {
/**
* Gets whether the setting has been disabled due to this controller.
* Can also return a string with the reason the setting is disabled.
*/
public get settingDisabled(): boolean {
public get settingDisabled(): boolean | string {
return false;
}
}

View file

@ -20,6 +20,7 @@ import { SettingLevel } from "../SettingLevel";
import { SlidingSyncOptionsDialog } from "../../components/views/dialogs/SlidingSyncOptionsDialog";
import Modal from "../../Modal";
import SettingsStore from "../SettingsStore";
import { _t } from "../../languageHandler";
export default class SlidingSyncController extends SettingController {
public async beforeChange(level: SettingLevel, roomId: string, newValue: any): Promise<boolean> {
@ -32,8 +33,12 @@ export default class SlidingSyncController extends SettingController {
PlatformPeg.get()?.reload();
}
public get settingDisabled(): boolean {
public get settingDisabled(): boolean | string {
// Cannot be disabled once enabled, user has been warned and must log out and back in.
return SettingsStore.getValue("feature_sliding_sync");
if (SettingsStore.getValue("feature_sliding_sync")) {
return _t("Log out and back in to disable");
}
return false;
}
}