diff --git a/app/src/core/index.ts b/app/src/core/index.ts index f47a2d5c..e83c40e1 100644 --- a/app/src/core/index.ts +++ b/app/src/core/index.ts @@ -81,16 +81,18 @@ export class ChatManager extends EventEmitter { }); this.search = new Search(this); + this.options = new OptionsManager(this.doc, pluginMetadata); + this.options.on('update', (...args) => this.emit('plugin-options-update', ...args)); + // connect new doc to persistance, scoped to the current username this.provider = new IndexeddbPersistence('chats:' + username, this.doc.root); this.provider.whenSynced.then(() => { this.doc.getChatIDs().map(id => this.emit(id)); this.emit('update'); + this.doc.emit('ready'); + this.options.reloadOptions(); }); - this.options = new OptionsManager(this.doc, pluginMetadata); - this.options.on('update', (...args) => this.emit('plugin-options-update', ...args)); - pluginRunner( 'init', pluginID => createBasicPluginContext(pluginID, this.options), diff --git a/app/src/core/options/index.ts b/app/src/core/options/index.ts index b2755615..5aaf5e0a 100644 --- a/app/src/core/options/index.ts +++ b/app/src/core/options/index.ts @@ -22,11 +22,11 @@ export class OptionsManager extends EventEmitter { this.optionGroups = [...globalOptions, ...this.pluginMetadata]; // Load options from localStorage and YChats - this.loadOptions(); + this.reloadOptions(); // Listen for update events on the broadcast channel broadcastChannel.onmessage = (event: MessageEvent) => { - this.loadOptions(); + this.reloadOptions(); if (event.data?.groupID) { this.emit('update', event.data.groupID); @@ -52,6 +52,7 @@ export class OptionsManager extends EventEmitter { this.optionsCache.set(key, value); } else if (option.scope === "user") { const key = cacheKey(groupID, option.id); + console.log(`loading option ${groupID}.${option.id} from YDoc into cache (${key})`); const value = this.yDoc.getOption(groupID, option.id) || option.defaultValue; this.optionsCache.set(key, value); } else { @@ -62,7 +63,7 @@ export class OptionsManager extends EventEmitter { } } - private loadOptions() { + public reloadOptions() { // Load browser and user-scoped options this.optionGroups.forEach(group => { group.options.forEach(option => {