Merge branch 'dk_desktop'

This commit is contained in:
David Kocik 2023-02-07 10:17:05 +01:00
commit 0295af2ada

View File

@ -338,26 +338,30 @@ void DesktopIntegrationDialog::perform_desktop_integration(bool perform_download
"StartupNotify=false\n" "StartupNotify=false\n"
"StartupWMClass=prusa-slicer\n", name_suffix, version_suffix, excutable_path); "StartupWMClass=prusa-slicer\n", name_suffix, version_suffix, excutable_path);
bool candidate_found = false;
for (size_t i = 0; i < target_candidates.size(); ++i) { for (size_t i = 0; i < target_candidates.size(); ++i) {
if (contains_path_dir(target_candidates[i], "applications")) { if (contains_path_dir(target_candidates[i], "applications")) {
target_dir_desktop = target_candidates[i]; target_dir_desktop = target_candidates[i];
// Write slicer desktop file // Write slicer desktop file
std::string path = GUI::format("%1%/applications/PrusaSlicer%2%.desktop", target_dir_desktop, version_suffix); std::string path = GUI::format("%1%/applications/PrusaSlicer%2%.desktop", target_dir_desktop, version_suffix);
if (create_desktop_file(path, desktop_file)){ if (create_desktop_file(path, desktop_file)) {
candidate_found = true;
BOOST_LOG_TRIVIAL(debug) << "PrusaSlicer.desktop file installation success."; BOOST_LOG_TRIVIAL(debug) << "PrusaSlicer.desktop file installation success.";
break; break;
} else { }
else {
// write failed - try another path // write failed - try another path
BOOST_LOG_TRIVIAL(debug) << "Attempt to PrusaSlicer.desktop file installation failed. failed path: " << target_candidates[i]; BOOST_LOG_TRIVIAL(debug) << "Attempt to PrusaSlicer.desktop file installation failed. failed path: " << target_candidates[i];
target_dir_desktop.clear(); target_dir_desktop.clear();
} }
} }
}
// if all failed - try creating default home folder // if all failed - try creating default home folder
if (i == target_candidates.size() - 1) { if (!candidate_found) {
// create $HOME/.local/share // create $HOME/.local/share
create_path(boost::nowide::narrow(wxFileName::GetHomeDir()), ".local/share/applications"); create_path(boost::nowide::narrow(wxFileName::GetHomeDir()), ".local/share/applications");
// create desktop file // create desktop file
target_dir_desktop = GUI::format("%1%/.local/share",wxFileName::GetHomeDir()); target_dir_desktop = GUI::format("%1%/.local/share", wxFileName::GetHomeDir());
std::string path = GUI::format("%1%/applications/PrusaSlicer%2%.desktop", target_dir_desktop, version_suffix); std::string path = GUI::format("%1%/applications/PrusaSlicer%2%.desktop", target_dir_desktop, version_suffix);
if (contains_path_dir(target_dir_desktop, "applications")) { if (contains_path_dir(target_dir_desktop, "applications")) {
if (!create_desktop_file(path, desktop_file)) { if (!create_desktop_file(path, desktop_file)) {
@ -365,14 +369,15 @@ void DesktopIntegrationDialog::perform_desktop_integration(bool perform_download
BOOST_LOG_TRIVIAL(error) << "Performing desktop integration failed - could not create desktop file"; BOOST_LOG_TRIVIAL(error) << "Performing desktop integration failed - could not create desktop file";
return; return;
} }
} else { }
else {
// Desktop file not written - end desktop integration // Desktop file not written - end desktop integration
BOOST_LOG_TRIVIAL(error) << "Performing desktop integration failed because the application directory was not found."; BOOST_LOG_TRIVIAL(error) << "Performing desktop integration failed because the application directory was not found.";
return; return;
} }
} }
} assert(!target_dir_desktop.empty());
if(target_dir_desktop.empty()) { if (target_dir_desktop.empty()) {
// Desktop file not written - end desktop integration // Desktop file not written - end desktop integration
BOOST_LOG_TRIVIAL(error) << "Performing desktop integration failed because the application directory was not found."; BOOST_LOG_TRIVIAL(error) << "Performing desktop integration failed because the application directory was not found.";
show_error(nullptr, _L("Performing desktop integration failed because the application directory was not found.")); show_error(nullptr, _L("Performing desktop integration failed because the application directory was not found."));