Merge pull request #48686 from bruvzg/bundle_icon_3

This commit is contained in:
Rémi Verschelde 2021-09-30 14:55:41 +02:00 committed by GitHub
commit 7c9e06f936
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 9 deletions

View file

@ -335,6 +335,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 ".";

View file

@ -436,6 +436,7 @@ public:
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;

View file

@ -1394,8 +1394,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
}
@ -2043,7 +2045,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);
}

View file

@ -225,6 +225,7 @@ public:
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, bool p_shared_storage = true) const;

View file

@ -2285,14 +2285,26 @@ String OS_OSX::get_cache_path() const {
}
String OS_OSX::get_bundle_resource_dir() const {
NSBundle *main = [NSBundle mainBundle];
NSString *resourcePath = [main resourcePath];
char *utfs = strdup([resourcePath UTF8String]);
String ret;
ret.parse_utf8(utfs);
free(utfs);
NSBundle *main = [NSBundle mainBundle];
if (main) {
NSString *resourcePath = [main resourcePath];
ret.parse_utf8([resourcePath UTF8String]);
}
return ret;
}
String OS_OSX::get_bundle_icon_path() const {
String ret;
NSBundle *main = [NSBundle mainBundle];
if (main) {
NSString *iconPath = [[main infoDictionary] objectForKey:@"CFBundleIconFile"];
if (iconPath) {
ret.parse_utf8([iconPath UTF8String]);
}
}
return ret;
}