Updates
CI / test (push) Successful in 1m1s
Release rolling / release (push) Successful in 7m4s

This commit is contained in:
Raven Scott
2026-07-18 20:54:50 -04:00
parent d3edb56062
commit 66586d2181
2 changed files with 77 additions and 51 deletions
+29 -29
View File
@@ -115,6 +115,35 @@ try {
// ignore // ignore
} }
/** @type {Record<string, object>} */
let chartCatalog = {}
let selectedCatalogChart = ''
let exploreChartId = settings.defaultExplore || 'system.io'
/** @type {Map<string, { severity: string, score: number, threshold: number|null, until: number }>} */
const anomalyByChart = new Map()
const ANOMALY_HOLD_MS = 60_000
let desktopNotifyReady = false
/** @type {Record<string, number[]>} */
const series = {
cpu: [],
cpuUser: [],
cpuSystem: [],
cpuIowait: [],
ram: [],
net: [],
netTx: [],
io: [],
ioWrite: [],
load: [],
explore: [],
detail: [],
}
/** Per-peer CPU series for compare mode @type {Map<string, number[]>} */
const peerCpu = new Map()
const metricsDashboard = createMetricsDashboard({ const metricsDashboard = createMetricsDashboard({
els: { els: {
root: $('charts-view'), root: $('charts-view'),
@@ -168,35 +197,6 @@ const metricsDashboard = createMetricsDashboard({
getWeights: (args) => manager.request(Methods.getWeights, args || {}), getWeights: (args) => manager.request(Methods.getWeights, args || {}),
}) })
/** @type {Record<string, number[]>} */
const series = {
cpu: [],
cpuUser: [],
cpuSystem: [],
cpuIowait: [],
ram: [],
net: [],
netTx: [],
io: [],
ioWrite: [],
load: [],
explore: [],
detail: [],
}
/** Per-peer CPU series for compare mode @type {Map<string, number[]>} */
const peerCpu = new Map()
/** @type {Record<string, object>} */
let chartCatalog = {}
let selectedCatalogChart = ''
let exploreChartId = settings.defaultExplore || 'system.io'
/** @type {Map<string, { severity: string, score: number, threshold: number|null, until: number }>} */
const anomalyByChart = new Map()
const ANOMALY_HOLD_MS = 60_000
let desktopNotifyReady = false
function seriesMax() { function seriesMax() {
return Math.max(30, Math.min(300, Number(settings.chartPoints) || 90)) return Math.max(30, Math.min(300, Number(settings.chartPoints) || 90))
} }
+47 -21
View File
@@ -99,35 +99,37 @@ function migrateLegacySettings() {
return null return null
} }
export function loadSettings() { function readLocalStorageMirror() {
const defaults = defaultSettings()
let fromFile = readSettingsFile(getSettingsCachePath())
if (!fromFile) {
fromFile = migrateLegacySettings()
if (fromFile) {
const merged = { ...defaults, ...fromFile }
saveSettings(merged)
return merged
}
}
try { try {
if (!fromFile && typeof localStorage !== 'undefined') { if (typeof localStorage === 'undefined') return null
const mir = localStorage.getItem(SETTINGS_LOCALSTORAGE_KEY) const mir = localStorage.getItem(SETTINGS_LOCALSTORAGE_KEY)
if (mir) fromFile = JSON.parse(mir) if (!mir) return null
} const parsed = JSON.parse(mir)
return parsed && typeof parsed === 'object' ? parsed : null
} catch { } catch {
// ignore return null
} }
}
/** Side-effect free merge of defaults + disk/legacy/LS. Never writes. */
function peekSettings() {
const defaults = defaultSettings()
const fromFile =
readSettingsFile(getSettingsCachePath()) ||
migrateLegacySettings() ||
readLocalStorageMirror()
return { ...defaults, ...(fromFile || {}) } return { ...defaults, ...(fromFile || {}) }
} }
/** @param {Partial<UiSettings>} patch */ /**
export function saveSettings(patch) { * Persist settings envelope to disk + LS mirror. Does not call loadSettings.
const next = { ...loadSettings(), ...patch } * @param {UiSettings} settings
*/
function persistSettings(settings) {
const payload = { const payload = {
version: SETTINGS_CACHE_VERSION, version: SETTINGS_CACHE_VERSION,
updatedAt: new Date().toISOString(), updatedAt: new Date().toISOString(),
settings: next, settings,
} }
try { try {
atomicWriteJson(getSettingsCachePath(), payload) atomicWriteJson(getSettingsCachePath(), payload)
@@ -136,15 +138,39 @@ export function saveSettings(patch) {
} }
try { try {
if (typeof localStorage !== 'undefined') { if (typeof localStorage !== 'undefined') {
localStorage.setItem(SETTINGS_LOCALSTORAGE_KEY, JSON.stringify(next)) localStorage.setItem(SETTINGS_LOCALSTORAGE_KEY, JSON.stringify(settings))
localStorage.setItem( localStorage.setItem(
'peardata-ui-boot', 'peardata-ui-boot',
JSON.stringify({ theme: next.theme }) JSON.stringify({ theme: settings.theme })
) )
} }
} catch { } catch {
// ignore // ignore
} }
}
export function loadSettings() {
const defaults = defaultSettings()
const cached = readSettingsFile(getSettingsCachePath())
if (cached && typeof cached === 'object') {
return { ...defaults, ...cached }
}
const legacy = migrateLegacySettings()
if (legacy) {
const merged = { ...defaults, ...legacy }
persistSettings(merged)
return merged
}
const mir = readLocalStorageMirror()
return { ...defaults, ...(mir || {}) }
}
/** @param {Partial<UiSettings>} patch */
export function saveSettings(patch) {
const next = { ...peekSettings(), ...patch }
persistSettings(next)
return next return next
} }