commit 34ed9726034adbb439515ccb3d576311603bfe2b
Author: Chris Rittenhouse <dev@litritt.com>
Date: Thu Aug 3 15:31:47 2023 -0400
Removes `experimentalFeatures` property from `Settings`
commit 4e31d22d56d68439a340707d2fdbac3763df1e3a
Author: Chris Rittenhouse <dev@litritt.com>
Date: Thu Aug 3 15:17:47 2023 -0400
Reorder icons
commit 7509eaa29946b622ce0ad920a740f0212db5e771
Author: Chris Rittenhouse <dev@litritt.com>
Date: Thu Aug 3 15:17:24 2023 -0400
Moves icon changing code to `AlternateAppIcons`
commit 84821ef99ded74c066563041618aec3c4acb30d7
Author: Chris Rittenhouse <dev@litritt.com>
Date: Thu Aug 3 14:33:15 2023 -0400
Fixes icon authors
commit 0b821830f09b434fa375c37a2504c21ee5f90bdb
Author: Chris Rittenhouse <dev@litritt.com>
Date: Fri Jul 21 01:44:00 2023 -0400
Adds comments for functional alternate app icon code
commit e8dd6165619bc143f13dde51e5160af2695ef17e
Author: Chris Rittenhouse <dev@litritt.com>
Date: Fri Jul 21 01:30:03 2023 -0400
Adds implementation for changing app icon
commit 1e07483d18d1e865804ae34d6011844b63cb33cc
Author: Chris Rittenhouse <dev@litritt.com>
Date: Fri Jul 21 01:28:24 2023 -0400
Adds Alternate App Icon experimental feature and options
commit 46ed2ce3ae9593d4cc95f29d6caa09f33f2ce62d
Author: Chris Rittenhouse <dev@litritt.com>
Date: Fri Jul 21 01:26:51 2023 -0400
Adds extension to handle retrieving app icon images
commit 9dddb5f98f4523e7877f97c66a5ae95e6513cc09
Author: Chris Rittenhouse <dev@litritt.com>
Date: Fri Jul 21 01:24:19 2023 -0400
Adds experimental features as a property of `Settings`
commit d74038fd418a0e6fcd45942cb67e722904fc3e24
Author: Chris Rittenhouse <dev@litritt.com>
Date: Fri Jul 21 01:23:02 2023 -0400
Adds alternate icon assets
Co-authored-by: Chris Rittenhouse <dev@litritt.com>
125 lines
3.3 KiB
Swift
125 lines
3.3 KiB
Swift
//
|
|
// AlternateAppIcons.swift
|
|
// Delta
|
|
//
|
|
// Created by Chris Rittenhouse on 5/2/23.
|
|
// Copyright © 2023 LitRitt. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
import DeltaFeatures
|
|
|
|
enum AppIcon: String, CaseIterable, CustomStringConvertible, Identifiable
|
|
{
|
|
case normal = "Default"
|
|
case gba4ios = "GBA4iOS"
|
|
case inverted = "Inverted"
|
|
case pixelated = "Pixelated"
|
|
case skin = "Controller Skin"
|
|
|
|
var description: String {
|
|
return self.rawValue
|
|
}
|
|
|
|
var id: String {
|
|
return self.rawValue
|
|
}
|
|
|
|
var author: String {
|
|
switch self
|
|
{
|
|
case .normal: return "Caroline Moore"
|
|
case .gba4ios: return "Paul Thorsen"
|
|
case .inverted, .skin, .pixelated: return "LitRitt"
|
|
}
|
|
}
|
|
|
|
var assetName: String {
|
|
switch self
|
|
{
|
|
case .normal: return "AppIcon"
|
|
case .gba4ios: return "IconGBA4iOS"
|
|
case .inverted: return "IconInverted"
|
|
case .pixelated: return "IconPixelated"
|
|
case .skin: return "IconSkin"
|
|
}
|
|
}
|
|
}
|
|
|
|
extension AppIcon: Equatable
|
|
{
|
|
static func == (lhs: AppIcon, rhs: AppIcon) -> Bool
|
|
{
|
|
return lhs.description == rhs.description
|
|
}
|
|
}
|
|
|
|
extension AppIcon: LocalizedOptionValue
|
|
{
|
|
var localizedDescription: Text {
|
|
Text(self.description)
|
|
}
|
|
}
|
|
|
|
struct AlternateAppIconOptions
|
|
{
|
|
@Option(name: "Alternate App Icon",
|
|
description: "Choose from alternate app icons created by the community.",
|
|
detailView: { value in
|
|
List {
|
|
ForEach(AppIcon.allCases) { icon in
|
|
HStack {
|
|
if icon == value.wrappedValue
|
|
{
|
|
Text("✓")
|
|
}
|
|
icon.localizedDescription
|
|
Text("- by \(icon.author)")
|
|
.font(.system(size: 15))
|
|
.foregroundColor(.gray)
|
|
Spacer()
|
|
Image(uiImage: Bundle.appIcon(for: icon) ?? UIImage())
|
|
.cornerRadius(13)
|
|
}
|
|
.contentShape(Rectangle())
|
|
.onTapGesture {
|
|
value.wrappedValue = icon
|
|
}
|
|
}
|
|
}
|
|
.onChange(of: value.wrappedValue) { _ in
|
|
updateAppIcon()
|
|
}
|
|
.displayInline()
|
|
})
|
|
var icon: AppIcon = .normal
|
|
}
|
|
|
|
extension AlternateAppIconOptions
|
|
{
|
|
static func updateAppIcon()
|
|
{
|
|
// Get current icon
|
|
let currentIcon = UIApplication.shared.alternateIconName
|
|
|
|
// Apply chosen icon if feature is enabled
|
|
if ExperimentalFeatures.shared.alternateAppIcons.isEnabled
|
|
{
|
|
let icon = ExperimentalFeatures.shared.alternateAppIcons.icon
|
|
|
|
// Only apply new icon if it's not already the current icon
|
|
switch icon
|
|
{
|
|
case .normal: if currentIcon != nil { UIApplication.shared.setAlternateIconName(nil) } // Default app icon
|
|
default: if currentIcon != icon.assetName { UIApplication.shared.setAlternateIconName(icon.assetName) } // Alternate app icon
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Remove alternate icons if feature is disabled
|
|
if currentIcon != nil { UIApplication.shared.setAlternateIconName(nil) }
|
|
}
|
|
}
|
|
}
|