Remove const_cast workarounds for wxExecute (wxWidgets 3.1+)

wxWidgets 3.1+ accepts const argv arrays (const wchar_t* const* and
const char* const*) in wxExecute(), making the const_casts unnecessary.
Remove all 14 const_cast<char**>/const_cast<wchar_t**> wrappers around
wxExecute calls and their associated FIXME comments across GUI.cpp,
NotificationManager.cpp, and Downloader.cpp.
This commit is contained in:
SoftFever
2026-03-24 20:34:32 +08:00
parent 5f13f0893c
commit 8dcc3cd20d
3 changed files with 14 additions and 21 deletions

View File

@@ -17,15 +17,13 @@ void open_folder(const std::string& path)
// Code taken from NotificationManager.cpp // Code taken from NotificationManager.cpp
// Execute command to open a file explorer, platform dependent. // Execute command to open a file explorer, platform dependent.
// FIXME: The const_casts aren't needed in wxWidgets 3.1, remove them when we upgrade.
#ifdef _WIN32 #ifdef _WIN32
const wxString widepath = from_u8(path); const wxString widepath = from_u8(path);
const wchar_t* argv[] = { L"explorer", widepath.GetData(), nullptr }; const wchar_t* argv[] = { L"explorer", widepath.GetData(), nullptr };
::wxExecute(const_cast<wchar_t**>(argv), wxEXEC_ASYNC, nullptr); ::wxExecute(argv, wxEXEC_ASYNC, nullptr);
#elif __APPLE__ #elif __APPLE__
const char* argv[] = { "open", path.data(), nullptr }; const char* argv[] = { "open", path.data(), nullptr };
::wxExecute(const_cast<char**>(argv), wxEXEC_ASYNC, nullptr); ::wxExecute(argv, wxEXEC_ASYNC, nullptr);
#else #else
const char* argv[] = { "xdg-open", path.data(), nullptr }; const char* argv[] = { "xdg-open", path.data(), nullptr };
@@ -53,11 +51,11 @@ void open_folder(const std::string& path)
exec_env.cwd = std::move(owd); exec_env.cwd = std::move(owd);
} }
::wxExecute(const_cast<char**>(argv), wxEXEC_ASYNC, nullptr, &exec_env); ::wxExecute(argv, wxEXEC_ASYNC, nullptr, &exec_env);
} }
else { else {
// Looks like we're NOT running from AppImage, we'll make no changes to the environment. // Looks like we're NOT running from AppImage, we'll make no changes to the environment.
::wxExecute(const_cast<char**>(argv), wxEXEC_ASYNC, nullptr, nullptr); ::wxExecute(argv, wxEXEC_ASYNC, nullptr, nullptr);
} }
#endif #endif
} }

View File

