2022-11-23 22:34:02 +01:00
//
// S e t t i n g s V i e w . s w i f t
// S i d e S t o r e U I
//
// C r e a t e d b y F a b i a n T h i e s o n 1 8 . 1 1 . 2 2 .
// C o p y r i g h t © 2 0 2 2 F a b i a n T h i e s . A l l r i g h t s r e s e r v e d .
//
import SwiftUI
2022-11-27 00:26:15 +01:00
import AsyncImage
2022-12-23 15:21:16 +01:00
import SFSafeSymbols
2022-11-23 22:34:02 +01:00
import AltStoreCore
import Intents
struct SettingsView : View {
2022-12-12 19:12:38 +01:00
var connectedAppleID : Team ? {
DatabaseManager . shared . activeTeam ( )
}
@ SwiftUI . FetchRequest ( sortDescriptors : [ ] , predicate : NSPredicate ( format : " %K == YES " , # keyPath ( Team . isActiveTeam ) ) )
var connectedTeams : FetchedResults < Team >
2022-11-23 22:34:02 +01:00
@ AppStorage ( " isBackgroundRefreshEnabled " )
var isBackgroundRefreshEnabled : Bool = true
2022-12-12 19:12:38 +01:00
@ State var isShowingConnectAppleIDView = false
2022-11-23 22:34:02 +01:00
@ State var isShowingAddShortcutView = false
2022-12-12 19:12:38 +01:00
let appVersion = Bundle . main . infoDictionary ? [ " CFBundleShortVersionString " ] as ? String ? ? " "
2022-11-23 22:34:02 +01:00
var body : some View {
List {
Section {
2022-12-12 19:12:38 +01:00
if let connectedAppleID = connectedTeams . first {
2022-11-23 22:34:02 +01:00
HStack {
Text ( " Name " )
. foregroundColor ( . secondary )
Spacer ( )
2022-12-12 19:12:38 +01:00
Text ( connectedAppleID . name )
2022-11-23 22:34:02 +01:00
}
HStack {
Text ( " E-Mail " )
. foregroundColor ( . secondary )
Spacer ( )
2022-12-12 19:12:38 +01:00
Text ( connectedAppleID . account . appleID )
2022-11-23 22:34:02 +01:00
}
HStack {
Text ( " Type " )
. foregroundColor ( . secondary )
Spacer ( )
2022-12-12 19:12:38 +01:00
Text ( connectedAppleID . type . localizedDescription )
2022-11-23 22:34:02 +01:00
}
2022-12-12 19:12:38 +01:00
} else {
2022-11-23 22:34:02 +01:00
SwiftUI . Button {
2022-12-12 19:12:38 +01:00
self . connectAppleID ( )
2022-11-23 22:34:02 +01:00
} label : {
2022-12-12 19:12:38 +01:00
Text ( " Connect your Apple ID " )
}
}
} header : {
if ! connectedTeams . isEmpty {
HStack {
Text ( " Connected Apple ID " )
Spacer ( )
SwiftUI . Button {
self . disconnectAppleID ( )
} label : {
Text ( " Sign Out " )
. font ( . callout )
. bold ( )
}
2022-11-23 22:34:02 +01:00
}
}
2022-12-12 19:12:38 +01:00
} footer : {
VStack ( spacing : 4 ) {
Text ( " Your Apple ID is required to sign the apps you install with SideStore. " )
Text ( " Your credentials are only sent to Apple's servers and are not accessible by the SideStore Team. Once successfully logged in, the login details are stored securely on your device. " )
}
2022-11-23 22:34:02 +01:00
}
Section {
Toggle ( isOn : self . $ isBackgroundRefreshEnabled , label : {
Text ( " Background Refresh " )
} )
2022-12-12 19:12:38 +01:00
SwiftUI . Button {
self . isShowingAddShortcutView = true
} label : {
Text ( " Add to Siri... " )
}
. sheet ( isPresented : self . $ isShowingAddShortcutView ) {
if let shortcut = INShortcut ( intent : INInteraction . refreshAllApps ( ) . intent ) {
SiriShortcutSetupView ( shortcut : shortcut )
2022-11-23 22:34:02 +01:00
}
}
} header : {
Text ( " Refreshing Apps " )
} footer : {
Text ( " Enable Background Refresh to automatically refresh apps in the background when connected to WiFi and with Wireguard active. " )
}
Section {
SwiftUI . Button ( action : switchToUIKit ) {
Text ( " Switch to UIKit " )
}
2022-11-27 00:26:15 +01:00
SwiftUI . Button ( action : resetImageCache ) {
Text ( " Reset Image Cache " )
}
2022-11-23 22:34:02 +01:00
} header : {
Text ( " Debug " )
}
Section {
NavigationLink {
SafariView ( url : URL ( string : " https://fabian-thies.de " ) ! )
} label : {
HStack {
Text ( " SwiftUI Redesign " )
. foregroundColor ( . secondary )
Spacer ( )
Text ( " fabianthdev " )
}
}
} header : {
Text ( " Credits " )
}
Section {
} footer : {
2022-12-12 19:12:38 +01:00
Text ( " SideStore \( appVersion ) " )
2022-11-23 22:34:02 +01:00
. multilineTextAlignment ( . center )
. frame ( maxWidth : . infinity )
}
}
. listStyle ( InsetGroupedListStyle ( ) )
. navigationTitle ( " Settings " )
. toolbar {
ToolbarItem ( placement : . navigationBarTrailing ) {
SwiftUI . Button {
} label : {
2022-12-23 15:21:16 +01:00
Image ( systemSymbol : . personCropCircle )
2022-11-23 22:34:02 +01:00
. imageScale ( . large )
}
}
}
}
2022-12-12 19:12:38 +01:00
// v a r a p p l e I D S e c t i o n : s o m e V i e w {
//
// }
func connectAppleID ( ) {
AppManager . shared . authenticate ( presentingViewController : nil ) { ( result ) in
DispatchQueue . main . async {
switch result
{
case . failure ( OperationError . cancelled ) :
// I g n o r e
break
case . failure ( let error ) :
NotificationManager . shared . reportError ( error : error )
case . success : break
}
}
}
}
func disconnectAppleID ( ) {
DatabaseManager . shared . signOut { ( error ) in
DispatchQueue . main . async {
if let error = error
{
NotificationManager . shared . reportError ( error : error )
}
}
}
}
2022-11-23 22:34:02 +01:00
func switchToUIKit ( ) {
let storyboard = UIStoryboard ( name : " Main " , bundle : . main )
let rootVC = storyboard . instantiateViewController ( withIdentifier : " tabBarController " ) as ! TabBarController
UIApplication . shared . keyWindow ? . rootViewController = rootVC
}
2022-11-27 00:26:15 +01:00
func resetImageCache ( ) {
do {
let url = try FileManager . default . url (
for : . cachesDirectory ,
in : . userDomainMask ,
appropriateFor : nil ,
create : true )
try FileManager . default . removeItem ( at : url . appendingPathComponent ( " com.zeu.cache " , isDirectory : true ) )
} catch let error {
fatalError ( " \( error ) " )
}
}
2022-11-23 22:34:02 +01:00
}
struct SettingsView_Previews : PreviewProvider {
static var previews : some View {
SettingsView ( )
}
}
2022-11-27 00:26:15 +01:00