url protocol registration on linux

This commit is contained in:
David Kocik 2022-06-13 13:26:11 +02:00
parent a98efb954c
commit 3b13add8a0
7 changed files with 61 additions and 9 deletions

View File

@ -14,7 +14,8 @@ enum DownloadState
DownloadStopped, DownloadStopped,
DownloadDone, DownloadDone,
DownloadError, DownloadError,
DownloadPaused DownloadPaused,
DownloadStateUnknown
}; };
class Download { class Download {

View File

@ -78,6 +78,7 @@ bool DownloadApp::OnInit()
m_frame = new DownloadFrame("Downloader", wxPoint(50, 50), wxSize(450, 340)); m_frame = new DownloadFrame("Downloader", wxPoint(50, 50), wxSize(450, 340));
m_frame->Show(true); m_frame->Show(true);
#ifdef _WIN32
wxWindow::MSWRegisterMessageHandler(WM_COPYDATA, [](wxWindow* win, WXUINT /* nMsg */, WXWPARAM wParam, WXLPARAM lParam) { wxWindow::MSWRegisterMessageHandler(WM_COPYDATA, [](wxWindow* win, WXUINT /* nMsg */, WXWPARAM wParam, WXLPARAM lParam) {
auto frame = dynamic_cast<DownloadFrame*>(win); auto frame = dynamic_cast<DownloadFrame*>(win);
COPYDATASTRUCT* copy_data_structure = { 0 }; COPYDATASTRUCT* copy_data_structure = { 0 };
@ -88,6 +89,7 @@ bool DownloadApp::OnInit()
} }
return true; return true;
}); });
#endif
return wxApp::OnInit(); return wxApp::OnInit();
} }
@ -400,6 +402,7 @@ DownloadState DownloadFrame::get_download_state(int id) const
return m_downloads[i]->get_state(); return m_downloads[i]->get_state();
} }
} }
return DownloadState::DownloadStateUnknown;
} }
bool DownloadFrame::is_in_state(int id, DownloadState state) const bool DownloadFrame::is_in_state(int id, DownloadState state) const
@ -409,6 +412,7 @@ bool DownloadFrame::is_in_state(int id, DownloadState state) const
return m_downloads[i]->get_state() == state; return m_downloads[i]->get_state() == state;
} }
} }
return false;
} }
bool DownloadFrame::cancel_download(int id) bool DownloadFrame::cancel_download(int id)
@ -471,6 +475,7 @@ wxString DownloadFrame::get_path_of(int id) const
return m_downloads[i]->get_final_path().string(); return m_downloads[i]->get_final_path().string();
} }
} }
return wxString();
} }
wxString DownloadFrame::get_folder_path_of(int id) const wxString DownloadFrame::get_folder_path_of(int id) const
@ -480,6 +485,7 @@ wxString DownloadFrame::get_folder_path_of(int id) const
return m_downloads[i]->get_final_path().parent_path().string(); return m_downloads[i]->get_final_path().parent_path().string();
} }
} }
return wxString();
} }
void DownloadFrame::handle_message(const wxString& msg) void DownloadFrame::handle_message(const wxString& msg)

View File

