mirror of
https://github.com/audacity/linuxdeploy.git
synced 2026-07-02 20:08:02 -05:00
Move linuxdeploy-specific helper out of desktop file class
This commit is contained in:
32
src/core.cpp
32
src/core.cpp
@@ -39,7 +39,7 @@ namespace linuxdeploy {
|
||||
deployedDesktopFiles.begin(),
|
||||
deployedDesktopFiles.end(),
|
||||
[&firstDeployedDesktopFileName](const desktopfile::DesktopFile& desktopFile) {
|
||||
auto fileName = desktopFile.path().filename().string();
|
||||
auto fileName = desktopFile.path();
|
||||
return fileName == firstDeployedDesktopFileName;
|
||||
}
|
||||
);
|
||||
@@ -85,4 +85,34 @@ namespace linuxdeploy {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool addDefaultKeys(DesktopFile& desktopFile, const std::string& executableFileName) {
|
||||
ldLog() << "Adding default values to desktop file:" << desktopFile.path() << std::endl;
|
||||
|
||||
auto rv = true;
|
||||
|
||||
auto setDefault = [&rv, &desktopFile](const std::string& section, const std::string& key, const std::string& value) {
|
||||
if (desktopFile.entryExists(section, key)) {
|
||||
DesktopFileEntry entry;
|
||||
|
||||
// this should never return false
|
||||
auto entryExists = desktopFile.getEntry(section, key, entry);
|
||||
assert(entryExists);
|
||||
|
||||
ldLog() << LD_WARNING << "Key exists, not modified:" << key << "(current value:" << entry.value() << LD_NO_SPACE << ")" << std::endl;
|
||||
rv = false;
|
||||
} else {
|
||||
auto entryOverwritten = desktopFile.setEntry(section, DesktopFileEntry(key, value));
|
||||
assert(!entryOverwritten);
|
||||
}
|
||||
};
|
||||
|
||||
setDefault("Desktop Entry", "Name", executableFileName);
|
||||
setDefault("Desktop Entry", "Exec", executableFileName);
|
||||
setDefault("Desktop Entry", "Icon", executableFileName);
|
||||
setDefault("Desktop Entry", "Type", "Application");
|
||||
setDefault("Desktop Entry", "Categories", "Utility;");
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
10
src/core.h
10
src/core.h
@@ -7,7 +7,7 @@
|
||||
|
||||
namespace linuxdeploy {
|
||||
/**
|
||||
* Deploy the application ".deskop", icon, and runnable files in the AppDir root path. According to the
|
||||
* Deploy the application ".desktop", icon, and runnable files in the AppDir root path. According to the
|
||||
* AppDir spec at: https://docs.appimage.org/reference/appdir.html
|
||||
*
|
||||
* @param desktopFilePaths to be deployed in the AppDir root
|
||||
@@ -17,4 +17,12 @@ namespace linuxdeploy {
|
||||
*/
|
||||
bool deployAppDirRootFiles(std::vector<std::string> desktopFilePaths, std::string customAppRunPath,
|
||||
linuxdeploy::core::appdir::AppDir& appDir);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param desktopFile
|
||||
* @param executableFileName
|
||||
* @return
|
||||
*/
|
||||
bool addDefaultKeys(desktopfile::DesktopFile& desktopFile, const std::string& executableFileName);
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
desktopfile::DesktopFile desktopFile;
|
||||
if (!desktopFile.addDefaultKeys(executableName)) {
|
||||
if (!addDefaultKeys(desktopFile, executableName)) {
|
||||
ldLog() << LD_WARNING << "Tried to overwrite existing entries in desktop file:" << desktopFilePath << std::endl;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user