From 9b7099d98b87f3a3cf5448c4ee9015e7e2a27684 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 7 Mar 2025 00:28:08 -0500 Subject: Added auto-updater --- src/tracker_frame.cpp | 59 +++++---------------------------------------------- 1 file changed, 5 insertions(+), 54 deletions(-) (limited to 'src/tracker_frame.cpp') diff --git a/src/tracker_frame.cpp b/src/tracker_frame.cpp index 9649c43..abc413d 100644 --- a/src/tracker_frame.cpp +++ b/src/tracker_frame.cpp @@ -63,6 +63,9 @@ TrackerFrame::TrackerFrame() AP_SetTrackerFrame(this); IPC_SetTrackerFrame(this); + updater_ = std::make_unique(this); + updater_->Cleanup(); + wxMenu *menuFile = new wxMenu(); menuFile->Append(ID_AP_CONNECT, "&Connect to Archipelago"); menuFile->Append(ID_IPC_CONNECT, "&Connect to Lingo"); @@ -143,7 +146,7 @@ TrackerFrame::TrackerFrame() } if (GetTrackerConfig().should_check_for_updates) { - CheckForUpdates(/*manual=*/false); + updater_->CheckForUpdates(/*invisible=*/true); } SetStatusText(GetStatusMessage()); @@ -245,7 +248,7 @@ void TrackerFrame::OnSettings(wxCommandEvent &event) { } void TrackerFrame::OnCheckForUpdates(wxCommandEvent &event) { - CheckForUpdates(/*manual=*/true); + updater_->CheckForUpdates(/*invisible=*/false); } void TrackerFrame::OnZoomIn(wxCommandEvent &event) { @@ -345,55 +348,3 @@ void TrackerFrame::OnRedrawPosition(wxCommandEvent &event) { void TrackerFrame::OnConnectToAp(ApConnectEvent &event) { AP_Connect(event.GetServer(), event.GetUser(), event.GetPass()); } - -void TrackerFrame::CheckForUpdates(bool manual) { - wxWebRequest request = wxWebSession::GetDefault().CreateRequest( - this, "https://code.fourisland.com/lingo-ap-tracker/plain/VERSION"); - - if (!request.IsOk()) { - if (manual) { - wxMessageBox("Could not check for updates.", "Error", - wxOK | wxICON_ERROR); - } else { - SetStatusText("Could not check for updates."); - } - - return; - } - - Bind(wxEVT_WEBREQUEST_STATE, [this, manual](wxWebRequestEvent &evt) { - if (evt.GetState() == wxWebRequest::State_Completed) { - std::string response = evt.GetResponse().AsString().ToStdString(); - - Version latest_version(response); - if (kTrackerVersion < latest_version) { - std::ostringstream message_text; - message_text << "There is a newer version of Lingo AP Tracker " - "available. You have " - << kTrackerVersion.ToString() - << ", and the latest version is " - << latest_version.ToString() - << ". Would you like to update?"; - - if (wxMessageBox(message_text.str(), "Update available", wxYES_NO) == - wxYES) { - wxLaunchDefaultBrowser( - "https://code.fourisland.com/lingo-ap-tracker/about/" - "CHANGELOG.md"); - } - } else if (manual) { - wxMessageBox("Lingo AP Tracker is up to date!", "Lingo AP Tracker", - wxOK); - } - } else if (evt.GetState() == wxWebRequest::State_Failed) { - if (manual) { - wxMessageBox("Could not check for updates.", "Error", - wxOK | wxICON_ERROR); - } else { - SetStatusText("Could not check for updates."); - } - } - }); - - request.Start(); -} -- cgit 1.4.1