Support async onSettingsChange
This commit is contained in:
parent
51b66ea7cb
commit
24a792404c
|
@ -189,7 +189,7 @@ export class PluginManager implements ServerHook {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
onSettingsChanged (name: string, settings: any) {
|
async onSettingsChanged (name: string, settings: any) {
|
||||||
const registered = this.getRegisteredPluginByShortName(name)
|
const registered = this.getRegisteredPluginByShortName(name)
|
||||||
if (!registered) {
|
if (!registered) {
|
||||||
logger.error('Cannot find plugin %s to call on settings changed.', name)
|
logger.error('Cannot find plugin %s to call on settings changed.', name)
|
||||||
|
@ -197,7 +197,7 @@ export class PluginManager implements ServerHook {
|
||||||
|
|
||||||
for (const cb of registered.registerHelpers.getOnSettingsChangedCallbacks()) {
|
for (const cb of registered.registerHelpers.getOnSettingsChangedCallbacks()) {
|
||||||
try {
|
try {
|
||||||
cb(settings)
|
await cb(settings)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('Cannot run on settings changed callback for %s.', registered.npmName, { err })
|
logger.error('Cannot run on settings changed callback for %s.', registered.npmName, { err })
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ export class RegisterHelpers {
|
||||||
private idAndPassAuths: RegisterServerAuthPassOptions[] = []
|
private idAndPassAuths: RegisterServerAuthPassOptions[] = []
|
||||||
private externalAuths: RegisterServerAuthExternalOptions[] = []
|
private externalAuths: RegisterServerAuthExternalOptions[] = []
|
||||||
|
|
||||||
private readonly onSettingsChangeCallbacks: ((settings: any) => void)[] = []
|
private readonly onSettingsChangeCallbacks: ((settings: any) => Promise<any>)[] = []
|
||||||
|
|
||||||
private readonly router: express.Router
|
private readonly router: express.Router
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ export class RegisterHelpers {
|
||||||
|
|
||||||
setSetting: (name: string, value: string) => PluginModel.setSetting(this.plugin.name, this.plugin.type, name, value),
|
setSetting: (name: string, value: string) => PluginModel.setSetting(this.plugin.name, this.plugin.type, name, value),
|
||||||
|
|
||||||
onSettingsChange: (cb: (settings: any) => void) => this.onSettingsChangeCallbacks.push(cb)
|
onSettingsChange: (cb: (settings: any) => Promise<any>) => this.onSettingsChangeCallbacks.push(cb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,5 +5,5 @@ export interface PluginSettingsManager {
|
||||||
|
|
||||||
setSetting: (name: string, value: string) => Promise<any>
|
setSetting: (name: string, value: string) => Promise<any>
|
||||||
|
|
||||||
onSettingsChange: (cb: (names: string[]) => void) => void
|
onSettingsChange: (cb: (names: string[]) => Promise<any>) => void
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue