Skip to content

Commit

Permalink
feat: update localized bundle names
Browse files Browse the repository at this point in the history
  • Loading branch information
khcrysalis committed Oct 1, 2024
1 parent d04676a commit 0061c73
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Shared/Signing/AppSigner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ func updateInfoPlist(infoDict: NSMutableDictionary, options: AppSigningOptions,
Debug.shared.log(message: "updateInfoPlist.updateicon: Does not include an icon! Will not do this.")
}

if infoDict.value(forKey: "CFBundleDisplayName") as? String != options.name {
try updateLocalizedInfoPlist(in: app, newDisplayName: options.name!)
}

if options.forceFileSharing! { infoDict.setObject(true, forKey: "UISupportsDocumentBrowser" as NSCopying) }
if options.forceiTunesFileSharing! { infoDict.setObject(true, forKey: "UIFileSharingEnabled" as NSCopying) }
if options.removeSupportedDevices! { infoDict.removeObject(forKey: "UISupportedDevices") }
Expand All @@ -295,3 +299,24 @@ func updateInfoPlist(infoDict: NSMutableDictionary, options: AppSigningOptions,
if options.forceLightDarkAppearence! != "Automatic" { infoDict.setObject(options.forceLightDarkAppearence!, forKey: "UIUserInterfaceStyle" as NSCopying)}
try infoDict.write(to: app.appendingPathComponent("Info.plist"))
}

func updateLocalizedInfoPlist(in appDirectory: URL, newDisplayName: String) throws {
let fileManager = FileManager.default
let contents = try fileManager.contentsOfDirectory(at: appDirectory, includingPropertiesForKeys: nil)
let localizationBundles = contents.filter { $0.pathExtension == "lproj" }

for localizationBundle in localizationBundles {
let infoPlistStringsURL = localizationBundle.appendingPathComponent("InfoPlist.strings")

if fileManager.fileExists(atPath: infoPlistStringsURL.path) {
var localizedStrings = try String(contentsOf: infoPlistStringsURL, encoding: .utf8)
let localizedDict = NSDictionary(contentsOf: infoPlistStringsURL) as! [String: String]

if localizedDict["CFBundleDisplayName"] != newDisplayName {
localizedStrings = localizedStrings.replacingOccurrences(of: localizedDict["CFBundleDisplayName"] ?? "", with: newDisplayName)
try localizedStrings.write(to: infoPlistStringsURL, atomically: true, encoding: .utf8)
Debug.shared.log(message: "Updated CFBundleDisplayName in \(infoPlistStringsURL.path)")
}
}
}
}

0 comments on commit 0061c73

Please sign in to comment.