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

[macOS, 3.x] Prefer .app bundle icon over the default one. #48686

Merged
merged 1 commit into from
Sep 30, 2021
Merged
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
5 changes: 5 additions & 0 deletions core/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ String OS::get_bundle_resource_dir() const {
return ".";
};

// Path to macOS .app bundle embedded icon
String OS::get_bundle_icon_path() const {
return String();
}

// OS specific path for user://
String OS::get_user_data_dir() const {
return ".";
Expand Down
1 change: 1 addition & 0 deletions core/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ class OS {
virtual String get_config_path() const;
virtual String get_cache_path() const;
virtual String get_bundle_resource_dir() const;
virtual String get_bundle_icon_path() const;

virtual String get_user_data_dir() const;
virtual String get_resource_dir() const;
Expand Down
8 changes: 5 additions & 3 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1365,8 +1365,10 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
}

#ifdef TOOLS_ENABLED
Ref<Image> icon = memnew(Image(app_icon_png));
OS::get_singleton()->set_icon(icon);
if (OS::get_singleton()->get_bundle_icon_path().empty()) {
Ref<Image> icon = memnew(Image(app_icon_png));
OS::get_singleton()->set_icon(icon);
}
#endif
}

Expand Down Expand Up @@ -1989,7 +1991,7 @@ bool Main::start() {
#endif
}

if (!hasicon) {
if (!hasicon && OS::get_singleton()->get_bundle_icon_path().empty()) {
Ref<Image> icon = memnew(Image(app_icon_png));
OS::get_singleton()->set_icon(icon);
}
Expand Down
1 change: 1 addition & 0 deletions platform/osx/os_osx.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class OS_OSX : public OS_Unix {
virtual String get_data_path() const;
virtual String get_cache_path() const;
virtual String get_bundle_resource_dir() const;
virtual String get_bundle_icon_path() const;
virtual String get_godot_dir_name() const;

virtual String get_system_dir(SystemDir p_dir) const;
Expand Down
20 changes: 16 additions & 4 deletions platform/osx/os_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2266,14 +2266,26 @@ virtual void log_error(const char *p_function, const char *p_file, int p_line, c
}

String OS_OSX::get_bundle_resource_dir() const {
String ret;

NSBundle *main = [NSBundle mainBundle];
NSString *resourcePath = [main resourcePath];
if (main) {
NSString *resourcePath = [main resourcePath];
ret.parse_utf8([resourcePath UTF8String]);
}
return ret;
}

char *utfs = strdup([resourcePath UTF8String]);
String OS_OSX::get_bundle_icon_path() const {
String ret;
ret.parse_utf8(utfs);
free(utfs);

NSBundle *main = [NSBundle mainBundle];
if (main) {
NSString *iconPath = [[main infoDictionary] objectForKey:@"CFBundleIconFile"];
if (iconPath) {
ret.parse_utf8([iconPath UTF8String]);
}
}
return ret;
}

Expand Down