fix: ensure battery and network state files are checked for existence before operations
This commit is contained in:
@@ -51,10 +51,19 @@ Item {
|
||||
// ---- persistence: survives reload AND close (FileView -> disk) ----
|
||||
// use Config.configDir (base dir) so path is stable and visible in repo
|
||||
readonly property string _historyPath: Config.configDir + "/modules/bar/states/Battery/battery_history.json"
|
||||
// guard: don't try to read non-existent file (avoids FileView warning)
|
||||
Process {
|
||||
id: historyFileExistsCheck
|
||||
command: ["test", "-f", root._historyPath]
|
||||
onExited: function(exitCode, exitStatus) {
|
||||
if (exitCode === 0) historyFile.path = root._historyPath
|
||||
// else keep historyFile.path empty -> no read attempt, writes will set it later
|
||||
}
|
||||
Component.onCompleted: running = true
|
||||
}
|
||||
FileView {
|
||||
id: historyFile
|
||||
path: _historyPath
|
||||
printErrors: true
|
||||
printErrors: false
|
||||
// adapter holds json, synced to disk via writeAdapter()
|
||||
adapter: JsonAdapter {
|
||||
property var percentageHistory: []
|
||||
@@ -85,6 +94,7 @@ Item {
|
||||
repeat: true
|
||||
running: true
|
||||
onTriggered: {
|
||||
if (historyFile.path === "") historyFile.path = root._historyPath
|
||||
historyFile.adapter.percentageHistory = root.percentageHistory
|
||||
historyFile.adapter.energyHistory = root.energyHistory
|
||||
historyFile.adapter.usageHistory = root.usageHistory
|
||||
@@ -125,11 +135,10 @@ Item {
|
||||
|
||||
// ensure save on clean close / reload (best-effort, reload preserves via FileView anyway)
|
||||
Component.onDestruction: {
|
||||
if (historyFile.loaded) {
|
||||
if (historyFile.path === "") historyFile.path = root._historyPath
|
||||
historyFile.adapter.percentageHistory = root.percentageHistory
|
||||
historyFile.adapter.energyHistory = root.energyHistory
|
||||
historyFile.adapter.usageHistory = root.usageHistory
|
||||
historyFile.writeAdapter()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,10 +42,17 @@ QtObject {
|
||||
// ---- persistence: survives reload AND close (disk) ----
|
||||
// use Config.configDir (base dir) so path is stable and visible in repo
|
||||
readonly property string _historyPath: Config.configDir + "/modules/bar/states/Network/network_history.json"
|
||||
// guard: don't try to read non-existent file
|
||||
property Process historyFileExistsCheck: Process {
|
||||
command: ["test", "-f", root._historyPath]
|
||||
onExited: function(exitCode, exitStatus) {
|
||||
if (exitCode === 0) root.historyFile.path = root._historyPath
|
||||
}
|
||||
Component.onCompleted: running = true
|
||||
}
|
||||
// QtObject has no default property, so hold FileView as typed property
|
||||
property FileView historyFile: FileView {
|
||||
path: _historyPath
|
||||
printErrors: true
|
||||
printErrors: false
|
||||
adapter: JsonAdapter {
|
||||
property var downloadHistory: []
|
||||
property var uploadHistory: []
|
||||
@@ -73,19 +80,19 @@ QtObject {
|
||||
repeat: true
|
||||
running: true
|
||||
onTriggered: {
|
||||
historyFile.adapter.downloadHistory = root.downloadHistory
|
||||
historyFile.adapter.uploadHistory = root.uploadHistory
|
||||
historyFile.adapter.pingHistory = root.pingHistory
|
||||
historyFile.writeAdapter()
|
||||
if (root.historyFile.path === "") root.historyFile.path = root._historyPath
|
||||
root.historyFile.adapter.downloadHistory = root.downloadHistory
|
||||
root.historyFile.adapter.uploadHistory = root.uploadHistory
|
||||
root.historyFile.adapter.pingHistory = root.pingHistory
|
||||
root.historyFile.writeAdapter()
|
||||
}
|
||||
}
|
||||
Component.onDestruction: {
|
||||
if (historyFile.loaded) {
|
||||
historyFile.adapter.downloadHistory = root.downloadHistory
|
||||
historyFile.adapter.uploadHistory = root.uploadHistory
|
||||
historyFile.adapter.pingHistory = root.pingHistory
|
||||
historyFile.writeAdapter()
|
||||
}
|
||||
if (root.historyFile.path === "") root.historyFile.path = root._historyPath
|
||||
root.historyFile.adapter.downloadHistory = root.downloadHistory
|
||||
root.historyFile.adapter.uploadHistory = root.uploadHistory
|
||||
root.historyFile.adapter.pingHistory = root.pingHistory
|
||||
root.historyFile.writeAdapter()
|
||||
}
|
||||
|
||||
function findAllConnectedDevices() {
|
||||
|
||||
Reference in New Issue
Block a user