Skip to content

Commit

Permalink
feat: add appIcon
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Oct 1, 2024
1 parent e6a52af commit ea1c694
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ DeviceInfo.systemVersion.patchVersion // e.g "0"
DeviceInfo.systemMajorVersion // e.g "1"
DeviceInfo.systemMinorVersion // e.g "3"
DeviceInfo.systemPatchVersion // e.g "0"
```
DeviceInfo.appIcon // -> UIImage | NSImage
```
17 changes: 17 additions & 0 deletions Sources/DeviceInfo/DeviceInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ public struct DeviceInfo {
public static let isDarkMode: Bool = { NSApp?.effectiveAppearance.isDarkMode ?? false }()
#elseif canImport(WatchKit)
#endif

#if canImport(UIKit)
static let appIcon: UIImage? = getAppIcon()
static func getAppIcon() -> UIImage? {
if let iconsDictionary = Bundle.main.infoDictionary?["CFBundleIcons"] as? [String: Any],
let primaryIconsDictionary = iconsDictionary["CFBundlePrimaryIcon"] as? [String: Any],
let iconFiles = primaryIconsDictionary["CFBundleIconFiles"] as? [String],
let lastIcon = iconFiles.last {
return UIImage(named: lastIcon)
}
return nil
}
#elseif canImport(AppKit)
@MainActor
static let appIcon: NSImage = NSApp.applicationIconImage!
#elseif canImport(WatchKit)
#endif
}


Expand Down

0 comments on commit ea1c694

Please sign in to comment.