Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added the ability to set custom app icons for windows / macos #819

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/src/processing/app/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,18 @@ public void load(File additions) {
// check for platform-specific properties in the defaults
String platformExt = "." + Platform.getName();
int platformExtLength = platformExt.length();
HashMap<String,String> tmpMap = new HashMap<>();
for (String key : table.keySet()) {
if (key.endsWith(platformExt)) {
// this is a key specific to a particular platform
String actualKey = key.substring(0, key.length() - platformExtLength);
String value = get(key);
table.put(actualKey, value);
//if the key is specific to this platform and is not the last property then attempting to append it to the map will throw a ConcurrentModificationException
//to avoid this we append it to a temporary map that can then be safely merged after the loop is complete
tmpMap.put(actualKey, value);
}
}
table.putAll(tmpMap);
}


Expand Down
25 changes: 23 additions & 2 deletions java/src/processing/mode/java/JavaBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,18 @@ protected boolean exportApplication(File destFolder,
File resourcesFolder = new File(contentsFolder, "Resources");
Util.copyDir(new File(contentsOrig, "Resources/en.lproj"),
new File(resourcesFolder, "en.lproj"));
Util.copyFile(mode.getContentFile("application/application.icns"),

Settings sketchProperties = new Settings(new File(sketch.getFolder(), "sketch.properties"));
String iconPath = sketchProperties.get("icon");//icon.macos
File iconFile;
if(iconPath == null || iconPath.isEmpty()){
iconFile = mode.getContentFile("application/application.icns");
System.out.println("using default icon");
}else {
iconFile = new File(sketch.getFolder(), iconPath);
System.out.println("found custom icon: "+iconPath);
}
Util.copyFile(iconFile,
new File(resourcesFolder, "application.icns"));

} else if (exportPlatform == PConstants.LINUX) {
Expand Down Expand Up @@ -958,7 +969,17 @@ protected boolean exportApplication(File destFolder,
File exeFile = new File(destFolder, sketch.getName() + ".exe");
config.addChild("outfile").setContent(exeFile.getAbsolutePath());

File iconFile = mode.getContentFile("application/application.ico");
//check sketch.properties to see if an icon was set
Settings sketchProperties = new Settings(new File(sketch.getFolder(), "sketch.properties"));
String iconPath = sketchProperties.get("icon");//icon.windows
File iconFile;
if(iconPath == null || iconPath.isEmpty()){
iconFile = mode.getContentFile("application/application.ico");
System.out.println("using default icon");
}else {
iconFile = new File(sketch.getFolder(), iconPath);
System.out.println("found custom icon: "+iconPath);
}
config.addChild("icon").setContent(iconFile.getAbsolutePath());

XML clazzPath = config.addChild("classPath");
Expand Down