Skip to content

Commit

Permalink
Enable dark mode depending on device state
Browse files Browse the repository at this point in the history
Refs: #98
  • Loading branch information
orontee committed Nov 13, 2024
1 parent 4718e97 commit 6b2e835
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 17 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Added

- Enable dark mode depending on device state (expects firmware >=
6.8.x) [#98](https://github.com/orontee/taranis/issues/98)

- Add icons to sunrise and sunset lines
[#95](https://github.com/orontee/taranis/issues/95)

Expand Down
44 changes: 30 additions & 14 deletions src/app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,8 @@ void App::setup() {
BOOST_LOG_TRIVIAL(info) << "Application setup";

this->l10n->initialize_translations();

const auto firmware_version = GetSoftwareVersion();
try {
check_firmware_version(firmware_version);
} catch (const UnsupportedFirmwareVersion &error) {
BOOST_LOG_TRIVIAL(warning)
<< "Unsupported firmware version " << firmware_version;
Message(ICON_WARNING, GetLangText("Unsupported software version"),
GetLangText("The application isn't compatible with the software "
"version of this reader."),
error_dialog_delay);
this->exit();
return;
}
this->check_minimum_supported_firmware();
this->set_app_capabilities();
this->set_task_parameters();

this->application_state->restore();
Expand Down Expand Up @@ -564,6 +552,34 @@ void App::update_configured_unit_system(UnitSystem unit_system) {
Config::config_changed();
}

void App::check_minimum_supported_firmware() {
const auto firmware_version = GetSoftwareVersion();
try {
firmware_version_greater_than(firmware_version, 6);
} catch (const UnsupportedFirmwareVersion &error) {
BOOST_LOG_TRIVIAL(warning)
<< "Unsupported firmware version, " << firmware_version;
Message(ICON_WARNING, GetLangText("Unsupported software version"),
GetLangText("The application isn't compatible with the software "
"version of this reader."),
error_dialog_delay);
this->exit();
return;
}
}

void App::set_app_capabilities() {
const auto firmware_version = GetSoftwareVersion();
try {
firmware_version_greater_than(firmware_version, 6, 8);
} catch (const UnsupportedFirmwareVersion &error) {
BOOST_LOG_TRIVIAL(warning)
<< "Firmware version not supporting dark mode, " << firmware_version;
return;
}
IvSetAppCapability(APP_CAPABILITY_SUPPORT_SCREEN_INVERSION);
}

void App::set_task_parameters() {
const auto task_identifier = GetCurrentTask();
const auto task_info = GetTaskInfo(task_identifier);
Expand Down
4 changes: 4 additions & 0 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class App {

void update_configured_unit_system(UnitSystem unit_system);

void check_minimum_supported_firmware();

void set_app_capabilities();

void set_task_parameters();

void start_refresh_timer() const;
Expand Down
3 changes: 3 additions & 0 deletions src/events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ std::string taranis::format_event_type(int event_type) {
if (event_type == EVT_PACKAGE_JOB_CHANGED) {
return "EVT_PACKAGE_JOB_CHANGED";
}
if (event_type == EVT_SCREEN_INVERSION_MODE_CHANGED) {
return "EVT_SCREEN_INVERSION_MODE_CHANGED";
}
if (event_type == EVT_CUSTOM) {
return "EVT_CUSTOM";
}
Expand Down
14 changes: 11 additions & 3 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,23 @@ normalize_precipitations(const std::vector<Condition> &conditions,

double max_number(double value_one, double value_two);

inline void check_firmware_version(const std::string &version) {
inline void firmware_version_greater_than(const std::string &version,
int major_version,
int minor_version = 0) {
// expected form V632.6.7.1405
std::stringstream to_parse{version};
std::string token;
if (std::getline(to_parse, token, '.')) {
std::getline(to_parse, token, '.');
try {
if (std::stoi(token) >= 6) {
return;
if (std::stoi(token) >= major_version) {
if (minor_version == 0) {
return;
}
std::getline(to_parse, token, '.');
if (std::stoi(token) >= minor_version) {
return;
}
}
} catch (const std::invalid_argument &error) {
}
Expand Down

0 comments on commit 6b2e835

Please sign in to comment.