diff --git a/main/source/init/tasks.cpp b/main/source/init/tasks.cpp index 03a7ede26..a230554e6 100644 --- a/main/source/init/tasks.cpp +++ b/main/source/init/tasks.cpp @@ -25,23 +25,27 @@ namespace hex::init { using namespace std::literals::string_literals; static bool checkForUpdates() { - hex::Net net; + // documentation of the value above the setting definition + int showCheckForUpdates = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.check_for_updates", 2); + if (showCheckForUpdates == 1){ + hex::Net net; - auto releases = net.getJson(GitHubApiURL + "/releases/latest"s, 2000).get(); - if (releases.code != 200) - return false; + auto releases = net.getJson(GitHubApiURL + "/releases/latest"s, 2000).get(); + if (releases.code != 200) + return false; - if (!releases.body.contains("tag_name") || !releases.body["tag_name"].is_string()) - return false; + if (!releases.body.contains("tag_name") || !releases.body["tag_name"].is_string()) + return false; - auto versionString = std::string(IMHEX_VERSION); - size_t versionLength = std::min(versionString.find_first_of('-'), versionString.length()); - auto currVersion = "v" + versionString.substr(0, versionLength); - auto latestVersion = releases.body["tag_name"].get(); + auto versionString = std::string(IMHEX_VERSION); + size_t versionLength = std::min(versionString.find_first_of('-'), versionString.length()); + auto currVersion = "v" + versionString.substr(0, versionLength); + auto latestVersion = releases.body["tag_name"].get(); - if (latestVersion != currVersion) - ImHexApi::System::impl::addInitArgument("update-available", latestVersion.data()); + if (latestVersion != currVersion) + ImHexApi::System::impl::addInitArgument("update-available", latestVersion.data()); + } return true; } diff --git a/plugins/builtin/source/content/settings_entries.cpp b/plugins/builtin/source/content/settings_entries.cpp index 793e4e4ee..46e1941ab 100644 --- a/plugins/builtin/source/content/settings_entries.cpp +++ b/plugins/builtin/source/content/settings_entries.cpp @@ -35,6 +35,22 @@ namespace hex::plugin::builtin { /* General */ + /* Values of this setting : + 0 - do not check for updates on startup + 1 - check for updates on startup + 2 - default value - ask the user if he wants to check for updates. This value should only be encountered on the first startup. + */ + ContentRegistry::Settings::add("hex.builtin.setting.general", "hex.builtin.setting.general.check_for_updates", 2, [](auto name, nlohmann::json &setting) { + static bool enabled = static_cast(setting) == 1; + + if (ImGui::Checkbox(name.data(), &enabled)) { + setting = static_cast(enabled); + return true; + } + + return false; + }); + ContentRegistry::Settings::add("hex.builtin.setting.general", "hex.builtin.setting.general.show_tips", 1, [](auto name, nlohmann::json &setting) { static bool enabled = static_cast(setting); diff --git a/plugins/builtin/source/content/welcome_screen.cpp b/plugins/builtin/source/content/welcome_screen.cpp index be5f3d7a7..953c6810a 100644 --- a/plugins/builtin/source/content/welcome_screen.cpp +++ b/plugins/builtin/source/content/welcome_screen.cpp @@ -517,6 +517,21 @@ namespace hex::plugin::builtin { loadDefaultLayout(); }); + EventManager::subscribe([] { + // documentation of the value above the setting definition + int showCheckForUpdates = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.check_for_updates", 2); + if (showCheckForUpdates == 2) { + ContentRegistry::Settings::write("hex.builtin.setting.general", "hex.builtin.setting.general.check_for_updates", 0); + View::showYesNoQuestionPopup("hex.builtin.welcome.check_for_updates_text"_lang, + [] { // yes + ContentRegistry::Settings::write("hex.builtin.setting.general", "hex.builtin.setting.general.check_for_updates", 1); + ImGui::CloseCurrentPopup(); + }, [] { // no + ImGui::CloseCurrentPopup(); + }); + } + }); + ContentRegistry::Interface::addMenuItem("hex.builtin.menu.file", 1075, [&] { if (ImGui::BeginMenu("hex.builtin.menu.file.open_recent"_lang, !s_recentProvidersUpdating && !s_recentProviders.empty())) { // Copy to avoid changing list while iteration diff --git a/plugins/builtin/source/lang/de_DE.cpp b/plugins/builtin/source/lang/de_DE.cpp index 658396c89..2e697e7f7 100644 --- a/plugins/builtin/source/lang/de_DE.cpp +++ b/plugins/builtin/source/lang/de_DE.cpp @@ -44,6 +44,8 @@ namespace hex::plugin::builtin { { "hex.builtin.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, { "hex.builtin.welcome.header.various", "Verschiedenes" }, { "hex.builtin.welcome.tip_of_the_day", "Tipp des Tages" }, + // { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup ?\n" + // "Possible updates will be shown in the 'Update' tab of the welcome screen" }, { "hex.builtin.welcome.safety_backup.title", "Verlorene Daten wiederherstellen" }, { "hex.builtin.welcome.safety_backup.desc", "Oh nein, ImHex ist letztes mal abgestürtzt.\nWillst du das verherige Projekt wiederherstellen?"}, @@ -779,6 +781,7 @@ namespace hex::plugin::builtin { { "hex.builtin.setting.imhex", "ImHex" }, { "hex.builtin.setting.imhex.recent_files", "Kürzlich geöffnete Dateien" }, { "hex.builtin.setting.general", "Allgemein" }, + // { "hex.builtin.setting.general.check_for_updates", "Check for updates on startup" }, { "hex.builtin.setting.general.show_tips", "Tipps beim start anzeigen" }, { "hex.builtin.setting.general.auto_load_patterns", "Automatisches Pattern laden" }, { "hex.builtin.setting.general.sync_pattern_source", "Pattern Source Code zwischen Providern synchronisieren" }, diff --git a/plugins/builtin/source/lang/en_US.cpp b/plugins/builtin/source/lang/en_US.cpp index ab6f21bb0..4148ec17b 100644 --- a/plugins/builtin/source/lang/en_US.cpp +++ b/plugins/builtin/source/lang/en_US.cpp @@ -45,6 +45,8 @@ namespace hex::plugin::builtin { { "hex.builtin.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, { "hex.builtin.welcome.header.various", "Various" }, { "hex.builtin.welcome.tip_of_the_day", "Tip of the Day" }, + { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup ?\n" + "Possible updates will be shown in the 'Update' tab of the welcome screen" }, { "hex.builtin.welcome.safety_backup.title", "Restore lost data" }, { "hex.builtin.welcome.safety_backup.desc", "Oh no, ImHex crashed last time.\nDo you want to restore your past work?"}, @@ -784,6 +786,7 @@ namespace hex::plugin::builtin { { "hex.builtin.setting.imhex", "ImHex" }, { "hex.builtin.setting.imhex.recent_files", "Recent Files" }, { "hex.builtin.setting.general", "General" }, + { "hex.builtin.setting.general.check_for_updates", "Check for updates on startup" }, { "hex.builtin.setting.general.show_tips", "Show tips on startup" }, { "hex.builtin.setting.general.auto_load_patterns", "Auto-load supported pattern" }, { "hex.builtin.setting.general.sync_pattern_source", "Sync pattern source code between providers" }, diff --git a/plugins/builtin/source/lang/it_IT.cpp b/plugins/builtin/source/lang/it_IT.cpp index 786dfdba3..2836dd145 100644 --- a/plugins/builtin/source/lang/it_IT.cpp +++ b/plugins/builtin/source/lang/it_IT.cpp @@ -44,6 +44,8 @@ namespace hex::plugin::builtin { { "hex.builtin.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, { "hex.builtin.welcome.header.various", "Varie" }, { "hex.builtin.welcome.tip_of_the_day", "Consiglio del giorno" }, + // { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup ?\n" + // "Possible updates will be shown in the 'Update' tab of the welcome screen" }, { "hex.builtin.welcome.safety_backup.title", "Ripristina i dati persi" }, { "hex.builtin.welcome.safety_backup.desc", "Oh no, l'ultima volta ImHex è crashato.\nVuoi ripristinare il tuo lavoro?"}, @@ -788,6 +790,7 @@ namespace hex::plugin::builtin { { "hex.builtin.setting.imhex", "ImHex" }, { "hex.builtin.setting.imhex.recent_files", "File recenti" }, { "hex.builtin.setting.general", "Generali" }, + // { "hex.builtin.setting.general.check_for_updates", "Check for updates on startup" }, { "hex.builtin.setting.general.show_tips", "Mostra consigli all'avvio" }, { "hex.builtin.setting.general.auto_load_patterns", "Auto-caricamento del pattern supportato" }, // { "hex.builtin.setting.general.sync_pattern_source", "Sync pattern source code between providers" }, diff --git a/plugins/builtin/source/lang/ja_JP.cpp b/plugins/builtin/source/lang/ja_JP.cpp index 94b2673bd..95ba05e70 100644 --- a/plugins/builtin/source/lang/ja_JP.cpp +++ b/plugins/builtin/source/lang/ja_JP.cpp @@ -44,6 +44,8 @@ namespace hex::plugin::builtin { { "hex.builtin.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, { "hex.builtin.welcome.header.various", "Various" }, //? { "hex.builtin.welcome.tip_of_the_day", "今日の豆知識" }, + // { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup ?\n" + // "Possible updates will be shown in the 'Update' tab of the welcome screen" }, { "hex.builtin.welcome.safety_backup.title", "セッションの回復" }, { "hex.builtin.welcome.safety_backup.desc", "ImHexがクラッシュしました。\n前のデータを復元しますか?"}, @@ -786,6 +788,7 @@ namespace hex::plugin::builtin { { "hex.builtin.setting.imhex", "ImHex" }, { "hex.builtin.setting.imhex.recent_files", "最近開いたファイル" }, { "hex.builtin.setting.general", "基本" }, + // { "hex.builtin.setting.general.check_for_updates", "Check for updates on startup" }, { "hex.builtin.setting.general.show_tips", "起動時に豆知識を表示" }, { "hex.builtin.setting.general.auto_load_patterns", "対応するパターンを自動で読み込む" }, { "hex.builtin.setting.general.sync_pattern_source", "プロバイダ間のパターンソースコードを同期" }, diff --git a/plugins/builtin/source/lang/ko_KR.cpp b/plugins/builtin/source/lang/ko_KR.cpp index a1e82998c..801edf4fc 100644 --- a/plugins/builtin/source/lang/ko_KR.cpp +++ b/plugins/builtin/source/lang/ko_KR.cpp @@ -44,6 +44,8 @@ namespace hex::plugin::builtin { { "hex.builtin.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, { "hex.builtin.welcome.header.various", "Various" }, { "hex.builtin.welcome.tip_of_the_day", "오늘의 팁" }, + // { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup ?\n" + // "Possible updates will be shown in the 'Update' tab of the welcome screen" }, { "hex.builtin.welcome.safety_backup.title", "손상된 데이터 복구" }, { "hex.builtin.welcome.safety_backup.desc", "이전에 ImHex가 비 정상적으로 종료된 것 같습니다.\n이전의 작업을 복구할까요?"}, @@ -783,6 +785,7 @@ namespace hex::plugin::builtin { { "hex.builtin.setting.imhex", "ImHex" }, { "hex.builtin.setting.imhex.recent_files", "최근 파일" }, { "hex.builtin.setting.general", "일반" }, + // { "hex.builtin.setting.general.check_for_updates", "Check for updates on startup" }, { "hex.builtin.setting.general.show_tips", "시작 시 팁 표시" }, { "hex.builtin.setting.general.auto_load_patterns", "지원하는 패턴 자동으로 로드" }, { "hex.builtin.setting.general.sync_pattern_source", "공급자 간 패턴 소스 코드 동기화" }, diff --git a/plugins/builtin/source/lang/pt_BR.cpp b/plugins/builtin/source/lang/pt_BR.cpp index 7cd41ea5e..c9e5414b7 100644 --- a/plugins/builtin/source/lang/pt_BR.cpp +++ b/plugins/builtin/source/lang/pt_BR.cpp @@ -44,6 +44,8 @@ namespace hex::plugin::builtin { { "hex.builtin.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, { "hex.builtin.welcome.header.various", "Vários" }, { "hex.builtin.welcome.tip_of_the_day", "Dica do Dia" }, + // { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup ?\n" + // "Possible updates will be shown in the 'Update' tab of the welcome screen" }, { "hex.builtin.welcome.safety_backup.title", "Restaurar dados perdidos" }, { "hex.builtin.welcome.safety_backup.desc", "Ah não, ImHex crashou na ultima vez.\nDeseja restaurar seu trabalho anterior?"}, @@ -782,6 +784,7 @@ namespace hex::plugin::builtin { { "hex.builtin.setting.imhex", "ImHex" }, { "hex.builtin.setting.imhex.recent_files", "Arquivos Recentes" }, { "hex.builtin.setting.general", "General" }, + // { "hex.builtin.setting.general.check_for_updates", "Check for updates on startup" }, { "hex.builtin.setting.general.show_tips", "Mostrar dicas na inicialização" }, { "hex.builtin.setting.general.auto_load_patterns", "Padrão compatível com carregamento automático" }, // { "hex.builtin.setting.general.sync_pattern_source", "Sync pattern source code between providers" }, diff --git a/plugins/builtin/source/lang/zh_CN.cpp b/plugins/builtin/source/lang/zh_CN.cpp index e0e421755..22a291f74 100644 --- a/plugins/builtin/source/lang/zh_CN.cpp +++ b/plugins/builtin/source/lang/zh_CN.cpp @@ -44,6 +44,8 @@ namespace hex::plugin::builtin { { "hex.builtin.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, { "hex.builtin.welcome.header.various", "杂项" }, { "hex.builtin.welcome.tip_of_the_day", "每日提示" }, + // { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup ?\n" + // "Possible updates will be shown in the 'Update' tab of the welcome screen" }, { "hex.builtin.welcome.safety_backup.title", "恢复崩溃数据" }, { "hex.builtin.welcome.safety_backup.desc", "糟糕,ImHex 上次崩溃了!\n您想从异常转储中恢复之前的数据吗?"}, @@ -784,6 +786,7 @@ namespace hex::plugin::builtin { { "hex.builtin.setting.imhex", "ImHex" }, { "hex.builtin.setting.imhex.recent_files", "最近文件" }, { "hex.builtin.setting.general", "通用" }, + // { "hex.builtin.setting.general.check_for_updates", "Check for updates on startup" }, { "hex.builtin.setting.general.show_tips", "在启动时显示每日提示" }, { "hex.builtin.setting.general.auto_load_patterns", "自动加载支持的模式" }, { "hex.builtin.setting.general.sync_pattern_source", "在提供器间同步模式源码" }, diff --git a/plugins/builtin/source/lang/zh_TW.cpp b/plugins/builtin/source/lang/zh_TW.cpp index 826a16d34..d8315a58d 100644 --- a/plugins/builtin/source/lang/zh_TW.cpp +++ b/plugins/builtin/source/lang/zh_TW.cpp @@ -44,6 +44,8 @@ namespace hex::plugin::builtin { { "hex.builtin.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, { "hex.builtin.welcome.header.various", "多樣" }, { "hex.builtin.welcome.tip_of_the_day", "今日提示" }, + // { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup ?\n" + // "Possible updates will be shown in the 'Update' tab of the welcome screen" }, { "hex.builtin.welcome.safety_backup.title", "復原遺失資料" }, { "hex.builtin.welcome.safety_backup.desc", "喔不,ImHex 上次崩潰了。\n您要復原您的工作階段嗎?"}, @@ -782,6 +784,7 @@ namespace hex::plugin::builtin { { "hex.builtin.setting.imhex", "ImHex" }, { "hex.builtin.setting.imhex.recent_files", "近期檔案" }, { "hex.builtin.setting.general", "一般" }, + // { "hex.builtin.setting.general.check_for_updates", "Check for updates on startup" }, { "hex.builtin.setting.general.show_tips", "啟動時顯示提示" }, { "hex.builtin.setting.general.auto_load_patterns", "自動載入支援的模式" }, { "hex.builtin.setting.general.sync_pattern_source", "同步提供者之間的模式原始碼" },