MetaImGUI 1.0.0
ImGui Application Template for C++20
Loading...
Searching...
No Matches
UpdateChecker.h
Go to the documentation of this file.
1/*
2 MetaImGUI
3 Copyright (C) 2026 A P Nicholson
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18
19#pragma once
20
21#include <atomic>
22#include <functional>
23#include <memory>
24#include <mutex>
25#include <stop_token>
26#include <string>
27#include <thread>
28
29namespace MetaImGUI {
30
31// C++20: Using designated initializers for clear, safe initialization
32struct UpdateInfo {
33 bool updateAvailable = false;
34 std::string latestVersion;
35 std::string currentVersion;
36 std::string releaseUrl;
37 std::string releaseNotes;
38 std::string downloadUrl;
39};
40
42public:
43 UpdateChecker(std::string repoOwner, std::string repoName);
45
46 // Delete copy and move
47 UpdateChecker(const UpdateChecker&) = delete;
51
52 // Check for updates asynchronously
53 void CheckForUpdatesAsync(std::function<void(const UpdateInfo&)> callback);
54
55 // Check for updates synchronously (blocking)
57
58 // Cancel ongoing check
59 void Cancel();
60
61 // Check if a check is in progress
62 [[nodiscard]] bool IsChecking() const;
63
64 // Compare versions (returns: -1 if v1 < v2, 0 if equal, 1 if v1 > v2)
65 static int CompareVersions(const std::string& v1, const std::string& v2);
66
67private:
68 std::string m_repoOwner;
69 std::string m_repoName;
70 std::atomic<bool> m_checking;
71
72 // C++20: Using std::jthread for automatic thread management
73 std::jthread m_checkThread;
74 std::stop_source m_stopSource;
75 std::mutex m_threadMutex; // Protects thread operations
76
77 // Internal implementation
78 UpdateInfo CheckForUpdatesImpl(const std::stop_token& stopToken);
79 std::string FetchLatestReleaseInfo();
80 UpdateInfo ParseReleaseInfo(const std::string& jsonResponse);
81};
82
83} // namespace MetaImGUI
UpdateChecker(UpdateChecker &&)=delete
UpdateChecker & operator=(UpdateChecker &&)=delete
static int CompareVersions(const std::string &v1, const std::string &v2)
void CheckForUpdatesAsync(std::function< void(const UpdateInfo &)> callback)
UpdateChecker & operator=(const UpdateChecker &)=delete
UpdateChecker(const UpdateChecker &)=delete
std::string latestVersion
std::string currentVersion