Skip to content

Commit

Permalink
fix: win: compile linuxtuils only on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
elsamuko committed Jan 28, 2023
1 parent 844f6a1 commit a3fef0d
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/linuxutils.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "linuxutils.hpp"
#if BOOST_OS_LINUX

#include "boost/process/child.hpp"
#include "boost/process/search_path.hpp"
Expand All @@ -16,23 +17,23 @@ namespace bp = boost::process;
//! return dir of snap program
//! \arg browser, e.g. "firefox"
//! \returns snap dir, e.g. "~/snap/firefox"
fs::path snapDir(const std::string& browser) {
const char* home = getenv("HOME");
fs::path snapDir( const std::string& browser ) {
const char* home = getenv( "HOME" );

if(!home) { return {}; }
if( !home ) { return {}; }

return fs::path(home) / "snap" / browser;
return fs::path( home ) / "snap" / browser;
}

//! return default program for mimetype
//! \arg mime e.g. "text/html"
//! \returns program, e.g. "firefox.desktop"
std::string queryOpen(const std::string& mime) {
std::string queryOpen( const std::string& mime ) {
bp::ipstream out;

std::vector<std::string> outline;

bp::child nm(bp::search_path("xdg-mime"), bp::args({"query", "default", mime}), bp::std_out > out);
bp::child nm( bp::search_path( "xdg-mime" ), bp::args( {"query", "default", mime} ), bp::std_out > out );

std::string value;
out >> value;
Expand All @@ -41,29 +42,31 @@ std::string queryOpen(const std::string& mime) {
}

//! check if browser is a snap browser
bool defaultBrowserIsSnap(const std::string& browser) {
bool defaultBrowserIsSnap( const std::string& browser ) {

fs::path snap = snapDir(browser);
fs::path snap = snapDir( browser );

if(snap.empty()) { return false; }
if( snap.empty() ) { return false; }

if(!fs::exists(snap)) { return false; }
if( !fs::exists( snap ) ) { return false; }

std::string program = queryOpen("text/html");
std::string program = queryOpen( "text/html" );
return program == browser + ".desktop";
}

fs::path copyToSnapDir(const boost::filesystem::path& orig) {
fs::path copyToSnapDir( const boost::filesystem::path& orig ) {

for(auto&& browser : {"firefox", "chromium" }) {
if(defaultBrowserIsSnap(browser)) {
fs::path newDir = snapDir(browser) / "fsrc";
for( auto&& browser : {"firefox", "chromium" } ) {
if( defaultBrowserIsSnap( browser ) ) {
fs::path newDir = snapDir( browser ) / "fsrc";
fs::path copy = newDir / orig.filename();
fs::create_directories(newDir);
fs::copy(orig, copy, fs::copy_options::overwrite_existing);
fs::create_directories( newDir );
fs::copy( orig, copy, fs::copy_options::overwrite_existing );
return copy;
}
}

return orig;
}

#endif // BOOST_OS_LINUX

0 comments on commit a3fef0d

Please sign in to comment.