@@ -530,16 +530,14 @@ void login()
void desktop_open_datadir_folder() void desktop_open_datadir_folder()
{ {
// Execute command to open a file explorer, platform dependent. // Execute command to open a file explorer, platform dependent.
// FIXME: The const_casts aren't needed in wxWidgets 3.1, remove them when we upgrade.
const auto path = data_dir(); const auto path = data_dir();
#ifdef _WIN32 #ifdef _WIN32
const wxString widepath = from_u8(path); const wxString widepath = from_u8(path);
const wchar_t *argv[] = { L"explorer", widepath.GetData(), nullptr }; const wchar_t *argv[] = { L"explorer", widepath.GetData(), nullptr };
::wxExecute(const_cast<wchar_t**>(argv), wxEXEC_ASYNC, nullptr); ::wxExecute(argv, wxEXEC_ASYNC, nullptr);
#elif __APPLE__ #elif __APPLE__
const char *argv[] = { "open", path.data(), nullptr }; const char *argv[] = { "open", path.data(), nullptr };
::wxExecute(const_cast<char**>(argv), wxEXEC_ASYNC, nullptr); ::wxExecute(argv, wxEXEC_ASYNC, nullptr);
#else #else
const char *argv[] = { "xdg-open", path.data(), nullptr }; const char *argv[] = { "xdg-open", path.data(), nullptr };
@@ -567,10 +565,10 @@ void desktop_open_datadir_folder()
exec_env.cwd = std::move(owd); exec_env.cwd = std::move(owd);
} }
::wxExecute(const_cast<char**>(argv), wxEXEC_ASYNC, nullptr, &exec_env); ::wxExecute(argv, wxEXEC_ASYNC, nullptr, &exec_env);
} else { } else {
// Looks like we're NOT running from AppImage, we'll make no changes to the environment. // Looks like we're NOT running from AppImage, we'll make no changes to the environment.
::wxExecute(const_cast<char**>(argv), wxEXEC_ASYNC, nullptr, nullptr); ::wxExecute(argv, wxEXEC_ASYNC, nullptr, nullptr);
} }
#endif #endif
} }
@@ -578,7 +576,6 @@ void desktop_open_datadir_folder()
void desktop_open_any_folder( const std::string& path ) void desktop_open_any_folder( const std::string& path )
{ {
// Execute command to open a file explorer, platform dependent. // Execute command to open a file explorer, platform dependent.
// FIXME: The const_casts aren't needed in wxWidgets 3.1, remove them when we upgrade.
#ifdef _WIN32 #ifdef _WIN32
const wxString widepath = from_u8(path); const wxString widepath = from_u8(path);
@@ -619,10 +616,10 @@ void desktop_open_any_folder( const std::string& path )
exec_env.cwd = std::move(owd); exec_env.cwd = std::move(owd);
} }
::wxExecute(const_cast<char **>(argv), wxEXEC_ASYNC, nullptr, &exec_env); ::wxExecute(argv, wxEXEC_ASYNC, nullptr, &exec_env);
} else { } else {
// Looks like we're NOT running from AppImage, we'll make no changes to the environment. // Looks like we're NOT running from AppImage, we'll make no changes to the environment.
::wxExecute(const_cast<char **>(argv), wxEXEC_ASYNC, nullptr, nullptr); ::wxExecute(argv, wxEXEC_ASYNC, nullptr, nullptr);
} }
#endif #endif
} }

View File

@@ -69,15 +69,13 @@ namespace {
// Code taken from desktop_open_datadir_folder() // Code taken from desktop_open_datadir_folder()
// Execute command to open a file explorer, platform dependent. // Execute command to open a file explorer, platform dependent.
// FIXME: The const_casts aren't needed in wxWidgets 3.1, remove them when we upgrade.
#ifdef _WIN32 #ifdef _WIN32
const wxString widepath = from_u8(path); const wxString widepath = from_u8(path);
const wchar_t* argv[] = { L"explorer", widepath.GetData(), nullptr }; const wchar_t* argv[] = { L"explorer", widepath.GetData(), nullptr };
::wxExecute(const_cast<wchar_t**>(argv), wxEXEC_ASYNC, nullptr); ::wxExecute(argv, wxEXEC_ASYNC, nullptr);
#elif __APPLE__ #elif __APPLE__
const char* argv[] = { "open", path.data(), nullptr }; const char* argv[] = { "open", path.data(), nullptr };
::wxExecute(const_cast<char**>(argv), wxEXEC_ASYNC, nullptr); ::wxExecute(argv, wxEXEC_ASYNC, nullptr);
#else #else
const char* argv[] = { "xdg-open", path.data(), nullptr }; const char* argv[] = { "xdg-open", path.data(), nullptr };
@@ -105,11 +103,11 @@ namespace {
exec_env.cwd = std::move(owd); exec_env.cwd = std::move(owd);
} }
::wxExecute(const_cast<char**>(argv), wxEXEC_ASYNC, nullptr, &exec_env); ::wxExecute(argv, wxEXEC_ASYNC, nullptr, &exec_env);
} }
else { else {
// Looks like we're NOT running from AppImage, we'll make no changes to the environment. // Looks like we're NOT running from AppImage, we'll make no changes to the environment.
::wxExecute(const_cast<char**>(argv), wxEXEC_ASYNC, nullptr, nullptr); ::wxExecute(argv, wxEXEC_ASYNC, nullptr, nullptr);
} }
#endif #endif
} }