Skip to content

Commit

Permalink
Merge pull request #57 from RakuyoKit/feature/2024-07-12
Browse files Browse the repository at this point in the history
Feature/2024-07-12
  • Loading branch information
rakuyoMo authored Jul 12, 2024
2 parents d2d3ef4 + b3101de commit bf0684c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Sources/Core/Extensions/Bundle+RAK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -102,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
Expand Down

0 comments on commit bf0684c

Please sign in to comment.