mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 08:56:02 +08:00
Remove old url protocol desktop files before opening browser for login
This commit is contained in:
parent
e6313aa5e0
commit
07320325e1
@ -139,20 +139,35 @@ bool contains_path_dir(const std::string& p, const std::string& dir_name)
|
|||||||
if (p.empty() || dir_name.empty())
|
if (p.empty() || dir_name.empty())
|
||||||
return false;
|
return false;
|
||||||
boost::filesystem::path path(p + (p[p.size()-1] == '/' ? "" : "/") + dir_name);
|
boost::filesystem::path path(p + (p[p.size()-1] == '/' ? "" : "/") + dir_name);
|
||||||
if (boost::filesystem::exists(path) && boost::filesystem::is_directory(path)) {
|
boost::system::error_code ec;
|
||||||
|
if (boost::filesystem::exists(path, ec) && !ec) {
|
||||||
//BOOST_LOG_TRIVIAL(debug) << path.string() << " " << std::oct << boost::filesystem::status(path).permissions();
|
//BOOST_LOG_TRIVIAL(debug) << path.string() << " " << std::oct << boost::filesystem::status(path).permissions();
|
||||||
return true; //boost::filesystem::status(path).permissions() & boost::filesystem::owner_write;
|
return boost::filesystem::is_directory(path); //boost::filesystem::status(path).permissions() & boost::filesystem::owner_write;
|
||||||
} else
|
} else
|
||||||
BOOST_LOG_TRIVIAL(debug) << path.string() << " doesnt exists";
|
BOOST_LOG_TRIVIAL(debug) << path.string() << " doesnt exists";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::filesystem::path get_existing_dir(const std::string& sub, const std::string& dir_name)
|
||||||
|
{
|
||||||
|
assert(!p.empty() && !dir_name.empty());
|
||||||
|
boost::filesystem::path path = boost::filesystem::path(sub) / dir_name;
|
||||||
|
boost::system::error_code ec;
|
||||||
|
if (!boost::filesystem::exists(path, ec) || ec) {
|
||||||
|
return boost::filesystem::path();
|
||||||
|
}
|
||||||
|
if (!boost::filesystem::is_directory(path, ec) || ec) {
|
||||||
|
return boost::filesystem::path();
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
// Creates directory in path if not exists yet
|
// Creates directory in path if not exists yet
|
||||||
void create_dir(const boost::filesystem::path& path)
|
void create_dir(const boost::filesystem::path& path)
|
||||||
{
|
{
|
||||||
if (boost::filesystem::exists(path))
|
boost::system::error_code ec;
|
||||||
|
if (boost::filesystem::exists(path, ec) && !ec)
|
||||||
return;
|
return;
|
||||||
BOOST_LOG_TRIVIAL(debug)<< "creating " << path.string();
|
BOOST_LOG_TRIVIAL(debug)<< "creating " << path.string();
|
||||||
boost::system::error_code ec;
|
|
||||||
boost::filesystem::create_directory(path, ec);
|
boost::filesystem::create_directory(path, ec);
|
||||||
if (ec)
|
if (ec)
|
||||||
BOOST_LOG_TRIVIAL(error)<< "create directory failed: " << ec.message();
|
BOOST_LOG_TRIVIAL(error)<< "create directory failed: " << ec.message();
|
||||||
@ -627,6 +642,38 @@ void DesktopIntegrationDialog::undo_downloader_registration()
|
|||||||
}
|
}
|
||||||
// There is no need to undo xdg-mime default command. It is done automatically when desktop file is deleted.
|
// There is no need to undo xdg-mime default command. It is done automatically when desktop file is deleted.
|
||||||
}
|
}
|
||||||
|
void DesktopIntegrationDialog::undo_downloader_registration_rigid()
|
||||||
|
{
|
||||||
|
// Try ro find any PrusaSlicerURLProtocol.desktop files including alpha and beta and get rid of them
|
||||||
|
|
||||||
|
// $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored.
|
||||||
|
// If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.
|
||||||
|
// $XDG_DATA_DIRS defines the preference-ordered set of base directories to search for data files in addition to the $XDG_DATA_HOME base directory.
|
||||||
|
// The directories in $XDG_DATA_DIRS should be seperated with a colon ':'.
|
||||||
|
// If $XDG_DATA_DIRS is either not set or empty, a value equal to /usr/local/share/:/usr/share/ should be used.
|
||||||
|
std::vector<std::string>target_candidates;
|
||||||
|
target_candidates.emplace_back(GUI::into_u8(wxFileName::GetHomeDir()) + "/.local/share");
|
||||||
|
resolve_path_from_var("XDG_DATA_HOME", target_candidates);
|
||||||
|
resolve_path_from_var("XDG_DATA_DIRS", target_candidates);
|
||||||
|
for (const std::string cand : target_candidates) {
|
||||||
|
boost::filesystem::path apps_path = get_existing_dir(cand, "applications");
|
||||||
|
if (apps_path.empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (const std::string& suffix : {"" , "-beta", "-alpha"}) {
|
||||||
|
boost::filesystem::path file_path = apps_path / GUI::format("PrusaSlicerURLProtocol%1%.desktop", suffix);
|
||||||
|
boost::system::error_code ec;
|
||||||
|
if (!boost::filesystem::exists(file_path, ec) || ec) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!boost::filesystem::remove(file_path, ec) || ec) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "Failed to remove file " << file_path << " ec: " << ec.message();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "Desktop File removed: " << file_path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DesktopIntegrationDialog::DesktopIntegrationDialog(wxWindow *parent)
|
DesktopIntegrationDialog::DesktopIntegrationDialog(wxWindow *parent)
|
||||||
: wxDialog(parent, wxID_ANY, _(L("Desktop Integration")), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
|
: wxDialog(parent, wxID_ANY, _(L("Desktop Integration")), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
|
||||||
|
@ -39,6 +39,7 @@ public:
|
|||||||
|
|
||||||
static void perform_downloader_desktop_integration();
|
static void perform_downloader_desktop_integration();
|
||||||
static void undo_downloader_registration();
|
static void undo_downloader_registration();
|
||||||
|
static void undo_downloader_registration_rigid();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -881,9 +881,13 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
|||||||
if (dialog.ShowModal() != wxID_OK) {
|
if (dialog.ShowModal() != wxID_OK) {
|
||||||
if(!dialog_msg.empty()) {
|
if(!dialog_msg.empty()) {
|
||||||
DownloaderUtils::Worker::perform_register(wxGetApp().app_config->get("url_downloader_dest"));
|
DownloaderUtils::Worker::perform_register(wxGetApp().app_config->get("url_downloader_dest"));
|
||||||
#ifdef __linux__
|
#if defined(__linux__) && defined(SLIC3R_DESKTOP_INTEGRATION)
|
||||||
if (DownloaderUtils::Worker::perform_registration_linux)
|
if (DownloaderUtils::Worker::perform_registration_linux)
|
||||||
DesktopIntegrationDialog::perform_downloader_desktop_integration();
|
DesktopIntegrationDialog::perform_downloader_desktop_integration();
|
||||||
|
#elif defined(__linux__) && ! defined(SLIC3R_DESKTOP_INTEGRATION)
|
||||||
|
// ! defined(SLIC3R_DESKTOP_INTEGRATION) means the desktop integration was done elswhere f.e. by flatpack
|
||||||
|
// Remove all desktop files registering prusaslicer:// url done by previous versions.
|
||||||
|
DesktopIntegrationDialog::undo_downloader_registration_rigid();
|
||||||
#endif // __linux__
|
#endif // __linux__
|
||||||
wxGetApp().open_login_browser_with_dialog(/*dialog_msg*/evt.data.second);
|
wxGetApp().open_login_browser_with_dialog(/*dialog_msg*/evt.data.second);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user