@ -217,22 +217,31 @@ bool execute_command(const wxString& command)
bool SlicerSend::get_instance_exists() const bool SlicerSend::get_instance_exists() const
{ {
#ifdef _WIN32
return !EnumWindows(EnumWindowsProcSlicer, 0); return !EnumWindows(EnumWindowsProcSlicer, 0);
#endif
return false;
} }
bool SlicerSend::send_path(const wxString& path) const bool SlicerSend::send_path(const wxString& path) const
{ {
#ifdef _WIN32
std::string escaped = escape_strings_cstyle({ "prusa-downloader", boost::nowide::narrow(path) }); std::string escaped = escape_strings_cstyle({ "prusa-downloader", boost::nowide::narrow(path) });
return send_message_slicer(boost::nowide::widen(escaped)); return send_message_slicer(boost::nowide::widen(escaped));
#endif
return false;
} }
bool SlicerSend::start_with_path(const wxString& path) const bool SlicerSend::start_with_path(const wxString& path) const
{ {
#ifdef _WIN32
// "C:\\Users\\User\\Downloads\\PrusaSlicer-2.4.2+win64-202204251110\\prusa-slicer.exe " // "C:\\Users\\User\\Downloads\\PrusaSlicer-2.4.2+win64-202204251110\\prusa-slicer.exe "
std::string escaped = escape_strings_cstyle({ boost::nowide::narrow(path) }); std::string escaped = escape_strings_cstyle({ boost::nowide::narrow(path) });
//return execute_command(boost::nowide::widen(escaped)); //return execute_command(boost::nowide::widen(escaped));
std::string binary = (boost::dll::program_location().parent_path() / "prusa-slicer.exe").string() + " "; std::string binary = (boost::dll::program_location().parent_path() / "prusa-slicer.exe").string() + " ";
//return execute_command("C:\\Users\\User\\Downloads\\PrusaSlicer-2.4.2+win64-202204251110\\prusa-slicer.exe " + boost::nowide::widen(escaped)); //return execute_command("C:\\Users\\User\\Downloads\\PrusaSlicer-2.4.2+win64-202204251110\\prusa-slicer.exe " + boost::nowide::widen(escaped));
return execute_command(boost::nowide::widen(binary) + boost::nowide::widen(escaped)); return execute_command(boost::nowide::widen(binary) + boost::nowide::widen(escaped));
#endif
return false;
} }
bool SlicerSend::start_or_send(const wxString& path) const bool SlicerSend::start_or_send(const wxString& path) const
@ -248,12 +257,18 @@ bool SlicerSend::start_or_send(const wxString& path) const
bool DownloaderSend::get_instance_exists() const bool DownloaderSend::get_instance_exists() const
{ {
#ifdef _WIN32
return !EnumWindows(EnumWindowsProcDownloader, 0); return !EnumWindows(EnumWindowsProcDownloader, 0);
#endif
return false;
} }
bool DownloaderSend::send_url(const wxString& url) const bool DownloaderSend::send_url(const wxString& url) const
{ {
#ifdef _WIN32
//std::string escaped = escape_strings_cstyle({ boost::nowide::narrow(url) }); //std::string escaped = escape_strings_cstyle({ boost::nowide::narrow(url) });
return send_message_downloader(url); return send_message_downloader(url);
#endif
return false;
} }

View File

@ -1248,8 +1248,7 @@ PageUpdate::PageUpdate(ConfigWizard *parent)
box_presets->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent &event) { this->preset_update = event.IsChecked(); }); box_presets->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent &event) { this->preset_update = event.IsChecked(); });
box_registry->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event) { box_registry->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event) {
//if(!event.IsChecked()) #ifdef _WIN32
// return;
// Registry key creation for "prusaslicer://" URL // Registry key creation for "prusaslicer://" URL
boost::filesystem::path binary_path(resources_dir()); boost::filesystem::path binary_path(resources_dir());
@ -1272,7 +1271,7 @@ PageUpdate::PageUpdate(ConfigWizard *parent)
} }
//key_full = "\"C:\\Program Files\\Prusa3D\\PrusaSlicer\\prusa-slicer-console.exe\" \"%1\""; //key_full = "\"C:\\Program Files\\Prusa3D\\PrusaSlicer\\prusa-slicer-console.exe\" \"%1\"";
key_full = key_string; key_full = key_string;
#endif
}); });
} }

View File

