Skip to content

Commit

Permalink
Improve desktop error output, restricting application to single instance
Browse files Browse the repository at this point in the history
  • Loading branch information
fboes committed May 15, 2019
1 parent 2fffe79 commit 75507c9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Change log
-----

* 💊 Fix handling of `--file` parameter, as it did not work as advertised
* 💊 Improve desktop error output, restricting application to single instance

1.2.4
-----
Expand Down
10 changes: 5 additions & 5 deletions src/WettergeraetDesktop/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ void Frame::loadMainMcf()
this->markAsClean();
}
catch (std::invalid_argument& e) {
this->metarInput->SetValue(e.what());
wxLogError(e.what());
return;
}
}
Expand All @@ -330,7 +330,7 @@ void Frame::actionFetch(wxCommandEvent& WXUNUSED(event))
{
auto icaoCode = this->icaoInput->GetValue();
if (icaoCode == "") {
this->metarInput->SetValue("No ICAO airport code given");
wxLogError(_("No ICAO airport code given"));
return;
}
this->metarInput->SetValue("Loading...");
Expand All @@ -342,7 +342,7 @@ void Frame::actionFetch(wxCommandEvent& WXUNUSED(event))
this->markAsDirty();
}
catch (std::invalid_argument& e) {
this->metarInput->SetValue(e.what());
wxLogError(e.what());
}
}

Expand All @@ -357,7 +357,7 @@ void Frame::actionParse(wxCommandEvent& WXUNUSED(event))
this->fromObjectToInput();
}
catch (std::invalid_argument& e) {
this->metarInput->SetValue(e.what());
wxLogError(e.what());
}
}

Expand All @@ -370,7 +370,7 @@ void Frame::actionSave(wxCommandEvent& WXUNUSED(event))
this->mainConfig.save();
}
catch (std::invalid_argument& e) {
this->metarInput->SetValue(e.what());
wxLogError(e.what());
return;
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/WettergeraetDesktop/WettergeraetDesktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,23 @@ IMPLEMENT_APP(WettergeraetDesktop)

bool WettergeraetDesktop::OnInit()
{
this->m_checker = new wxSingleInstanceChecker;
if (this->m_checker->IsAnotherRunning())
{
wxLogError(_("Another program instance is already running, aborting."));
delete this->m_checker; // OnExit() won't be called if we return false
this->m_checker = NULL;
return false;
}

Frame *frame = new Frame(wxT("Aerofly Wetterger\u00E4t"), wxApp::argc, wxApp::argv);
frame->Show(true);

return true;
}

int WettergeraetDesktop::OnExit()
{
delete this->m_checker;
return 0;
}
5 changes: 5 additions & 0 deletions src/WettergeraetDesktop/WettergeraetDesktop.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#pragma once

#include <wx/wx.h>
#include <wx/snglinst.h>

class WettergeraetDesktop : public wxApp
{
private:
wxSingleInstanceChecker *m_checker;
public:
virtual bool OnInit() override;
virtual int OnExit() override;

};

0 comments on commit 75507c9

Please sign in to comment.