mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 08:23:12 +09:00
Merge pull request #758 from Cooldude2606/feature/pending-restart
Add indicators for host version mismatch and required restart
This commit is contained in:
14 files changed
+248
-79
No files matched your search
@@ -203,6 +203,8 @@ export class Config<
|
||||
|
||||
/** Set to true when a field in the config is changed. */
|
||||
dirty = false;
|
||||
/** Set to true when a 'restart required' field in the config is changed. */
|
||||
restartRequired = false;
|
||||
|
||||
/**
|
||||
* Create a new instance of the given config
|
||||
@@ -272,6 +274,27 @@ export class Config<
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of a field, while also settings the required flags and events.
|
||||
* This method does not perform any validation on the value being set
|
||||
*
|
||||
* @param name - Name of the field to set
|
||||
* @param value - The new value of the field
|
||||
* @param notify - False to skip setting dirty flags and emitting events
|
||||
*/
|
||||
_set(name: keyof Fields & string, value: FieldValue, notify: boolean = true) {
|
||||
const prev = this.fields[name];
|
||||
this.fields[name] = value as any;
|
||||
if (notify && !isDeepStrictEqual(value, prev)) {
|
||||
const def = this.constructor.fieldDefinitions[name];
|
||||
if (def.restartRequired) {
|
||||
this.restartRequired = true;
|
||||
}
|
||||
this.dirty = true;
|
||||
this.emit("fieldChanged", name, value, prev);
|
||||
}
|
||||
}
|
||||
|
||||
static jsonSchema = ConfigSchema;
|
||||
|
||||
static validate = libSchema.compile(this.jsonSchema as any);
|
||||
@@ -391,12 +414,7 @@ export class Config<
|
||||
continue;
|
||||
}
|
||||
|
||||
let prev = this.fields[name];
|
||||
this.fields[name] = value as any;
|
||||
if (notify && !isDeepStrictEqual(value, prev)) {
|
||||
this.dirty = true;
|
||||
this.emit("fieldChanged", name, value, prev);
|
||||
}
|
||||
this._set(name, value, notify);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -511,12 +529,7 @@ export class Config<
|
||||
throw new InvalidValue(`Expected type of ${name} to be ${def.type}, not ${basicType(value)}`);
|
||||
}
|
||||
|
||||
let prev = this.fields[name];
|
||||
this.fields[name] = value as Fields[Field];
|
||||
if (!isDeepStrictEqual(value, prev)) {
|
||||
this.dirty = true;
|
||||
this.emit("fieldChanged", name, value, prev);
|
||||
}
|
||||
this._set(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -559,10 +572,7 @@ export class Config<
|
||||
} else {
|
||||
delete updated[prop];
|
||||
}
|
||||
this.fields[name] = updated as Fields[Field];
|
||||
if (!isDeepStrictEqual(updated, prev)) {
|
||||
this.dirty = true;
|
||||
this.emit("fieldChanged", name, updated, prev);
|
||||
}
|
||||
|
||||
this._set(name, updated);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import type { PluginNodeEnvInfo, PluginWebpackEnvInfo } from "../plugin";
|
||||
import { Static } from "@sinclair/typebox";
|
||||
|
||||
export interface ControllerConfigFields {
|
||||
"controller.version": string;
|
||||
"controller.name": string;
|
||||
"controller.mods_directory": string;
|
||||
"controller.database_directory": string;
|
||||
@@ -46,6 +47,12 @@ export class ControllerConfig extends classes.Config<ControllerConfigFields> {
|
||||
}
|
||||
|
||||
static fieldDefinitions: classes.ConfigDefs<ControllerConfigFields> = {
|
||||
"controller.version": {
|
||||
type: "string",
|
||||
initialValue: "", // Set on start
|
||||
readonly: ["controller"],
|
||||
hidden: true,
|
||||
},
|
||||
"controller.name": {
|
||||
title: "Name",
|
||||
description: "Name of the cluster.",
|
||||
@@ -215,6 +222,7 @@ export class ControllerConfig extends classes.Config<ControllerConfigFields> {
|
||||
}
|
||||
|
||||
export interface HostConfigFields {
|
||||
"host.version": string;
|
||||
"host.name": string;
|
||||
"host.id": number;
|
||||
"host.factorio_directory": string;
|
||||
@@ -237,6 +245,12 @@ export interface HostConfigFields {
|
||||
export class HostConfig extends classes.Config<HostConfigFields> {
|
||||
declare static fromJSON: (json: classes.ConfigSchema, location: classes.ConfigLocation) => HostConfig;
|
||||
static fieldDefinitions: classes.ConfigDefs<HostConfigFields> = {
|
||||
"host.version": {
|
||||
type: "string",
|
||||
initialValue: "", // Set on start
|
||||
readonly: ["host"],
|
||||
hidden: true,
|
||||
},
|
||||
"host.name": {
|
||||
description: "Name of the host",
|
||||
type: "string",
|
||||
|
||||
@@ -250,6 +250,7 @@ export class SystemInfo {
|
||||
public diskCapacity: number,
|
||||
public diskAvailable: number,
|
||||
public canRestart: boolean,
|
||||
public restartRequired: boolean,
|
||||
/** Millisecond Unix timestamp this entry was last updated at */
|
||||
public updatedAtMs: number,
|
||||
public isDeleted: boolean,
|
||||
@@ -268,6 +269,7 @@ export class SystemInfo {
|
||||
"diskCapacity": Type.Number(),
|
||||
"diskAvailable": Type.Number(),
|
||||
"canRestart": Type.Boolean(),
|
||||
"restartRequired": Type.Boolean(),
|
||||
"updatedAtMs": Type.Number(),
|
||||
"isDeleted": Type.Boolean(),
|
||||
});
|
||||
@@ -286,6 +288,7 @@ export class SystemInfo {
|
||||
json.diskCapacity,
|
||||
json.diskAvailable,
|
||||
json.canRestart,
|
||||
json.restartRequired,
|
||||
json.updatedAtMs,
|
||||
json.isDeleted,
|
||||
);
|
||||
|
||||
@@ -134,7 +134,7 @@ function minZip<T>(a: T[], b: T[]): [T, T][] {
|
||||
|
||||
let previousTotalCpuMs: number[] = [];
|
||||
let previousIdleCpuMs: number[] = [];
|
||||
export async function gatherSystemInfo(id: SystemInfo["id"], canRestart: boolean) {
|
||||
export async function gatherSystemInfo(id: SystemInfo["id"], canRestart: boolean, restartRequired: boolean) {
|
||||
const cpus = os.cpus();
|
||||
const currentTotalCpuMs = cpus.map(({ times }) => times.user + times.idle + times.irq + times.nice + times.sys);
|
||||
const currentIdleCpuMs = cpus.map(({ times }) => times.idle);
|
||||
@@ -165,6 +165,7 @@ export async function gatherSystemInfo(id: SystemInfo["id"], canRestart: boolean
|
||||
diskCapacity,
|
||||
diskAvailable,
|
||||
canRestart,
|
||||
restartRequired,
|
||||
Date.now(),
|
||||
false,
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user