Skip to content

Commit

Permalink
persist the versions for which notifications were skipped.
Browse files Browse the repository at this point in the history
  • Loading branch information
opiopan committed Jun 21, 2024
1 parent 2d672d8 commit 993ac22
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/gui/Models.Mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,11 @@ namespace winrt::gui::Models::implementation{
void Mapper::IsIgnoredUpdate(bool value){
std::unique_lock lock{mutex};
update_property(lock, is_ignored_update, value, L"NewRelease");
if (value){
tools::utf16_to_utf8_translator utf8str;
utf8str = latest_release.c_str();
fsmapper::app_config.set_skipped_version(utf8str);
}
}


Expand Down Expand Up @@ -763,15 +768,22 @@ namespace winrt::gui::Models::implementation{
current_version = latest_version;
co_await ui_thread;
std::unique_lock lock{mutex};
latest_release_uri = latest_version_uri;
is_available_new_release = true;
latest_release = latest_version_string;
is_ignored_update = false;
lock.unlock();
update_property(L"NewRelease");
tools::utf8_to_utf16_translator utf16str;
utf16str = fsmapper::app_config.get_skipped_version();
utils::parsed_version skipped_version{utf16str};
if (current_version > skipped_version){
latest_release_uri = latest_version_uri;
is_available_new_release = true;
latest_release = latest_version_string;
is_ignored_update = false;
lock.unlock();
update_property(L"NewRelease");
}else{
current_version = skipped_version;
lock.unlock();
}
co_await winrt::resume_background();
}

}
catch (winrt::hresult_error const &){}

Expand Down
10 changes: 10 additions & 0 deletions src/gui/Utilities/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ static const auto* CONFIG_RENDERING_METHOD = "rendering_method";
static const auto* CONFIG_PLUGIN_FOLDER_IS_DEFAULT = "plugin_folder_is_default";
static const auto* CONFIG_CUSTOM_PLUGIN_FOLDER = "custom_plugin_folder";
static const auto* CONFIG_LUA_STANDARD_LIBRARIES = "lua_stdlib";
static const auto *CONFIG_SKIPPED_VERSION = "skipped_version";

using namespace fsmapper;
using namespace nlohmann;
Expand All @@ -42,6 +43,7 @@ class config_imp : public config{
bool plugin_folder_is_default{true};
std::filesystem::path custom_plugin_folder;
uint64_t lua_standard_libraries{MOPT_STDLIB_BASE | MOPT_STDLIB_PACKAGE | MOPT_STDLIB_MATH | MOPT_STDLIB_TABLE | MOPT_STDLIB_STRING};
std::string skipped_version{"0.0"};

template <typename KEY, typename VALUE>
void reflect_number(json& jobj, const KEY& key, VALUE& var){
Expand Down Expand Up @@ -127,6 +129,7 @@ class config_imp : public config{
reflect_string(data, CONFIG_CUSTOM_PLUGIN_FOLDER, path);
custom_plugin_folder = path;
reflect_number(data, CONFIG_LUA_STANDARD_LIBRARIES, lua_standard_libraries);
reflect_string(data, CONFIG_SKIPPED_VERSION, skipped_version);
}

void save() override{
Expand All @@ -145,6 +148,7 @@ class config_imp : public config{
{CONFIG_PLUGIN_FOLDER_IS_DEFAULT, plugin_folder_is_default},
{CONFIG_CUSTOM_PLUGIN_FOLDER, custom_plugin_folder.string()},
{CONFIG_LUA_STANDARD_LIBRARIES, lua_standard_libraries},
{CONFIG_SKIPPED_VERSION, skipped_version},
};
std::ofstream os(config_path.string());
os << data;
Expand Down Expand Up @@ -217,6 +221,12 @@ class config_imp : public config{
void set_lua_standard_libraries(uint64_t value){
update_value(lua_standard_libraries, value);
}
const char* get_skipped_version(){
return skipped_version.c_str();
}
void set_skipped_version(const char* value){
update_value(skipped_version, value);
}
};

static config_imp the_config;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/Utilities/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ namespace fsmapper{
virtual void set_custom_plugin_folder(std::filesystem::path&& path) = 0;
virtual uint64_t get_lua_standard_libraries() = 0;
virtual void set_lua_standard_libraries(uint64_t value) = 0;
virtual const char* get_skipped_version() = 0;
virtual void set_skipped_version(const char* value) = 0;
};

void init_app_config();
Expand Down

0 comments on commit 993ac22

Please sign in to comment.