@ -420,6 +420,34 @@ void DesktopIntegrationDialog::perform_desktop_integration()
show_error(nullptr, _L("Performing desktop integration failed - could not create Gcodeviewer desktop file. PrusaSlicer desktop file was probably created successfully.")); show_error(nullptr, _L("Performing desktop integration failed - could not create Gcodeviewer desktop file. PrusaSlicer desktop file was probably created successfully."));
} }
} }
bool url_destop_file = true;
if (url_destop_file)
{
// no need for icon right?
std::string desktop_file = GUI::format(
"[Desktop Entry]\n"
"Name=PrusaSlicer URL Protocol%1%\n"
"Exec=\"%3%\" %%u\n"
"Terminal=false\n"
"Type=Application\n"
"MimeType=x-scheme-handler/prusaslicer;\n"
"StartupNotify=false\n"
, name_suffix, version_suffix, excutable_path);
std::string desktop_path = GUI::format("%1%/applications/PrusaSlicerURLProtocol%2%.desktop", target_dir_desktop, version_suffix);
if (create_desktop_file(desktop_path, desktop_file)) {
// save path to desktop file
//app_config->set("desktop_integration_app_viewer_path", desktop_path);
std::string command = GUI::format("xdg-mime default PrusaSlicerURLProtocol%1%.desktop x-scheme-handler/prusaslicer", version_suffix);
//std::string command = GUI::format("xdg-mime default PrusaSlicer%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;
} else {
BOOST_LOG_TRIVIAL(error) << "Performing desktop integration failed - could not create URL Protocol desktop file";
show_error(nullptr, _L("Performing desktop integration failed - could not create RL Protocol desktop file. PrusaSlicer desktop file was probably created successfully."));
}
}
wxGetApp().plater()->get_notification_manager()->push_notification(NotificationType::DesktopIntegrationSuccess); wxGetApp().plater()->get_notification_manager()->push_notification(NotificationType::DesktopIntegrationSuccess);
} }

View File

@ -201,7 +201,8 @@ FileArchiveDialog::FileArchiveDialog( mz_zip_archive* archive, std::vector<boost
stack.pop_back(); stack.pop_back();
}; };
// recursively stores whole structure of file onto function stack and synchoronize with stack object. // recursively stores whole structure of file onto function stack and synchoronize with stack object.
std::function<size_t(boost::filesystem::path&, std::vector<ArchiveViewNode*>&)> adjust_stack = [&adjust_stack, &reduce_stack, &avc = m_avc](boost::filesystem::path& file, std::vector<ArchiveViewNode*>& stack)->size_t { std::function<size_t(const boost::filesystem::path&, std::vector<ArchiveViewNode*>&)> adjust_stack = [&adjust_stack, &reduce_stack, &avc = m_avc](const boost::filesystem::path& const_file, std::vector<ArchiveViewNode*>& stack)->size_t {
boost::filesystem::path file(const_file);
size_t struct_size = file.has_parent_path() ? adjust_stack(file.parent_path(), stack) : 0; size_t struct_size = file.has_parent_path() ? adjust_stack(file.parent_path(), stack) : 0;
if (stack.size() > struct_size && (file.has_extension() || file.filename().string() != stack[struct_size]->get_name())) if (stack.size() > struct_size && (file.has_extension() || file.filename().string() != stack[struct_size]->get_name()))
@ -209,7 +210,7 @@ FileArchiveDialog::FileArchiveDialog( mz_zip_archive* archive, std::vector<boost
reduce_stack(stack, struct_size); reduce_stack(stack, struct_size);
} }
if (!file.has_extension() && stack.size() == struct_size) if (!file.has_extension() && stack.size() == struct_size)
stack.push_back(avc->get_model()->AddFile(stack.empty() ? nullptr : stack.back(), boost::nowide::widen(file.filename().string()))); stack.push_back(avc->get_model()->AddFile(stack.empty() ? nullptr : stack.back(), file.filename().string())); // filename string to wstring?
return struct_size + 1; return struct_size + 1;
}; };
@ -230,7 +231,7 @@ FileArchiveDialog::FileArchiveDialog( mz_zip_archive* archive, std::vector<boost
if (!stack.empty()) if (!stack.empty())
parent = stack.back(); parent = stack.back();
m_avc->get_model()->AddFile(parent, boost::nowide::widen(path.filename().string()))->set_fullpath(std::move(path)); m_avc->get_model()->AddFile(parent, path.filename().string())->set_fullpath(std::move(path)); // filename string to wstring?
} }
} }

View File

@ -4,8 +4,10 @@
#include "GUI_Utils.hpp" #include "GUI_Utils.hpp"
#include "libslic3r/miniz_extension.hpp" #include "libslic3r/miniz_extension.hpp"
#include <boost/filesystem/path.hpp>
#include <wx/wx.h> #include <wx/wx.h>
#include <wx/dataview.h>
#include "wxExtensions.hpp"
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {