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

fix url protocol integration under linux #5535

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
45 changes: 22 additions & 23 deletions src/slic3r/GUI/DesktopIntegrationDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,9 @@ void DesktopIntegrationDialog::undo_desktop_intgration()
wxGetApp().plater()->get_notification_manager()->push_notification(NotificationType::UndoDesktopIntegrationSuccess);
}

void DesktopIntegrationDialog::perform_downloader_desktop_integration()
void DesktopIntegrationDialog::perform_downloader_desktop_integration(std::string url_prefix)
{
BOOST_LOG_TRIVIAL(debug) << "performing downloader desktop integration.";
BOOST_LOG_TRIVIAL(debug) << "performing downloader desktop integration. " << url_prefix ;
// Path to appimage
const char* appimage_env = std::getenv("APPIMAGE");
std::string excutable_path;
Expand Down Expand Up @@ -531,34 +531,21 @@ void DesktopIntegrationDialog::perform_downloader_desktop_integration()

std::string desktop_file_downloader = GUI::format(
"[Desktop Entry]\n"
"Name=OrcaSlicer URL Protocol%1%\n"
"Exec=\"%2%\" %%u\n"
"Name=OrcaSlicer URL Protocol %1% %2%\n"
"Exec=%3% %%u\n"
"Terminal=false\n"
"Type=Application\n"
"MimeType=x-scheme-handler/prusaslicer;\n"
"MimeType=x-scheme-handler/%1%;\n"
"StartupNotify=false\n"
"NoDisplay=true\n"
, name_suffix, excutable_path);

// desktop file for downloader as part of main app
std::string desktop_path = GUI::format("%1%/applications/OrcaSlicerURLProtocol%2%.desktop", target_dir_desktop, version_suffix);
if (create_desktop_file(desktop_path, desktop_file_downloader)) {
// save path to desktop file
app_config->set("desktop_integration_URL_path", desktop_path);
// finish registration on mime type
std::string command = GUI::format("xdg-mime default OrcaSlicerURLProtocol%1%.desktop x-scheme-handler/prusaslicer", version_suffix);
BOOST_LOG_TRIVIAL(debug) << "system command: " << command;
int r = system(command.c_str());
BOOST_LOG_TRIVIAL(debug) << "system result: " << r;

}
, url_prefix, name_suffix, excutable_path);

bool candidate_found = false;
for (size_t i = 0; i < target_candidates.size(); ++i) {
if (contains_path_dir(target_candidates[i], "applications")) {
target_dir_desktop = target_candidates[i];
// Write slicer desktop file
std::string path = GUI::format("%1%/applications/OrcaSlicerURLProtocol%2%.desktop", target_dir_desktop, version_suffix);
std::string path = GUI::format("%1%/applications/OrcaSlicerURLProtocol-%2%%3%.desktop", target_dir_desktop, url_prefix, version_suffix);
if (create_desktop_file(path, desktop_file_downloader)) {
app_config->set("desktop_integration_URL_path", path);
candidate_found = true;
Expand All @@ -578,7 +565,7 @@ void DesktopIntegrationDialog::perform_downloader_desktop_integration()
create_path(boost::nowide::narrow(wxFileName::GetHomeDir()), ".local/share/applications");
// create desktop file
target_dir_desktop = GUI::format("%1%/.local/share", wxFileName::GetHomeDir());
std::string path = GUI::format("%1%/applications/OrcaSlicerURLProtocol%2%.desktop", target_dir_desktop, version_suffix);
std::string path = GUI::format("%1%/applications/OrcaSlicerURLProtocol-%2%%3%.desktop", target_dir_desktop, url_prefix, version_suffix);
if (contains_path_dir(target_dir_desktop, "applications")) {
if (!create_desktop_file(path, desktop_file_downloader)) {
// Desktop file not written - end desktop integration
Expand All @@ -601,8 +588,20 @@ void DesktopIntegrationDialog::perform_downloader_desktop_integration()
return;
}

// desktop file for downloader as part of main app
std::string desktop_path = GUI::format("%1%/applications/OrcaSlicerURLProtocol-%2%%3%.desktop", target_dir_desktop, url_prefix, version_suffix);
if (create_desktop_file(desktop_path, desktop_file_downloader)) {
// save path to desktop file
app_config->set("desktop_integration_URL_path", desktop_path);
// finish registration on mime type
std::string command = GUI::format("xdg-mime default OrcaSlicerURLProtocol-%1%%2%.desktop x-scheme-handler/%1%", url_prefix, version_suffix);
BOOST_LOG_TRIVIAL(debug) << "system command: " << command;
int r = system(command.c_str());
BOOST_LOG_TRIVIAL(debug) << "system result: " << r;
}

// finish registration on mime type
std::string command = GUI::format("xdg-mime default OrcaSlicerURLProtocol%1%.desktop x-scheme-handler/prusaslicer", version_suffix);
std::string command = GUI::format("xdg-mime default OrcaSlicerURLProtocol-%1%%2%.desktop x-scheme-handler/%1%", url_prefix, version_suffix);
BOOST_LOG_TRIVIAL(debug) << "system command: " << command;
int r = system(command.c_str());
BOOST_LOG_TRIVIAL(debug) << "system result: " << r;
Expand Down Expand Up @@ -668,4 +667,4 @@ DesktopIntegrationDialog::~DesktopIntegrationDialog()

} // namespace GUI
} // namespace Slic3r
#endif // __linux__
#endif // __linux__
4 changes: 2 additions & 2 deletions src/slic3r/GUI/DesktopIntegrationDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DesktopIntegrationDialog : public wxDialog
// Deletes Desktop files and icons for both PrusaSlicer and GcodeViewer at paths stored in App Config.
static void undo_desktop_intgration();

static void perform_downloader_desktop_integration();
static void perform_downloader_desktop_integration(std::string url_prefix);
static void undo_downloader_registration();
private:

Expand All @@ -39,4 +39,4 @@ class DesktopIntegrationDialog : public wxDialog
} // namespace Slic3r

#endif // slic3r_DesktopIntegrationDialog_hpp_
#endif // __linux__
#endif // __linux__
4 changes: 2 additions & 2 deletions src/slic3r/GUI/GUI_App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6601,8 +6601,8 @@ void GUI_App::associate_url(std::wstring url_prefix)
key_full.Create(false);
}
key_full = key_string;
#elif defined(__linux__) && defined(SLIC3R_DESKTOP_INTEGRATION)
DesktopIntegrationDialog::perform_downloader_desktop_integration();
#elif defined(__linux__) && defined(SLIC3R_DESKTOP_INTEGRATION)
DesktopIntegrationDialog::perform_downloader_desktop_integration(boost::nowide::narrow(url_prefix));
#endif // WIN32
}

Expand Down
Loading