Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphicPacksWindow2: Disable update button when a game is running #1137

Merged
merged 4 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/gui/DownloadGraphicPacksWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,6 @@ void deleteDownloadedGraphicPacks()

void DownloadGraphicPacksWindow::UpdateThread()
{
if (CafeSystem::IsTitleRunning())
{
wxMessageBox(_("Graphic packs cannot be updated while a game is running."), _("Graphic packs"), 5, this->GetParent());
// cancel update
m_threadState = ThreadFinished;
return;
}

// get github url
std::string githubAPIUrl;
curlDownloadFileState_t tempDownloadState;
Expand Down Expand Up @@ -326,8 +318,6 @@ DownloadGraphicPacksWindow::DownloadGraphicPacksWindow(wxWindow* parent)


m_downloadState = std::make_unique<curlDownloadFileState_t>();

m_thread = std::thread(&DownloadGraphicPacksWindow::UpdateThread, this);
}

DownloadGraphicPacksWindow::~DownloadGraphicPacksWindow()
Expand All @@ -344,6 +334,12 @@ const std::string& DownloadGraphicPacksWindow::GetException() const

int DownloadGraphicPacksWindow::ShowModal()
{
if(CafeSystem::IsTitleRunning())
{
wxMessageBox(_("Graphic packs cannot be updated while a game is running."), _("Graphic packs"), 5, this->GetParent());
return wxID_CANCEL;
}
m_thread = std::thread(&DownloadGraphicPacksWindow::UpdateThread, this);
wxDialog::ShowModal();
return m_threadState == ThreadCanceled ? wxID_CANCEL : wxID_OK;
}
Expand Down
10 changes: 10 additions & 0 deletions src/gui/GraphicPacksWindow2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ GraphicPacksWindow2::GraphicPacksWindow2(wxWindow* parent, uint64_t title_id_fil

SetSizer(main_sizer);

UpdateTitleRunning(CafeSystem::IsTitleRunning());
FillGraphicPackList();
}

Expand Down Expand Up @@ -676,6 +677,15 @@ void GraphicPacksWindow2::OnInstalledGamesChanged(wxCommandEvent& event)
event.Skip();
}

void GraphicPacksWindow2::UpdateTitleRunning(bool running)
{
m_update_graphicPacks->Enable(!running);
if(running)
m_update_graphicPacks->SetToolTip(_("Graphic packs cannot be updated while a game is running."));
else
m_update_graphicPacks->SetToolTip(nullptr);
}

void GraphicPacksWindow2::ReloadPack(const GraphicPackPtr& graphic_pack) const
{
if (graphic_pack->HasShaders() || graphic_pack->HasPatches() || graphic_pack->HasCustomVSyncFrequency())
Expand Down
1 change: 1 addition & 0 deletions src/gui/GraphicPacksWindow2.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class GraphicPacksWindow2 : public wxDialog
~GraphicPacksWindow2();

static void RefreshGraphicPacks();
void UpdateTitleRunning(bool running);

private:
std::string m_filter;
Expand Down
10 changes: 10 additions & 0 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ bool MainWindow::FileLoad(const fs::path launchPath, wxLaunchGameEvent::INITIATE
CreateCanvas();
CafeSystem::LaunchForegroundTitle();
RecreateMenu();
UpdateChildWindowTitleRunningState();

return true;
}
Expand Down Expand Up @@ -683,6 +684,7 @@ void MainWindow::OnFileMenu(wxCommandEvent& event)
RecreateMenu();
CreateGameListAndStatusBar();
DoLayout();
UpdateChildWindowTitleRunningState();
}
}

Expand Down Expand Up @@ -2320,6 +2322,14 @@ void MainWindow::RecreateMenu()
SetMenuVisible(false);
}

void MainWindow::UpdateChildWindowTitleRunningState()
{
const bool running = CafeSystem::IsTitleRunning();

if(auto graphicPacksWindow = dynamic_cast<GraphicPacksWindow2*>(m_graphic_pack_window))
goeiecool9999 marked this conversation as resolved.
Show resolved Hide resolved
graphicPacksWindow->UpdateTitleRunning(running);
}

void MainWindow::RestoreSettingsAfterGameExited()
{
RecreateMenu();
Expand Down
1 change: 1 addition & 0 deletions src/gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class MainWindow : public wxFrame, public CafeSystem::SystemImplementation

private:
void RecreateMenu();
void UpdateChildWindowTitleRunningState();
static wxString GetInitialWindowTitle();
void ShowGettingStartedDialog();

Expand Down
Loading