diff --git a/server/package-lock.json b/server/package-lock.json index ae00549a8..c8a81dd62 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/server", - "version": "0.3.9", + "version": "0.3.10", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/server", - "version": "0.3.9", + "version": "0.3.10", "license": "ISC", "dependencies": { "@ffmpeg-installer/ffmpeg": "^1.1.0", diff --git a/server/package.json b/server/package.json index 58b071b31..48230f7d4 100644 --- a/server/package.json +++ b/server/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/server", - "version": "0.3.9", + "version": "0.3.10", "description": "", "dependencies": { "@ffmpeg-installer/ffmpeg": "^1.1.0", diff --git a/server/src/services/plugin.ts b/server/src/services/plugin.ts index 3d0f16347..0a2026082 100644 --- a/server/src/services/plugin.ts +++ b/server/src/services/plugin.ts @@ -51,13 +51,22 @@ export class PluginComponent { throw new Error(message); } const pluginDevice = this.scrypted.findPluginDeviceById(id); + // immediately remove the mixin and save this state, + // but hold off on generating the new descriptor until + // the new table is finished. this.scrypted.stateManager.setPluginDeviceState(pluginDevice, ScryptedInterfaceProperty.mixins, [...new Set(mixins)]); - this.scrypted.stateManager.updateDescriptor(pluginDevice); await this.scrypted.datastore.upsert(pluginDevice); + // device may not exist, so force creation. this.scrypted.rebuildPluginDeviceMixinTable(id); this.scrypted.getDevice(id); await this.scrypted.devices[id]?.handler?.ensureProxy(); + + // after the mixin table is generated, report/persist the final device descriptor + const promises = this.scrypted.devices[id]?.handler?.mixinTable?.map(e => e.entry); + await Promise.allSettled(promises); + this.scrypted.stateManager.updateDescriptor(pluginDevice); + await this.scrypted.datastore.upsert(pluginDevice); } async getIdForPluginId(pluginId: string) { return this.scrypted.findPluginDevice(pluginId)?._id;