mcp-quiz-server
Version:
🧠AI-Powered Quiz Management via Model Context Protocol (MCP) - Create, manage, and take quizzes directly from VS Code, Claude, and other AI agents.
119 lines • 3.91 kB
JavaScript
export class SettingsService {
constructor() {
this.listeners = new Set();
this.STORAGE_KEY = 'quiz-app-settings';
this.settings = this.getDefaultSettings();
this.loadSettings();
}
static getInstance() {
if (!SettingsService.instance) {
SettingsService.instance = new SettingsService();
}
return SettingsService.instance;
}
getDefaultSettings() {
return {
ui: {
hideDisabledNavButtons: false,
hideAllNavButtons: false,
autoAdvanceQuestions: false,
clickToAdvance: false,
showContinueButton: true,
announceSelections: true,
selectionFeedbackDuration: 2000,
showQuestionNumbers: true,
enableAnimations: true,
defaultViewMode: 'list',
sidebarExpanded: true
},
quiz: {
showHints: false,
confirmBeforeSubmit: true,
highlightAnsweredQuestions: true
}
};
}
getSettings() {
return { ...this.settings };
}
updateSettings(updates) {
this.settings = this.mergeDeep(this.settings, updates);
this.saveSettings();
this.notifyListeners();
}
updateUISettings(uiSettings) {
this.updateSettings({ ui: { ...this.settings.ui, ...uiSettings } });
}
updateQuizSettings(quizSettings) {
this.updateSettings({ quiz: { ...this.settings.quiz, ...quizSettings } });
}
resetToDefaults() {
this.settings = this.getDefaultSettings();
this.saveSettings();
this.notifyListeners();
}
subscribe(callback) {
this.listeners.add(callback);
return () => {
this.listeners.delete(callback);
};
}
notifyListeners() {
this.listeners.forEach(callback => callback(this.getSettings()));
}
loadSettings() {
try {
const saved = localStorage.getItem(this.STORAGE_KEY);
if (saved) {
const parsed = JSON.parse(saved);
this.settings = this.mergeDeep(this.getDefaultSettings(), parsed);
}
}
catch (error) {
console.warn('Failed to load settings from localStorage:', error);
this.settings = this.getDefaultSettings();
}
}
saveSettings() {
try {
localStorage.setItem(this.STORAGE_KEY, JSON.stringify(this.settings));
}
catch (error) {
console.error('Failed to save settings to localStorage:', error);
}
}
mergeDeep(target, source) {
const result = { ...target };
for (const key in source) {
if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
result[key] = this.mergeDeep(result[key] || {}, source[key]);
}
else {
result[key] = source[key];
}
}
return result;
}
get hideDisabledNavButtons() {
return this.settings.ui.hideDisabledNavButtons;
}
get autoAdvanceQuestions() {
return this.settings.ui.autoAdvanceQuestions;
}
get enableAnimations() {
return this.settings.ui.enableAnimations;
}
get defaultViewMode() {
return this.settings.ui.defaultViewMode;
}
get showContinueButton() {
return this.settings.ui.showContinueButton;
}
get announceSelections() {
return this.settings.ui.announceSelections;
}
get selectionFeedbackDuration() {
return this.settings.ui.selectionFeedbackDuration;
}
}
//# sourceMappingURL=SettingsService-new.js.map