Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 78f33a7

Browse files
committed
Move linuxdeploy-specific helper out of desktop file class
1 parent 3df27ba commit 78f33a7

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

src/core.cpp

+31-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace linuxdeploy {
3939
deployedDesktopFiles.begin(),
4040
deployedDesktopFiles.end(),
4141
[&firstDeployedDesktopFileName](const desktopfile::DesktopFile& desktopFile) {
42-
auto fileName = desktopFile.path().filename().string();
42+
auto fileName = desktopFile.path();
4343
return fileName == firstDeployedDesktopFileName;
4444
}
4545
);
@@ -85,4 +85,34 @@ namespace linuxdeploy {
8585
return false;
8686
}
8787
}
88+
89+
bool addDefaultKeys(DesktopFile& desktopFile, const std::string& executableFileName) {
90+
ldLog() << "Adding default values to desktop file:" << desktopFile.path() << std::endl;
91+
92+
auto rv = true;
93+
94+
auto setDefault = [&rv, &desktopFile](const std::string& section, const std::string& key, const std::string& value) {
95+
if (desktopFile.entryExists(section, key)) {
96+
DesktopFileEntry entry;
97+
98+
// this should never return false
99+
auto entryExists = desktopFile.getEntry(section, key, entry);
100+
assert(entryExists);
101+
102+
ldLog() << LD_WARNING << "Key exists, not modified:" << key << "(current value:" << entry.value() << LD_NO_SPACE << ")" << std::endl;
103+
rv = false;
104+
} else {
105+
auto entryOverwritten = desktopFile.setEntry(section, DesktopFileEntry(key, value));
106+
assert(!entryOverwritten);
107+
}
108+
};
109+
110+
setDefault("Desktop Entry", "Name", executableFileName);
111+
setDefault("Desktop Entry", "Exec", executableFileName);
112+
setDefault("Desktop Entry", "Icon", executableFileName);
113+
setDefault("Desktop Entry", "Type", "Application");
114+
setDefault("Desktop Entry", "Categories", "Utility;");
115+
116+
return rv;
117+
}
88118
}

src/core.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace linuxdeploy {
99
/**
10-
* Deploy the application ".deskop", icon, and runnable files in the AppDir root path. According to the
10+
* Deploy the application ".desktop", icon, and runnable files in the AppDir root path. According to the
1111
* AppDir spec at: https://docs.appimage.org/reference/appdir.html
1212
*
1313
* @param desktopFilePaths to be deployed in the AppDir root
@@ -17,4 +17,12 @@ namespace linuxdeploy {
1717
*/
1818
bool deployAppDirRootFiles(std::vector<std::string> desktopFilePaths, std::string customAppRunPath,
1919
linuxdeploy::core::appdir::AppDir& appDir);
20+
21+
/**
22+
*
23+
* @param desktopFile
24+
* @param executableFileName
25+
* @return
26+
*/
27+
bool addDefaultKeys(desktopfile::DesktopFile& desktopFile, const std::string& executableFileName);
2028
}

src/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ int main(int argc, char** argv) {
245245
}
246246

247247
desktopfile::DesktopFile desktopFile;
248-
if (!desktopFile.addDefaultKeys(executableName)) {
248+
if (!addDefaultKeys(desktopFile, executableName)) {
249249
ldLog() << LD_WARNING << "Tried to overwrite existing entries in desktop file:" << desktopFilePath << std::endl;
250250
}
251251

0 commit comments

Comments
 (0)