diff --git a/core/os/os.cpp b/core/os/os.cpp index 7505f3ff349c..69366f688c81 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -282,6 +282,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 "."; diff --git a/core/os/os.h b/core/os/os.h index c0274284779a..29d33ce4f005 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -252,6 +252,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; diff --git a/main/main.cpp b/main/main.cpp index d512c41e7a79..7d7c9d737450 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1721,8 +1721,10 @@ Error Main::setup2(Thread::ID p_main_tid_override) { } #ifdef TOOLS_ENABLED - Ref icon = memnew(Image(app_icon_png)); - DisplayServer::get_singleton()->set_icon(icon); + if (OS::get_singleton()->get_bundle_icon_path().is_empty()) { + Ref icon = memnew(Image(app_icon_png)); + DisplayServer::get_singleton()->set_icon(icon); + } #endif } @@ -2440,7 +2442,7 @@ bool Main::start() { #endif } - if (!hasicon) { + if (!hasicon && OS::get_singleton()->get_bundle_icon_path().is_empty()) { Ref icon = memnew(Image(app_icon_png)); DisplayServer::get_singleton()->set_icon(icon); } diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index df41ccd89216..a52436a70ac9 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -82,6 +82,7 @@ class OS_OSX : public OS_Unix { virtual String get_data_path() const override; virtual String get_cache_path() const override; virtual String get_bundle_resource_dir() const override; + virtual String get_bundle_icon_path() const override; virtual String get_godot_dir_name() const override; virtual String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const override; diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index c6e35fee83bf..6ef1bdbd11f1 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -379,14 +379,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; }