From 1ff54636c57cfafd0d9ba78065267393197df013 Mon Sep 17 00:00:00 2001 From: Rakuyo Date: Fri, 12 Jul 2024 15:35:36 +0800 Subject: [PATCH 1/2] feat: Improve the Bundle extension --- Sources/Core/Extensions/Bundle+RAK.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/Core/Extensions/Bundle+RAK.swift b/Sources/Core/Extensions/Bundle+RAK.swift index 10d6113..2f04d3e 100644 --- a/Sources/Core/Extensions/Bundle+RAK.swift +++ b/Sources/Core/Extensions/Bundle+RAK.swift @@ -26,7 +26,15 @@ extension Extendable where Base: Bundle { } public static func appName(from: From = .app) -> String { - getValue(by: "CFBundleDisplayName", from: from) ?? getValue(by: "CFBundleName", from: from) ?? "" + displayName(from: from) ?? bundleName(from: from) ?? "" + } + + public static func bundleName(from: From = .app) -> String? { + getValue(by: "CFBundleName", from: from) + } + + public static func displayName(from: From = .app) -> String? { + getValue(by: "CFBundleDisplayName", from: from) } public static func shortVersionString(from: From = .app) -> String { From b3101def022acefc3e1766ec44efaa623cc38b76 Mon Sep 17 00:00:00 2001 From: Rakuyo Date: Fri, 12 Jul 2024 15:37:42 +0800 Subject: [PATCH 2/2] feat: Update --- Sources/Core/Extensions/Bundle+RAK.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/Core/Extensions/Bundle+RAK.swift b/Sources/Core/Extensions/Bundle+RAK.swift index 2f04d3e..2307f5d 100644 --- a/Sources/Core/Extensions/Bundle+RAK.swift +++ b/Sources/Core/Extensions/Bundle+RAK.swift @@ -110,12 +110,14 @@ extension Extendable where Base: Bundle { extension Extendable where Base: Bundle { /// Return the main bundle when in the app or an app extension. fileprivate static var app: Bundle { - var components = Bundle.main.bundleURL.path.split(separator: "/") - var bundle: Bundle? + var components = Base.main.bundleURL.path.split(separator: "/") + let bundle: Base? if let index = components.lastIndex(where: { $0.hasSuffix(".app") }) { components.removeLast((components.count - 1) - index) - bundle = Bundle(path: components.joined(separator: "/")) + bundle = .init(path: components.joined(separator: "/")) + } else { + bundle = nil } return bundle ?? .main