fix user-scoped options not being loaded
parent
8f9ec46f9e
commit
4cf0915670
|
@ -81,16 +81,18 @@ export class ChatManager extends EventEmitter {
|
||||||
});
|
});
|
||||||
this.search = new Search(this);
|
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
|
// connect new doc to persistance, scoped to the current username
|
||||||
this.provider = new IndexeddbPersistence('chats:' + username, this.doc.root);
|
this.provider = new IndexeddbPersistence('chats:' + username, this.doc.root);
|
||||||
this.provider.whenSynced.then(() => {
|
this.provider.whenSynced.then(() => {
|
||||||
this.doc.getChatIDs().map(id => this.emit(id));
|
this.doc.getChatIDs().map(id => this.emit(id));
|
||||||
this.emit('update');
|
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(
|
pluginRunner(
|
||||||
'init',
|
'init',
|
||||||
pluginID => createBasicPluginContext(pluginID, this.options),
|
pluginID => createBasicPluginContext(pluginID, this.options),
|
||||||
|
|
|
@ -22,11 +22,11 @@ export class OptionsManager extends EventEmitter {
|
||||||
this.optionGroups = [...globalOptions, ...this.pluginMetadata];
|
this.optionGroups = [...globalOptions, ...this.pluginMetadata];
|
||||||
|
|
||||||
// Load options from localStorage and YChats
|
// Load options from localStorage and YChats
|
||||||
this.loadOptions();
|
this.reloadOptions();
|
||||||
|
|
||||||
// Listen for update events on the broadcast channel
|
// Listen for update events on the broadcast channel
|
||||||
broadcastChannel.onmessage = (event: MessageEvent) => {
|
broadcastChannel.onmessage = (event: MessageEvent) => {
|
||||||
this.loadOptions();
|
this.reloadOptions();
|
||||||
|
|
||||||
if (event.data?.groupID) {
|
if (event.data?.groupID) {
|
||||||
this.emit('update', event.data.groupID);
|
this.emit('update', event.data.groupID);
|
||||||
|
@ -52,6 +52,7 @@ export class OptionsManager extends EventEmitter {
|
||||||
this.optionsCache.set(key, value);
|
this.optionsCache.set(key, value);
|
||||||
} else if (option.scope === "user") {
|
} else if (option.scope === "user") {
|
||||||
const key = cacheKey(groupID, option.id);
|
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;
|
const value = this.yDoc.getOption(groupID, option.id) || option.defaultValue;
|
||||||
this.optionsCache.set(key, value);
|
this.optionsCache.set(key, value);
|
||||||
} else {
|
} else {
|
||||||
|
@ -62,7 +63,7 @@ export class OptionsManager extends EventEmitter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private loadOptions() {
|
public reloadOptions() {
|
||||||
// Load browser and user-scoped options
|
// Load browser and user-scoped options
|
||||||
this.optionGroups.forEach(group => {
|
this.optionGroups.forEach(group => {
|
||||||
group.options.forEach(option => {
|
group.options.forEach(option => {
|
||||||
|
|
Loading…
Reference in New Issue