Apply strictNullChecks to src/settings/* (#10252
* Apply strictNullChecks to src/settings/* * Fix inherited typespull/28788/head^2
parent
95223c87fe
commit
eca28ac2f3
|
@ -154,7 +154,7 @@ export enum KeyBindingAction {
|
||||||
ToggleHiddenEventVisibility = "KeyBinding.toggleHiddenEventVisibility",
|
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
|
// 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>>;
|
export type IKeyboardShortcuts = Partial<Record<KeyBindingAction, KeyboardShortcutSetting>>;
|
||||||
|
|
|
@ -126,7 +126,7 @@ export interface IBaseSetting<T extends SettingValueType = SettingValueType> {
|
||||||
|
|
||||||
// The supported levels are required. Preferably, use the preset arrays
|
// The supported levels are required. Preferably, use the preset arrays
|
||||||
// at the top of this file to define this rather than a custom array.
|
// 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
|
// 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
|
// the data being stored (ie: if a boolean is used, the setting should
|
||||||
|
|
|
@ -45,13 +45,13 @@ const defaultWatchManager = new WatchManager();
|
||||||
const defaultSettings: Record<string, any> = {};
|
const defaultSettings: Record<string, any> = {};
|
||||||
const invertedDefaultSettings: Record<string, boolean> = {};
|
const invertedDefaultSettings: Record<string, boolean> = {};
|
||||||
const featureNames: string[] = [];
|
const featureNames: string[] = [];
|
||||||
for (const key of Object.keys(SETTINGS)) {
|
for (const key in SETTINGS) {
|
||||||
defaultSettings[key] = SETTINGS[key].default;
|
const setting = SETTINGS[key];
|
||||||
if (SETTINGS[key].isFeature) featureNames.push(key);
|
defaultSettings[key] = setting.default;
|
||||||
if (SETTINGS[key].invertedSettingName) {
|
if (setting.isFeature) featureNames.push(key);
|
||||||
// Invert now so that the rest of the system will invert it back
|
if (setting.invertedSettingName) {
|
||||||
// to what was intended.
|
// Invert now so that the rest of the system will invert it back to what was intended.
|
||||||
invertedDefaultSettings[SETTINGS[key].invertedSettingName] = !SETTINGS[key].default;
|
invertedDefaultSettings[setting.invertedSettingName] = !setting.default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +250,7 @@ export default class SettingsStore {
|
||||||
if (roomId === null) {
|
if (roomId === null) {
|
||||||
// Unregister all existing watchers and register the new one
|
// Unregister all existing watchers and register the new one
|
||||||
rooms.forEach((roomId) => {
|
rooms.forEach((roomId) => {
|
||||||
SettingsStore.unwatchSetting(this.monitors.get(settingName)!.get(roomId));
|
SettingsStore.unwatchSetting(this.monitors.get(settingName)!.get(roomId)!);
|
||||||
});
|
});
|
||||||
this.monitors.get(settingName)!.clear();
|
this.monitors.get(settingName)!.clear();
|
||||||
registerWatcher();
|
registerWatcher();
|
||||||
|
|
|
@ -29,7 +29,7 @@ export default class SlidingSyncController extends SettingController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async onChange(): Promise<void> {
|
public async onChange(): Promise<void> {
|
||||||
PlatformPeg.get().reload();
|
PlatformPeg.get()?.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
public get settingDisabled(): boolean {
|
public get settingDisabled(): boolean {
|
||||||
|
|
|
@ -53,20 +53,16 @@ export default class ThemeWatcher {
|
||||||
public start(): void {
|
public start(): void {
|
||||||
this.themeWatchRef = SettingsStore.watchSetting("theme", null, this.onChange);
|
this.themeWatchRef = SettingsStore.watchSetting("theme", null, this.onChange);
|
||||||
this.systemThemeWatchRef = SettingsStore.watchSetting("use_system_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.preferDark.addEventListener("change", this.onChange);
|
this.preferLight.addEventListener("change", this.onChange);
|
||||||
this.preferLight.addEventListener("change", this.onChange);
|
this.preferHighContrast.addEventListener("change", this.onChange);
|
||||||
this.preferHighContrast.addEventListener("change", this.onChange);
|
|
||||||
}
|
|
||||||
this.dispatcherRef = dis.register(this.onAction);
|
this.dispatcherRef = dis.register(this.onAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
public stop(): void {
|
public stop(): void {
|
||||||
if (this.preferDark.addEventListener) {
|
this.preferDark.removeEventListener("change", this.onChange);
|
||||||
this.preferDark.removeEventListener("change", this.onChange);
|
this.preferLight.removeEventListener("change", this.onChange);
|
||||||
this.preferLight.removeEventListener("change", this.onChange);
|
this.preferHighContrast.removeEventListener("change", this.onChange);
|
||||||
this.preferHighContrast.removeEventListener("change", this.onChange);
|
|
||||||
}
|
|
||||||
if (this.systemThemeWatchRef) SettingsStore.unwatchSetting(this.systemThemeWatchRef);
|
if (this.systemThemeWatchRef) SettingsStore.unwatchSetting(this.systemThemeWatchRef);
|
||||||
if (this.themeWatchRef) SettingsStore.unwatchSetting(this.themeWatchRef);
|
if (this.themeWatchRef) SettingsStore.unwatchSetting(this.themeWatchRef);
|
||||||
if (this.dispatcherRef) dis.unregister(this.dispatcherRef);
|
if (this.dispatcherRef) dis.unregister(this.dispatcherRef);
|
||||||
|
@ -144,14 +140,14 @@ export default class ThemeWatcher {
|
||||||
return SettingsStore.getValue("theme");
|
return SettingsStore.getValue("theme");
|
||||||
}
|
}
|
||||||
|
|
||||||
private themeBasedOnSystem(): string {
|
private themeBasedOnSystem(): string | undefined {
|
||||||
let newTheme: string;
|
let newTheme: string | undefined;
|
||||||
if (this.preferDark.matches) {
|
if (this.preferDark.matches) {
|
||||||
newTheme = "dark";
|
newTheme = "dark";
|
||||||
} else if (this.preferLight.matches) {
|
} else if (this.preferLight.matches) {
|
||||||
newTheme = "light";
|
newTheme = "light";
|
||||||
}
|
}
|
||||||
if (this.preferHighContrast.matches) {
|
if (newTheme && this.preferHighContrast.matches) {
|
||||||
const hcTheme = findHighContrastTheme(newTheme);
|
const hcTheme = findHighContrastTheme(newTheme);
|
||||||
if (hcTheme) {
|
if (hcTheme) {
|
||||||
newTheme = hcTheme;
|
newTheme = hcTheme;
|
||||||
|
|
Loading…
Reference in New Issue