Updates
This commit is contained in:
@@ -115,6 +115,35 @@ try {
|
||||
// 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({
|
||||
els: {
|
||||
root: $('charts-view'),
|
||||
@@ -168,35 +197,6 @@ const metricsDashboard = createMetricsDashboard({
|
||||
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() {
|
||||
return Math.max(30, Math.min(300, Number(settings.chartPoints) || 90))
|
||||
}
|
||||
|
||||
+48
-22
@@ -99,35 +99,37 @@ function migrateLegacySettings() {
|
||||
return null
|
||||
}
|
||||
|
||||
export function loadSettings() {
|
||||
const defaults = defaultSettings()
|
||||
let fromFile = readSettingsFile(getSettingsCachePath())
|
||||
if (!fromFile) {
|
||||
fromFile = migrateLegacySettings()
|
||||
if (fromFile) {
|
||||
const merged = { ...defaults, ...fromFile }
|
||||
saveSettings(merged)
|
||||
return merged
|
||||
}
|
||||
}
|
||||
function readLocalStorageMirror() {
|
||||
try {
|
||||
if (!fromFile && typeof localStorage !== 'undefined') {
|
||||
const mir = localStorage.getItem(SETTINGS_LOCALSTORAGE_KEY)
|
||||
if (mir) fromFile = JSON.parse(mir)
|
||||
}
|
||||
if (typeof localStorage === 'undefined') return null
|
||||
const mir = localStorage.getItem(SETTINGS_LOCALSTORAGE_KEY)
|
||||
if (!mir) return null
|
||||
const parsed = JSON.parse(mir)
|
||||
return parsed && typeof parsed === 'object' ? parsed : null
|
||||
} 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 || {}) }
|
||||
}
|
||||
|
||||
/** @param {Partial<UiSettings>} patch */
|
||||
export function saveSettings(patch) {
|
||||
const next = { ...loadSettings(), ...patch }
|
||||
/**
|
||||
* Persist settings envelope to disk + LS mirror. Does not call loadSettings.
|
||||
* @param {UiSettings} settings
|
||||
*/
|
||||
function persistSettings(settings) {
|
||||
const payload = {
|
||||
version: SETTINGS_CACHE_VERSION,
|
||||
updatedAt: new Date().toISOString(),
|
||||
settings: next,
|
||||
settings,
|
||||
}
|
||||
try {
|
||||
atomicWriteJson(getSettingsCachePath(), payload)
|
||||
@@ -136,15 +138,39 @@ export function saveSettings(patch) {
|
||||
}
|
||||
try {
|
||||
if (typeof localStorage !== 'undefined') {
|
||||
localStorage.setItem(SETTINGS_LOCALSTORAGE_KEY, JSON.stringify(next))
|
||||
localStorage.setItem(SETTINGS_LOCALSTORAGE_KEY, JSON.stringify(settings))
|
||||
localStorage.setItem(
|
||||
'peardata-ui-boot',
|
||||
JSON.stringify({ theme: next.theme })
|
||||
JSON.stringify({ theme: settings.theme })
|
||||
)
|
||||
}
|
||||
} catch {
|
||||
// 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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user