mirror of
https://github.com/ashaduri/gsmartcontrol.git
synced 2026-09-26 13:55:34 +00:00
Improve format detection: check output content for JSON vs text
- When smartctl/output property exists: both JSON and text available
- When no property and output starts with '{': JSON only (loaded JSON virtual drive)
- When no property and output doesn't start with '{': text only (loaded text virtual drive)
- Ensures correct filters shown for each scenario per requirements
Co-authored-by: ashaduri <2302268+ashaduri@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ashaduri/gsmartcontrol/sessions/a0167009-9a8b-4835-9c5d-83a6f7ff903d
This commit is contained in:
co-authored by
ashaduri
parent
4823af1d23
commit
893dfc75c8
@@ -172,10 +172,11 @@ class GscTextWindow : public AppBuilderWidget<GscTextWindow<InstanceSwitch>, Ins
|
||||
|
||||
if (storage_device_) {
|
||||
// Check if we have text output in the property repository
|
||||
bool has_text_property = false;
|
||||
if (auto p = storage_device_->get_property_repository().lookup_property("smartctl/output"); !p.empty()) {
|
||||
const std::string text_output = p.get_value<std::string>();
|
||||
if (!text_output.empty()) {
|
||||
has_text = true;
|
||||
has_text_property = true;
|
||||
}
|
||||
}
|
||||
// Get the output - it could be JSON or text format
|
||||
@@ -184,12 +185,20 @@ class GscTextWindow : public AppBuilderWidget<GscTextWindow<InstanceSwitch>, Ins
|
||||
output = storage_device_->get_basic_output();
|
||||
}
|
||||
if (!output.empty()) {
|
||||
// If we have text in property repo, the output is JSON; otherwise it's text
|
||||
if (has_text) {
|
||||
// If we have text in property repo, the output is JSON with embedded text
|
||||
if (has_text_property) {
|
||||
has_json = true;
|
||||
} else {
|
||||
// No text in property means the output itself is text format
|
||||
has_text = true;
|
||||
} else {
|
||||
// No text in property means either:
|
||||
// 1. Output is JSON without embedded text, or
|
||||
// 2. Output is text format (loaded text virtual drive)
|
||||
// We check if output starts with '{' to detect JSON
|
||||
if (!output.empty() && output[0] == '{') {
|
||||
has_json = true;
|
||||
} else {
|
||||
has_text = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user