Skip to content

Commit

Permalink
Check software version at startup
Browse files Browse the repository at this point in the history
Refs: #30
  • Loading branch information
orontee committed Sep 7, 2023
1 parent 3a27ff8 commit f827518
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 4 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

- Check software version at startup
[#30](https://github.com/orontee/argos/issues/30)

### Changed

### Removed
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ e-book reader.

Weather data is provided by [OpenWeather](https://openweathermap.org).

**The application is compatible with hardware running software version
≥6.**

Consult the [NEWS file](NEWS.md) for notable changes between versions.

## Install
Expand Down
17 changes: 15 additions & 2 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,26 @@ class App {
}

private:
static const int error_dialog_delay{3600};
static const int error_dialog_delay{5000};

std::shared_ptr<Model> model;
std::unique_ptr<Service> service;
std::unique_ptr<Ui> ui;

void setup() { this->ui = std::make_unique<Ui>(this->model); }
void setup() {
const auto version = GetSoftwareVersion();
try {
check_software_version(version);
} catch (const UnsupportedSoftwareVersion &error) {
Message(ICON_WARNING, T("Unsupported software version"),
T("The application isn't compatible with the software "
"version of this reader."),
error_dialog_delay);
this->exit();
return;
}
this->ui = std::make_unique<Ui>(this->model);
}

void show() {
if (not this->ui)
Expand Down
4 changes: 4 additions & 0 deletions src/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,8 @@ struct InvalidLocation : std::runtime_error {
struct UnsupportedUnitSystem : std::runtime_error {
UnsupportedUnitSystem() : std::runtime_error{""} {}
};

struct UnsupportedSoftwareVersion : std::runtime_error {
UnsupportedSoftwareVersion() : std::runtime_error{""} {}
};
} // namespace taranis
5 changes: 5 additions & 0 deletions src/l10n.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ inline void initialize_translations() {
"lisez la License publique générale GNU, version 3 ou ultérieure.");

// app.h
AddTranslation("Unsupported software version", "Logiciel incompatible");
AddTranslation("The application isn't compatible with the software version "
"of this reader.",
"L'application n'est pas compatible avec la version "
"logicielle de ce matériel.");
AddTranslation("Network error", "Erreur réseau");
AddTranslation(
"Failure while fetching weather data. Check your network connection.",
Expand Down
24 changes: 22 additions & 2 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
#include <algorithm>
#include <cctype>
#include <locale>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>

#include "errors.h"
#include "model.h"

namespace taranis {
Expand All @@ -18,13 +22,29 @@ normalize_precipitations(const std::vector<Condition> &conditions,

double max_number(double value_one, double value_two);

static inline void ltrim(std::string &s) {
inline void check_software_version(const std::string &version) {
// 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;
}
} catch (const std::invalid_argument &error) {
}
}
throw UnsupportedSoftwareVersion{};
}

inline void ltrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](char ch) {
return not std::isspace(ch) and ch != ',';
}));
}

static inline void rtrim(std::string &s) {
inline void rtrim(std::string &s) {
s.erase(
std::find_if(s.rbegin(), s.rend(),
[](char ch) { return not std::isspace(ch) and ch != ','; })
Expand Down

0 comments on commit f827518

Please sign in to comment.