diff options
Diffstat (limited to 'src/tracker_frame.cpp')
| -rw-r--r-- | src/tracker_frame.cpp | 59 |
1 files changed, 5 insertions, 54 deletions
| 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() | |||
| 63 | AP_SetTrackerFrame(this); | 63 | AP_SetTrackerFrame(this); |
| 64 | IPC_SetTrackerFrame(this); | 64 | IPC_SetTrackerFrame(this); |
| 65 | 65 | ||
| 66 | updater_ = std::make_unique<Updater>(this); | ||
| 67 | updater_->Cleanup(); | ||
| 68 | |||
| 66 | wxMenu *menuFile = new wxMenu(); | 69 | wxMenu *menuFile = new wxMenu(); |
| 67 | menuFile->Append(ID_AP_CONNECT, "&Connect to Archipelago"); | 70 | menuFile->Append(ID_AP_CONNECT, "&Connect to Archipelago"); |
| 68 | menuFile->Append(ID_IPC_CONNECT, "&Connect to Lingo"); | 71 | menuFile->Append(ID_IPC_CONNECT, "&Connect to Lingo"); |
| @@ -143,7 +146,7 @@ TrackerFrame::TrackerFrame() | |||
| 143 | } | 146 | } |
| 144 | 147 | ||
| 145 | if (GetTrackerConfig().should_check_for_updates) { | 148 | if (GetTrackerConfig().should_check_for_updates) { |
| 146 | CheckForUpdates(/*manual=*/false); | 149 | updater_->CheckForUpdates(/*invisible=*/true); |
| 147 | } | 150 | } |
| 148 | 151 | ||
| 149 | SetStatusText(GetStatusMessage()); | 152 | SetStatusText(GetStatusMessage()); |
| @@ -245,7 +248,7 @@ void TrackerFrame::OnSettings(wxCommandEvent &event) { | |||
| 245 | } | 248 | } |
| 246 | 249 | ||
| 247 | void TrackerFrame::OnCheckForUpdates(wxCommandEvent &event) { | 250 | void TrackerFrame::OnCheckForUpdates(wxCommandEvent &event) { |
| 248 | CheckForUpdates(/*manual=*/true); | 251 | updater_->CheckForUpdates(/*invisible=*/false); |
| 249 | } | 252 | } |
| 250 | 253 | ||
| 251 | void TrackerFrame::OnZoomIn(wxCommandEvent &event) { | 254 | void TrackerFrame::OnZoomIn(wxCommandEvent &event) { |
| @@ -345,55 +348,3 @@ void TrackerFrame::OnRedrawPosition(wxCommandEvent &event) { | |||
| 345 | void TrackerFrame::OnConnectToAp(ApConnectEvent &event) { | 348 | void TrackerFrame::OnConnectToAp(ApConnectEvent &event) { |
| 346 | AP_Connect(event.GetServer(), event.GetUser(), event.GetPass()); | 349 | AP_Connect(event.GetServer(), event.GetUser(), event.GetPass()); |
| 347 | } | 350 | } |
| 348 | |||
| 349 | void TrackerFrame::CheckForUpdates(bool manual) { | ||
| 350 | wxWebRequest request = wxWebSession::GetDefault().CreateRequest( | ||
| 351 | this, "https://code.fourisland.com/lingo-ap-tracker/plain/VERSION"); | ||
| 352 | |||
| 353 | if (!request.IsOk()) { | ||
| 354 | if (manual) { | ||
| 355 | wxMessageBox("Could not check for updates.", "Error", | ||
| 356 | wxOK | wxICON_ERROR); | ||
| 357 | } else { | ||
| 358 | SetStatusText("Could not check for updates."); | ||
| 359 | } | ||
| 360 | |||
| 361 | return; | ||
| 362 | } | ||
| 363 | |||
| 364 | Bind(wxEVT_WEBREQUEST_STATE, [this, manual](wxWebRequestEvent &evt) { | ||
| 365 | if (evt.GetState() == wxWebRequest::State_Completed) { | ||
| 366 | std::string response = evt.GetResponse().AsString().ToStdString(); | ||
| 367 | |||
| 368 | Version latest_version(response); | ||
| 369 | if (kTrackerVersion < latest_version) { | ||
| 370 | std::ostringstream message_text; | ||
| 371 | message_text << "There is a newer version of Lingo AP Tracker " | ||
| 372 | "available. You have " | ||
| 373 | << kTrackerVersion.ToString() | ||
| 374 | << ", and the latest version is " | ||
| 375 | << latest_version.ToString() | ||
| 376 | << ". Would you like to update?"; | ||
| 377 | |||
| 378 | if (wxMessageBox(message_text.str(), "Update available", wxYES_NO) == | ||
| 379 | wxYES) { | ||
| 380 | wxLaunchDefaultBrowser( | ||
| 381 | "https://code.fourisland.com/lingo-ap-tracker/about/" | ||
| 382 | "CHANGELOG.md"); | ||
| 383 | } | ||
| 384 | } else if (manual) { | ||
| 385 | wxMessageBox("Lingo AP Tracker is up to date!", "Lingo AP Tracker", | ||
| 386 | wxOK); | ||
| 387 | } | ||
| 388 | } else if (evt.GetState() == wxWebRequest::State_Failed) { | ||
| 389 | if (manual) { | ||
| 390 | wxMessageBox("Could not check for updates.", "Error", | ||
| 391 | wxOK | wxICON_ERROR); | ||
| 392 | } else { | ||
| 393 | SetStatusText("Could not check for updates."); | ||
| 394 | } | ||
| 395 | } | ||
| 396 | }); | ||
| 397 | |||
| 398 | request.Start(); | ||
| 399 | } | ||
