Apply strictNullChecks to src/settings/* (#10252

* Apply strictNullChecks to src/settings/*

* Fix inherited types
pull/28788/head^2
Michael Telatyński 2023-02-28 10:24:59 +00:00 committed by GitHub
parent 95223c87fe
commit eca28ac2f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 24 deletions

View File

@ -154,7 +154,7 @@ export enum KeyBindingAction {
ToggleHiddenEventVisibility = "KeyBinding.toggleHiddenEventVisibility",
}
type KeyboardShortcutSetting = IBaseSetting<KeyCombo>;
type KeyboardShortcutSetting = Omit<IBaseSetting<KeyCombo>, "supportedLevels">;
// TODO: We should figure out what to do with the keyboard shortcuts that are not handled by KeybindingManager
export type IKeyboardShortcuts = Partial<Record<KeyBindingAction, KeyboardShortcutSetting>>;

View File

@ -126,7 +126,7 @@ export interface IBaseSetting<T extends SettingValueType = SettingValueType> {
// The supported levels are required. Preferably, use the preset arrays
// at the top of this file to define this rather than a custom array.
supportedLevels?: SettingLevel[];
supportedLevels: SettingLevel[];
// Required. Can be any data type. The value specified here should match
// the data being stored (ie: if a boolean is used, the setting should

View File

@ -45,13 +45,13 @@ const defaultWatchManager = new WatchManager();
const defaultSettings: Record<string, any> = {};
const invertedDefaultSettings: Record<string, boolean> = {};
const featureNames: string[] = [];
for (const key of Object.keys(SETTINGS)) {
defaultSettings[key] = SETTINGS[key].default;
if (SETTINGS[key].isFeature) featureNames.push(key);
if (SETTINGS[key].invertedSettingName) {
// Invert now so that the rest of the system will invert it back
// to what was intended.
invertedDefaultSettings[SETTINGS[key].invertedSettingName] = !SETTINGS[key].default;
for (const key in SETTINGS) {
const setting = SETTINGS[key];
defaultSettings[key] = setting.default;
if (setting.isFeature) featureNames.push(key);
if (setting.invertedSettingName) {
// Invert now so that the rest of the system will invert it back to what was intended.
invertedDefaultSettings[setting.invertedSettingName] = !setting.default;
}
}
@ -250,7 +250,7 @@ export default class SettingsStore {
if (roomId === null) {
// Unregister all existing watchers and register the new one
rooms.forEach((roomId) => {
SettingsStore.unwatchSetting(this.monitors.get(settingName)!.get(roomId));
SettingsStore.unwatchSetting(this.monitors.get(settingName)!.get(roomId)!);
});
this.monitors.get(settingName)!.clear();
registerWatcher();

View File

@ -29,7 +29,7 @@ export default class SlidingSyncController extends SettingController {
}
public async onChange(): Promise<void> {
PlatformPeg.get().reload();
PlatformPeg.get()?.reload();
}
public get settingDisabled(): boolean {

View File

@ -53,20 +53,16 @@ export default class ThemeWatcher {
public start(): void {
this.themeWatchRef = SettingsStore.watchSetting("theme", null, this.onChange);
this.systemThemeWatchRef = SettingsStore.watchSetting("use_system_theme", null, this.onChange);
if (this.preferDark.addEventListener) {
this.preferDark.addEventListener("change", this.onChange);
this.preferLight.addEventListener("change", this.onChange);
this.preferHighContrast.addEventListener("change", this.onChange);
}
this.preferDark.addEventListener("change", this.onChange);
this.preferLight.addEventListener("change", this.onChange);
this.preferHighContrast.addEventListener("change", this.onChange);
this.dispatcherRef = dis.register(this.onAction);
}
public stop(): void {
if (this.preferDark.addEventListener) {
this.preferDark.removeEventListener("change", this.onChange);
this.preferLight.removeEventListener("change", this.onChange);
this.preferHighContrast.removeEventListener("change", this.onChange);
}
this.preferDark.removeEventListener("change", this.onChange);
this.preferLight.removeEventListener("change", this.onChange);
this.preferHighContrast.removeEventListener("change", this.onChange);
if (this.systemThemeWatchRef) SettingsStore.unwatchSetting(this.systemThemeWatchRef);
if (this.themeWatchRef) SettingsStore.unwatchSetting(this.themeWatchRef);
if (this.dispatcherRef) dis.unregister(this.dispatcherRef);
@ -144,14 +140,14 @@ export default class ThemeWatcher {
return SettingsStore.getValue("theme");
}
private themeBasedOnSystem(): string {
let newTheme: string;
private themeBasedOnSystem(): string | undefined {
let newTheme: string | undefined;
if (this.preferDark.matches) {
newTheme = "dark";
} else if (this.preferLight.matches) {
newTheme = "light";
}
if (this.preferHighContrast.matches) {
if (newTheme && this.preferHighContrast.matches) {
const hcTheme = findHighContrastTheme(newTheme);
if (hcTheme) {
newTheme = hcTheme;