fix: ensure battery and network state files are checked for existence before operations
This commit is contained in:
@@ -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