Add icons for mis-matched version and restart required

This commit is contained in:
Cooldude2606 committed 2025-04-27 22:35:00 +01:00
1 parent 47c5e0fabd
commit cf9f087cba
10 files changed
+97 -51

No files matched your search

+27 -17
View File
@@ -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);
}
}
@@ -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,
);
+2 -1
View File
@@ -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,
);