This commit is contained in:
2026-07-11 02:27:14 +03:00
parent a6ee6293e6
commit c0945d601a
14 changed files with 1147 additions and 1 deletions
+74
View File
@@ -0,0 +1,74 @@
import { App, PluginSettingTab, Setting } from 'obsidian';
import type ZeroQoLModulesPlugin from './main';
import { MODULES } from './modules';
import { ZeroQSettings } from './types';
const MODULE_DEFAULTS = MODULES.reduce(
(acc, mod) => {
acc[mod.id] = {
enabled: true,
settings: { ...mod.defaultSettings },
};
return acc;
},
{} as ZeroQSettings['modules'],
);
export const DEFAULT_SETTINGS: ZeroQSettings = {
modules: MODULE_DEFAULTS,
};
export function getModuleSettings(
settings: ZeroQSettings,
moduleId: string,
): Record<string, unknown> {
return settings.modules[moduleId]?.settings ?? {};
}
export class ZeroQSettingTab extends PluginSettingTab {
plugin: ZeroQoLModulesPlugin;
constructor(app: App, plugin: ZeroQoLModulesPlugin) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const { containerEl } = this;
containerEl.empty();
containerEl.createEl('h1', { text: 'ZeroQ QoL Modules' });
containerEl.createEl('p', {
text: 'Включайте и отключайте модули по своему усмотрению.',
attr: { style: 'color: var(--text-muted); margin-bottom: 20px;' },
});
for (const module of MODULES) {
const moduleSettings = this.plugin.settings.modules[module.id];
new Setting(containerEl)
.setName(module.name)
.setDesc(module.description)
.addToggle((toggle) =>
toggle
.setValue(moduleSettings?.enabled ?? true)
.onChange(async (value) => {
if (!this.plugin.settings.modules[module.id]) {
this.plugin.settings.modules[module.id] = {
enabled: value,
settings: { ...module.defaultSettings },
};
} else {
this.plugin.settings.modules[module.id].enabled = value;
}
await this.plugin.saveSettings();
if (value) {
this.plugin.loadModule(module);
} else {
this.plugin.unloadModule(module);
}
}),
);
}
}
}