Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 78f33a7

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

3 files changed

+41-3Lines changed: 41 additions & 3 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/core.cpp‎

Copy file name to clipboardExpand all lines: src/core.cpp
+31-1Lines changed: 31 additions & 1 deletion
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
}
Collapse file

‎src/core.h‎

Copy file name to clipboardExpand all lines: src/core.h
+9-1Lines changed: 9 additions & 1 deletion
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
}
Collapse file

‎src/main.cpp‎

Copy file name to clipboardExpand all lines: src/main.cpp
+1-1Lines changed: 1 addition & 1 deletion
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.