mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-19 03:33:36 +01:00
AppIconsView: improve the way primary icons are handled
This commit is contained in:
@@ -28,6 +28,7 @@ struct AppIconsView: View {
|
|||||||
SpecialIcon(assetName: "Steel", suffix: "(Nightly)", forceIndex: 2),
|
SpecialIcon(assetName: "Steel", suffix: "(Nightly)", forceIndex: 2),
|
||||||
]
|
]
|
||||||
private var icons: [Icon] = []
|
private var icons: [Icon] = []
|
||||||
|
private var primaryIcon: Icon
|
||||||
|
|
||||||
@State private var selectedIcon: String? = "" // this is just so the list row background changes when selecting a value, I couldn't get it to keep the selected icon name (for some reason it was always "", even when I set it to the selected icon asset name)
|
@State private var selectedIcon: String? = "" // this is just so the list row background changes when selecting a value, I couldn't get it to keep the selected icon name (for some reason it was always "", even when I set it to the selected icon asset name)
|
||||||
@State private var selectedIconAssetName: String // FIXME: use selectedIcon instead
|
@State private var selectedIconAssetName: String // FIXME: use selectedIcon instead
|
||||||
@@ -35,9 +36,10 @@ struct AppIconsView: View {
|
|||||||
init() {
|
init() {
|
||||||
let bundleIcons = Bundle.main.object(forInfoDictionaryKey: "CFBundleIcons") as! [String: Any]
|
let bundleIcons = Bundle.main.object(forInfoDictionaryKey: "CFBundleIcons") as! [String: Any]
|
||||||
|
|
||||||
let primaryIcon = bundleIcons["CFBundlePrimaryIcon"] as! [String: Any]
|
let primaryIconData = bundleIcons["CFBundlePrimaryIcon"] as! [String: Any]
|
||||||
let primaryIconName = primaryIcon["CFBundleIconName"] as! String
|
let primaryIconName = primaryIconData["CFBundleIconName"] as! String
|
||||||
icons.append(Icon(displayName: primaryIconName, assetName: primaryIconName)) // ensure primary icon is first
|
primaryIcon = Icon(displayName: primaryIconName, assetName: primaryIconName)
|
||||||
|
icons.append(primaryIcon)
|
||||||
|
|
||||||
for (key, _) in bundleIcons["CFBundleAlternateIcons"] as! [String: Any] {
|
for (key, _) in bundleIcons["CFBundleAlternateIcons"] as! [String: Any] {
|
||||||
icons.append(Icon(displayName: key, assetName: key))
|
icons.append(Icon(displayName: key, assetName: key))
|
||||||
@@ -60,9 +62,9 @@ struct AppIconsView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let alternateIconName = UIApplication.shared.alternateIconName {
|
if let alternateIconName = UIApplication.shared.alternateIconName {
|
||||||
selectedIconAssetName = icons.first { $0.assetName == alternateIconName }?.assetName ?? icons[0].assetName
|
selectedIconAssetName = icons.first { $0.assetName == alternateIconName }?.assetName ?? primaryIcon.assetName
|
||||||
} else {
|
} else {
|
||||||
selectedIconAssetName = icons[0].assetName
|
selectedIconAssetName = primaryIcon.assetName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,8 +73,8 @@ struct AppIconsView: View {
|
|||||||
// FIXME: Button gives errors for some reason
|
// FIXME: Button gives errors for some reason
|
||||||
SwiftUI.Button(action: {
|
SwiftUI.Button(action: {
|
||||||
selectedIconAssetName = icon.assetName
|
selectedIconAssetName = icon.assetName
|
||||||
// Pass nil for original icon
|
// Pass nil for primary icon
|
||||||
UIApplication.shared.setAlternateIconName(icon.assetName == icons[0].assetName ? nil : icon.assetName, completionHandler: { error in
|
UIApplication.shared.setAlternateIconName(icon.assetName == primaryIcon.assetName ? nil : icon.assetName, completionHandler: { error in
|
||||||
if let error = error {
|
if let error = error {
|
||||||
print("error when setting alternate app icon to \(icon.assetName): \(error.localizedDescription)")
|
print("error when setting alternate app icon to \(icon.assetName): \(error.localizedDescription)")
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user