mirror of
https://github.com/vector-im/element-web.git
synced 2026-05-06 04:36:21 +02:00
Add new incompatible controllers.
This commit is contained in:
parent
eade32a80c
commit
acd9d6d867
54
src/settings/controllers/CombinationIncompatbleController.ts
Normal file
54
src/settings/controllers/CombinationIncompatbleController.ts
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import SettingController from "./SettingController.ts";
|
||||
import { type SettingLevel } from "../SettingLevel.ts";
|
||||
import IncompatibleController from "./IncompatibleController.ts";
|
||||
import IncompatibleConfigController from "./IncompatibleConfigController.ts";
|
||||
|
||||
/**
|
||||
* Enforces that a boolean setting cannot be enabled if the incompatible setting
|
||||
* is also enabled, to prevent cascading undefined behaviour between conflicting
|
||||
* labs flags.
|
||||
*/
|
||||
export default class CombinationIncompatbleController extends SettingController {
|
||||
public constructor(
|
||||
private readonly controllers: (IncompatibleConfigController|IncompatibleController)[]
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
public getValueOverride(
|
||||
level: SettingLevel,
|
||||
roomId: string,
|
||||
calculatedValue: any,
|
||||
calculatedAtLevel: SettingLevel | null,
|
||||
): any {
|
||||
for (const controller of this.controllers) {
|
||||
const res = controller.getValueOverride(level, roomId, calculatedValue, calculatedAtLevel);
|
||||
if (res !== null) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public get settingDisabled(): boolean|string {
|
||||
for (const controller of this.controllers) {
|
||||
const res = controller.settingDisabled;
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public get incompatibleSetting(): boolean {
|
||||
return this.controllers.some(s => s.incompatibleSetting);
|
||||
}
|
||||
}
|
||||
57
src/settings/controllers/IncompatibleConfigController.ts
Normal file
57
src/settings/controllers/IncompatibleConfigController.ts
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import SettingController from "./SettingController.ts";
|
||||
import { type SettingLevel } from "../SettingLevel.ts";
|
||||
import { IConfigOptions } from "../../IConfigOptions.ts";
|
||||
import SdkConfig from "../../SdkConfig.ts";
|
||||
|
||||
/**
|
||||
* Enforces that a boolean setting cannot be enabled if the incompatible setting
|
||||
* is also enabled, to prevent cascading undefined behaviour between conflicting
|
||||
* labs flags.
|
||||
*/
|
||||
export default class IncompatibleConfigController extends SettingController {
|
||||
public constructor(
|
||||
private readonly getSetting: (c: IConfigOptions) => boolean,
|
||||
private forcedValue: any = false,
|
||||
private incompatibleValue: any | ((v: any) => boolean) = true,
|
||||
private readonly disabledString?: string,
|
||||
) {
|
||||
super();
|
||||
console.log(SdkConfig.get());
|
||||
}
|
||||
|
||||
public getValueOverride(
|
||||
level: SettingLevel,
|
||||
roomId: string,
|
||||
calculatedValue: any,
|
||||
calculatedAtLevel: SettingLevel | null,
|
||||
): any {
|
||||
if (this.incompatibleSetting) {
|
||||
return this.forcedValue;
|
||||
}
|
||||
return null; // no override
|
||||
}
|
||||
|
||||
public get configSettingValue(): boolean {
|
||||
return this.getSetting(SdkConfig.get());
|
||||
}
|
||||
|
||||
public get settingDisabled(): boolean|string {
|
||||
console.log("IncompatibleConfigController", this.configSettingValue, this.incompatibleSetting ? (this.disabledString ?? true) : false);
|
||||
return this.incompatibleSetting ? (this.disabledString ?? true) : false;
|
||||
}
|
||||
|
||||
public get incompatibleSetting(): boolean {
|
||||
if (typeof this.incompatibleValue === "function") {
|
||||
return this.incompatibleValue(this.configSettingValue);
|
||||
}
|
||||
return this.configSettingValue === this.incompatibleValue;
|
||||
}
|
||||
}
|
||||
@ -21,6 +21,7 @@ export default class IncompatibleController extends SettingController {
|
||||
private settingName: BooleanSettingKey,
|
||||
private forcedValue: any = false,
|
||||
private incompatibleValue: any | ((v: any) => boolean) = true,
|
||||
private readonly disabledString?: string,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
@ -37,8 +38,8 @@ export default class IncompatibleController extends SettingController {
|
||||
return null; // no override
|
||||
}
|
||||
|
||||
public get settingDisabled(): boolean {
|
||||
return this.incompatibleSetting;
|
||||
public get settingDisabled(): boolean|string {
|
||||
return this.incompatibleSetting ? (this.disabledString ?? true) : false;
|
||||
}
|
||||
|
||||
public get incompatibleSetting(): boolean {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user