Separate updates of Instance and InstanceDetails

Some updates for instances trigger instance details updates, while other
updates to instances are not visible on instance details. Rename
instanceUpdated to instanceDetailsUpdated to better represent what it
does and only set instancesDirty when an update is made to the
instances.
This commit is contained in:
Hornwitser committed 2023-11-30 15:01:14 +01:00
1 parent fae6ed3297
commit a0b02ee68b
2 files changed
+13 -10

No files matched your search

+8 -7
View File
@@ -720,8 +720,10 @@ export default class Controller {
let instance = new InstanceInfo({ config: instanceConfig, status: "unassigned" });
this.instances!.set(instanceId, instance);
this.instancesDirty = true;
await lib.invokeHook(this.plugins, "onInstanceStatusChanged", instance);
this.addInstanceHooks(instance);
this.instanceDetailsUpdated(instance);
return instance;
}
@@ -766,13 +768,14 @@ export default class Controller {
// Assign to target
instance.config.set("instance.assigned_host", hostId);
this.instancesDirty = true;
if (hostId !== null && newHostConnection) {
await newHostConnection.send(
new lib.InstanceAssignInternalRequest(instanceId, instance.config.serialize("host"))
);
} else {
instance.status = "unassigned";
this.instanceUpdated(instance);
this.instanceDetailsUpdated(instance);
}
}
@@ -791,10 +794,11 @@ export default class Controller {
await this.sendTo({ hostId }, new lib.InstanceDeleteInternalRequest(instanceId));
}
this.instances!.delete(instanceId);
this.instancesDirty = true;
let prev = instance.status;
instance.status = "deleted";
this.instanceUpdated(instance);
this.instanceDetailsUpdated(instance);
await lib.invokeHook(this.plugins, "onInstanceStatusChanged", instance, prev);
}
@@ -822,18 +826,15 @@ export default class Controller {
addInstanceHooks(instance: InstanceInfo) {
instance.config.on("fieldChanged", (group: lib.ConfigGroup, field: string, prev: any) => {
if (group.name === "instance" && field === "name") {
this.instanceUpdated(instance);
this.instanceDetailsUpdated(instance);
}
this.instancesDirty = true;
lib.invokeHook(this.plugins, "onInstanceConfigFieldChanged", instance, group, field, prev);
});
this.instanceUpdated(instance);
}
instanceUpdated(instance: InstanceInfo) {
this.instancesDirty = true;
instanceDetailsUpdated(instance: InstanceInfo) {
let assigned_host: number|null|undefined = instance.config.get("instance.assigned_host");
if (assigned_host === null) {
assigned_host = undefined;
+5 -3
View File
@@ -77,7 +77,7 @@ export default class HostConnection extends BaseConnection {
let prev = instance.status;
instance.status = "unknown";
this._controller.instanceUpdated(instance);
this._controller.instanceDetailsUpdated(instance);
lib.invokeHook(this._controller.plugins, "onInstanceStatusChanged", instance, prev);
}
});
@@ -181,7 +181,7 @@ export default class HostConnection extends BaseConnection {
instance.status = request.status as lib.InstanceStatus;
instance.game_port = request.gamePort || null;
logger.verbose(`Instance ${instance.config.get("instance.name")} State: ${instance.status}`);
this._controller.instanceUpdated(instance);
this._controller.instanceDetailsUpdated(instance);
await lib.invokeHook(this._controller.plugins, "onInstanceStatusChanged", instance, prev);
}
@@ -215,7 +215,7 @@ export default class HostConnection extends BaseConnection {
let prev = controllerInstance.status;
controllerInstance.status = instanceData.status as InstanceStatus;
logger.verbose(`Instance ${instanceConfig.get("instance.name")} State: ${instanceData.status}`);
this._controller.instanceUpdated(controllerInstance);
this._controller.instanceDetailsUpdated(controllerInstance);
await lib.invokeHook(
this._controller.plugins, "onInstanceStatusChanged", controllerInstance, prev
);
@@ -228,12 +228,14 @@ export default class HostConnection extends BaseConnection {
{ config: instanceConfig, status: instanceData.status as InstanceStatus }
);
this._controller.instances!.set(instanceConfig.get("instance.id"), newInstance);
this._controller.instancesDirty = true;
this._controller.addInstanceHooks(newInstance);
await this.send(
new lib.InstanceAssignInternalRequest(
instanceConfig.get("instance.id"), instanceConfig.serialize("host")
)
);
this._controller.instanceDetailsUpdated(newInstance);
await lib.invokeHook(this._controller.plugins, "onInstanceStatusChanged", newInstance);
}