[ADD] News, Browse and Settings views ported to SwiftUI

This commit contains WIP SwiftUI versions of most of the views in SideStore.
This commit is contained in:
Fabian Thies
2022-11-23 22:34:02 +01:00
parent ed2270ff46
commit 16a8bce102
30 changed files with 2047 additions and 2 deletions

View File

@@ -0,0 +1,210 @@
//
// AppDetailView.swift
// SideStore
//
// Created by Fabian Thies on 18.11.22.
// Copyright © 2022 Fabian Thies. All rights reserved.
//
import SwiftUI
import GridStack
import AltStoreCore
struct AppDetailView: View {
let storeApp: StoreApp
var dateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .medium
dateFormatter.timeStyle = .none
return dateFormatter
}()
var byteCountFormatter: ByteCountFormatter = {
let formatter = ByteCountFormatter()
return formatter
}()
@State var scrollOffset: CGFloat = .zero
let maxContentCornerRadius: CGFloat = 24
let headerViewHeight: CGFloat = 140
let permissionColumns = 4
var isHeaderViewVisible: Bool {
scrollOffset < headerViewHeight + 12
}
var contentCornerRadius: CGFloat {
max(CGFloat.zero, min(maxContentCornerRadius, maxContentCornerRadius * (1 - self.scrollOffset / self.headerViewHeight)))
}
var body: some View {
ObservableScrollView(scrollOffset: self.$scrollOffset) { proxy in
LazyVStack {
headerView
.frame(height: headerViewHeight)
contentView
}
}
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItemGroup(placement: .navigationBarTrailing) {
AppPillButton(app: storeApp)
.disabled(isHeaderViewVisible)
.offset(y: isHeaderViewVisible ? 12 : 0)
.opacity(isHeaderViewVisible ? 0 : 1)
.animation(.easeInOut(duration: 0.2), value: isHeaderViewVisible)
}
ToolbarItemGroup(placement: .principal) {
HStack {
Spacer()
AppIconView(iconUrl: storeApp.iconURL, size: 24)
Text(storeApp.name)
.bold()
Spacer()
}
.offset(y: isHeaderViewVisible ? 12 : 0)
.opacity(isHeaderViewVisible ? 0 : 1)
.animation(.easeInOut(duration: 0.2), value: isHeaderViewVisible)
}
}
}
var headerView: some View {
ZStack(alignment: .center) {
GeometryReader { proxy in
AppIconView(iconUrl: storeApp.iconURL, size: proxy.frame(in: .global).width)
.blur(radius: 20)
}
AppRowView(app: storeApp)
.padding(.horizontal)
}
}
var contentView: some View {
VStack(alignment: .leading) {
if let subtitle = storeApp.subtitle {
Text(subtitle)
.multilineTextAlignment(.center)
.frame(maxWidth: .infinity)
.padding()
}
if !storeApp.screenshotURLs.isEmpty {
screenshotsView
}
Text(storeApp.localizedDescription)
.lineLimit(6)
.padding()
currentVersionView
permissionsView
// TODO: Add review view
// Only let users rate the app if it is currently installed!
}
.background(
RoundedRectangle(cornerRadius: contentCornerRadius)
.foregroundColor(Color(UIColor.systemBackground))
.shadow(radius: isHeaderViewVisible ? 12 : 0)
)
}
var screenshotsView: some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(storeApp.screenshotURLs) { url in
if #available(iOS 15.0, *) {
AsyncImage(url: url) { image in
image.resizable()
} placeholder: {
Rectangle()
.foregroundColor(.secondary)
}
.aspectRatio(9/16, contentMode: .fit)
.cornerRadius(8)
}
}
}
.padding(.horizontal)
}
.frame(height: 400)
.shadow(radius: 12)
}
var currentVersionView: some View {
VStack(alignment: .leading, spacing: 8) {
HStack(alignment: .bottom) {
VStack(alignment: .leading) {
Text("What's New")
.bold()
.font(.title3)
Text("Version \(storeApp.version)")
.font(.callout)
.foregroundColor(.secondary)
}
Spacer()
VStack(alignment: .trailing) {
Text(dateFormatter.string(from: storeApp.versionDate))
Text(byteCountFormatter.string(fromByteCount: Int64(storeApp.size)))
}
.font(.callout)
.foregroundColor(.secondary)
}
if let versionDescription = storeApp.versionDescription {
Text(versionDescription)
.lineLimit(5)
} else {
Text("No version information")
.foregroundColor(.secondary)
}
}
.padding()
}
var permissionsView: some View {
VStack(alignment: .leading, spacing: 8) {
Text("Permissions")
.bold()
.font(.title3)
if storeApp.permissions.isEmpty {
Text("The app requires no permissions.")
.font(.callout)
.foregroundColor(.secondary)
} else {
GridStack(minCellWidth: 40, spacing: 8, numItems: storeApp.permissions.count, alignment: .leading) { index, cellWidth in
let permission = storeApp.permissions[index]
VStack {
Image(systemName: "photo.on.rectangle")
.padding()
.background(Circle().foregroundColor(Color(UIColor.secondarySystemBackground)))
Text(permission.type.localizedShortName ?? "")
}
.frame(width: cellWidth, height: cellWidth * 1.2)
.background(Color.red)
}
}
Spacer()
}
.padding()
}
}
//struct AppDetailView_Previews: PreviewProvider {
// static var previews: some View {
// AppDetailView()
// }
//}

View File

@@ -0,0 +1,54 @@
//
// AddSourceView.swift
// SideStore
//
// Created by Fabian Thies on 20.11.22.
// Copyright © 2022 Fabian Thies. All rights reserved.
//
import SwiftUI
struct AddSourceView: View {
@State var sourceUrlText: String = ""
var continueHandler: (_ urlText: String) -> ()
var body: some View {
List {
Section {
TextField("https://connect.altstore.ml", text: $sourceUrlText)
.keyboardType(.URL)
.autocapitalization(.none)
.autocorrectionDisabled()
} header: {
Text("Source URL")
} footer: {
VStack(alignment: .leading, spacing: 4) {
Text("Please enter the source url here. Then, tap continue to validate and add the source in the next step.")
HStack(alignment: .top) {
Image(systemName: "exclamationmark.triangle.fill")
Text("Be careful with unvalidated third-party sources! Make sure to only add sources that you trust.")
}
}
}
SwiftUI.Button {
self.continueHandler(self.sourceUrlText)
} label: {
Text("Continue")
}
.disabled(URL(string: self.sourceUrlText)?.host == nil)
}
.listStyle(InsetGroupedListStyle())
.navigationTitle("Add Source")
}
}
struct AddSourceView_Previews: PreviewProvider {
static var previews: some View {
AddSourceView(continueHandler: { _ in })
}
}

View File

@@ -0,0 +1,48 @@
//
// BrowseAppPreviewView.swift
// SideStore
//
// Created by Fabian Thies on 20.11.22.
// Copyright © 2022 Fabian Thies. All rights reserved.
//
import SwiftUI
import AltStoreCore
struct BrowseAppPreviewView: View {
let storeApp: StoreApp
var body: some View {
VStack {
AppRowView(app: storeApp)
if let subtitle = storeApp.subtitle {
Text(subtitle)
}
if !storeApp.screenshotURLs.isEmpty {
HStack {
ForEach(storeApp.screenshotURLs.prefix(2)) { url in
if #available(iOS 15.0, *) {
AsyncImage(url: url) { image in
image
.resizable()
.aspectRatio(contentMode: .fit)
} placeholder: {
Color(UIColor.secondarySystemBackground)
}
.cornerRadius(8)
}
}
}
.frame(height: 300)
}
}
}
}
//struct BrowseAppPreviewView_Previews: PreviewProvider {
// static var previews: some View {
// BrowseAppPreviewView()
// }
//}

View File

@@ -0,0 +1,99 @@
//
// BrowseView.swift
// SideStoreUI
//
// Created by Fabian Thies on 18.11.22.
// Copyright © 2022 Fabian Thies. All rights reserved.
//
import SwiftUI
import AltStoreCore
struct BrowseView: View {
@SwiftUI.FetchRequest(sortDescriptors: [
NSSortDescriptor(keyPath: \StoreApp.sourceIdentifier, ascending: true),
NSSortDescriptor(keyPath: \StoreApp.sortIndex, ascending: true),
NSSortDescriptor(keyPath: \StoreApp.name, ascending: true),
NSSortDescriptor(keyPath: \StoreApp.bundleIdentifier, ascending: true)
]/*, predicate: NSPredicate(format: "%K != %@", #keyPath(StoreApp.bundleIdentifier), StoreApp.altstoreAppID)*/)
var apps: FetchedResults<StoreApp>
var filteredApps: [StoreApp] {
apps.filter { $0.matches(self.searchText) }
}
@State
var selectedStoreApp: StoreApp?
@State var searchText = ""
@State var isShowingSourcesView = false
var body: some View {
ScrollView {
LazyVStack(spacing: 24) {
ForEach(filteredApps, id: \.bundleIdentifier) { app in
NavigationLink {
AppDetailView(storeApp: app)
} label: {
BrowseAppPreviewView(storeApp: app)
}
.buttonStyle(PlainButtonStyle())
}
}
.padding()
.searchable(text: self.$searchText, placeholder: "Search")
}
.background(Color(UIColor.systemGroupedBackground).ignoresSafeArea())
.navigationTitle("Browse")
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
SwiftUI.Button {
self.isShowingSourcesView = true
} label: {
Text("Sources")
}
.sheet(isPresented: self.$isShowingSourcesView) {
NavigationView {
SourcesView()
}
}
}
}
}
}
struct BrowseView_Previews: PreviewProvider {
static var previews: some View {
BrowseView()
}
}
extension StoreApp {
func matches(_ searchText: String) -> Bool {
searchText.isEmpty ||
self.name.lowercased().contains(searchText.lowercased()) ||
self.developerName.lowercased().contains(searchText.lowercased())
}
}
extension View {
@ViewBuilder func `if`<Content: View>(_ condition: Bool, transform: (Self) -> Content) -> some View {
if condition {
transform(self)
} else {
self
}
}
@ViewBuilder func searchable(text: Binding<String>, placeholder: String) -> some View {
if #available(iOS 15.0, *) {
self.searchable(text: text, prompt: Text(placeholder))
} else {
self
}
}
}

View File

@@ -0,0 +1,114 @@
//
// ConfirmAddSourceView.swift
// SideStore
//
// Created by Fabian Thies on 18.11.22.
// Copyright © 2022 Fabian Thies. All rights reserved.
//
import SwiftUI
import AltStoreCore
struct ConfirmAddSourceView: View {
let fetchedSource: FetchedSource
var source: Source {
fetchedSource.source
}
var confirmationHandler: (_ source: FetchedSource) -> ()
var cancellationHandler: () -> ()
var body: some View {
VStack(alignment: .leading) {
List {
Section {
VStack(alignment: .leading) {
Text("\(source.apps.count) Apps")
Text(source.apps.map { $0.name }.joined(separator: ", "))
.font(.callout)
.lineLimit(1)
.foregroundColor(.secondary)
}
VStack() {
Text("\(source.newsItems.count) News Items")
}
} header: {
Text("Source Contents")
}
Section {
VStack(alignment: .leading) {
Text("Source Identifier")
Text(source.identifier)
.font(.callout)
.foregroundColor(.secondary)
}
VStack(alignment: .leading) {
Text("Source URL")
Text(source.sourceURL.absoluteString)
.font(.callout)
.foregroundColor(.secondary)
}
} header: {
Text("Source Info")
}
}
.listStyle(InsetGroupedListStyle())
Spacer()
SwiftUI.Button {
confirmationHandler(fetchedSource)
} label: {
Label(title: { Text("Add Source") }, icon: { Image(systemName: "plus") })
.multilineTextAlignment(.center)
.foregroundColor(.white)
.padding()
.frame(
maxWidth: .infinity,
alignment: .bottomLeading
)
.background(
RoundedRectangle(cornerRadius: 10)
.foregroundColor(Color.accentColor)
)
}
.padding()
}
.background(Color(UIColor.systemGroupedBackground).ignoresSafeArea())
.toolbar {
ToolbarItemGroup(placement: .navigationBarTrailing) {
SwiftUI.Button {
} label: {
Image(systemName: "xmark.circle.fill")
.foregroundColor(.secondary)
}
}
ToolbarItemGroup(placement: .navigation) {
VStack(alignment: .leading) {
Text(source.name)
.font(.title3)
.bold()
Text(source.identifier)
.font(.callout)
.foregroundColor(.secondary)
}
}
}
.navigationBarTitleDisplayMode(.inline)
}
}
struct ConfirmAddSourceView_Previews: PreviewProvider {
static var previews: some View {
AddSourceView(continueHandler: { _ in })
}
}

View File

@@ -0,0 +1,188 @@
//
// SourcesView.swift
// SideStore
//
// Created by Fabian Thies on 20.11.22.
// Copyright © 2022 Fabian Thies. All rights reserved.
//
import SwiftUI
import AltStoreCore
import CoreData
struct SourcesView: View {
@Environment(\.managedObjectContext)
var managedObjectContext
@SwiftUI.FetchRequest(sortDescriptors: [
NSSortDescriptor(keyPath: \Source.name, ascending: true),
NSSortDescriptor(keyPath: \Source.sourceURL, ascending: true),
NSSortDescriptor(keyPath: \Source.identifier, ascending: true)
])
var installedSources: FetchedResults<Source>
@State var isShowingAddSourceAlert = false
@State var sourceToConfirm: FetchedSource?
var body: some View {
ScrollView {
LazyVStack(alignment: .leading, spacing: 24) {
// Installed Sources
LazyVStack(alignment: .leading, spacing: 12) {
Text("Sources control what apps are available to download through SideStore.")
.font(.callout)
.foregroundColor(.secondary)
ForEach(installedSources, id: \.identifier) { source in
VStack(alignment: .leading) {
Text(source.name)
.bold()
Text(source.sourceURL.absoluteString)
.font(.callout)
.foregroundColor(.secondary)
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
.background(Color.accentColor.opacity(0.5))
.clipShape(RoundedRectangle(cornerRadius: 30, style: .circular))
.if(source.identifier != Source.altStoreIdentifier) { view in
view.contextMenu(ContextMenu(menuItems: {
SwiftUI.Button {
self.removeSource(source)
} label: {
Label("Remove", systemImage: "trash")
}
}))
}
}
}
// Trusted Sources
LazyVStack(alignment: .leading) {
Text("Trusted Sources")
.font(.title3)
.bold()
Text("SideStore has reviewed these sources to make sure they meet our safety standards.")
.font(.callout)
.foregroundColor(.secondary)
}
}
.padding()
}
.navigationTitle("Sources")
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
SwiftUI.Button {
self.isShowingAddSourceAlert = true
} label: {
Image(systemName: "plus")
}
.sheet(isPresented: self.$isShowingAddSourceAlert) {
NavigationView {
AddSourceView(continueHandler: fetchSource(with:))
}
}
.sheet(item: self.$sourceToConfirm) { source in
if #available(iOS 16.0, *) {
NavigationView {
ConfirmAddSourceView(fetchedSource: source, confirmationHandler: addSource(_:)) {
self.sourceToConfirm = nil
}
}
.presentationDetents([.medium])
}
}
}
ToolbarItem(placement: .navigationBarTrailing) {
SwiftUI.Button {
self.isShowingAddSourceAlert = false
} label: {
Text("Done").bold()
}
}
}
}
func fetchSource(with urlText: String) {
self.isShowingAddSourceAlert = false
guard let url = URL(string: urlText) else {
return
}
AppManager.shared.fetchSource(sourceURL: url) { result in
switch result {
case let .success(source):
self.sourceToConfirm = FetchedSource(source: source)
case let .failure(error):
print(error)
}
}
}
func addSource(_ source: FetchedSource) {
source.context?.perform {
do {
try source.context?.save()
} catch {
print(error)
}
}
self.sourceToConfirm = nil
}
func removeSource(_ source: Source) {
DatabaseManager.shared.persistentContainer.performBackgroundTask { (context) in
let source = context.object(with: source.objectID) as! Source
context.delete(source)
do {
try context.save()
} catch {
print(error)
}
}
}
}
struct SourcesListView_Previews: PreviewProvider {
static var previews: some View {
SourcesView()
}
}
extension Source: Identifiable {
public var id: String {
self.identifier
}
}
struct FetchedSource: Identifiable {
let source: Source
let context: NSManagedObjectContext?
var id: String {
source.identifier
}
init?(source: Source) {
guard let context = source.managedObjectContext else{
return nil
}
self.source = source
self.context = context
}
}

View File

@@ -0,0 +1,27 @@
//
// MyAppsView.swift
// SideStoreUI
//
// Created by Fabian Thies on 18.11.22.
// Copyright © 2022 Fabian Thies. All rights reserved.
//
import SwiftUI
struct MyAppsView: View {
var body: some View {
ScrollView {
LazyVStack {
}
}
.background(Color(UIColor.systemGroupedBackground).ignoresSafeArea())
.navigationTitle("My Apps")
}
}
struct MyAppsView_Previews: PreviewProvider {
static var previews: some View {
MyAppsView()
}
}

View File

@@ -0,0 +1,101 @@
//
// NewsItemView.swift
// SideStoreUI
//
// Created by Fabian Thies on 18.11.22.
// Copyright © 2022 Fabian Thies. All rights reserved.
//
import SwiftUI
import AltStoreCore
struct NewsItemView: View {
typealias TapHandler<T> = (T) -> Void
let newsItem: NewsItem
private var newsSelectionHandler: TapHandler<NewsItem>? = nil
private var appSelectionHandler: TapHandler<StoreApp>? = nil
init(newsItem: NewsItem) {
self.newsItem = newsItem
}
var body: some View {
VStack(spacing: 12) {
newsContent
.onTapGesture {
newsSelectionHandler?(newsItem)
}
if let connectedApp = newsItem.storeApp {
NavigationLink {
AppDetailView(storeApp: connectedApp)
} label: {
AppRowView(app: connectedApp)
}
.buttonStyle(PlainButtonStyle())
}
}
}
var newsContent: some View {
VStack(alignment: .leading, spacing: 12) {
VStack(alignment: .leading, spacing: 12) {
Text(newsItem.title)
.font(.title2)
.bold()
.foregroundColor(.white)
Text(newsItem.caption)
.foregroundColor(.white.opacity(0.7))
}
.padding(24)
if let imageUrl = newsItem.imageURL, #available(iOS 15.0, *) {
AsyncImage(
url: imageUrl,
content: { image in
if let image = image.image {
image
.resizable()
.aspectRatio(contentMode: .fit)
}
}
)
}
}
.frame(
maxWidth: .infinity,
alignment: .topLeading
)
.background(Color(newsItem.tintColor))
.clipShape(RoundedRectangle(cornerRadius: 30, style: .circular))
}
func onNewsSelection(_ handler: @escaping TapHandler<NewsItem>) -> Self {
var newSelf = self
newSelf.newsSelectionHandler = handler
return newSelf
}
func onAppSelection(_ handler: @escaping TapHandler<StoreApp>) -> Self {
var newSelf = self
newSelf.appSelectionHandler = handler
return newSelf
}
}
extension URL: Identifiable {
public var id: String {
return self.absoluteString
}
}
//struct NewsItemView_Previews: PreviewProvider {
// static var previews: some View {
// NewsItemView()
// }
//}

View File

@@ -0,0 +1,55 @@
//
// NewsView.swift
// SideStoreUI
//
// Created by Fabian Thies on 18.11.22.
// Copyright © 2022 Fabian Thies. All rights reserved.
//
import SwiftUI
import AltStoreCore
struct NewsView: View {
@SwiftUI.FetchRequest(sortDescriptors: [
NSSortDescriptor(keyPath: \NewsItem.date, ascending: false),
NSSortDescriptor(keyPath: \NewsItem.sortIndex, ascending: true),
NSSortDescriptor(keyPath: \NewsItem.sourceIdentifier, ascending: true)
])
var news: FetchedResults<NewsItem>
@State
var activeExternalUrl: URL?
@State
var selectedStoreApp: StoreApp?
var body: some View {
ScrollView {
LazyVStack(spacing: 24) {
ForEach(news, id: \.objectID) { newsItem in
NewsItemView(newsItem: newsItem)
.onNewsSelection { newsItem in
self.activeExternalUrl = newsItem.externalURL
}
.frame(
maxWidth: .infinity,
alignment: .topLeading
)
}
}
.padding()
}
.background(Color(UIColor.systemGroupedBackground).ignoresSafeArea())
.navigationTitle("News")
.sheet(item: self.$activeExternalUrl) { url in
SafariView(url: url)
}
}
}
struct NewsView_Previews: PreviewProvider {
static var previews: some View {
NewsView()
}
}

View File

@@ -0,0 +1,22 @@
//
// NewsViewModel.swift
// SideStoreUI
//
// Created by Fabian Thies on 18.11.22.
// Copyright © 2022 Fabian Thies. All rights reserved.
//
import SwiftUI
import AltStoreCore
class NewsViewModel: ViewModel {
@SwiftUI.FetchRequest(sortDescriptors: [
NSSortDescriptor(keyPath: \NewsItem.date, ascending: false),
NSSortDescriptor(keyPath: \NewsItem.sortIndex, ascending: true),
NSSortDescriptor(keyPath: \NewsItem.sourceIdentifier, ascending: true)
])
var news: FetchedResults<NewsItem>
init() {}
}

View File

@@ -0,0 +1,109 @@
//
// RootView.swift
// SideStoreUI
//
// Created by Fabian Thies on 18.11.22.
// Copyright © 2022 Fabian Thies. All rights reserved.
//
import SwiftUI
struct RootView: View {
@State var selectedTab: Tab = .defaultTab
var body: some View {
TabView(selection: self.$selectedTab) {
ForEach(Tab.allCases) { tab in
NavigationView {
content(for: tab)
}
.tag(tab)
.tabItem {
tab.label
}
}
}
.overlay(self.notificationsOverlay)
}
@ViewBuilder
func content(for tab: Tab) -> some View {
switch tab {
case .news:
NewsView()
case .browse:
BrowseView()
case .myApps:
MyAppsView()
case .settings:
SettingsView()
}
}
@ObservedObject
var notificationManager = NotificationManager.shared
var notificationsOverlay: some View {
VStack {
Spacer()
ForEach(Array(notificationManager.notifications.values)) { notification in
VStack(alignment: .leading) {
Text(notification.title)
.bold()
if let message = notification.message {
Text(message)
.font(.callout)
}
}
.padding()
.background(Color(UIColor.altPrimary))
.clipShape(RoundedRectangle(cornerRadius: 16))
}
Spacer()
.frame(height: 50)
}
.padding()
.animation(.easeInOut)
}
}
extension RootView {
enum Tab: Int, NavigationTab {
case news, browse, myApps, settings
static var defaultTab: RootView.Tab = .news
var displaySymbol: String {
switch self {
case .news: return "newspaper"
case .browse: return "app.dashed"
case .myApps: return "app.badge"
case .settings: return "gearshape"
}
}
var displayName: String {
switch self {
case .news: return "News"
case .browse: return "Browse"
case .myApps: return "My Apps"
case .settings: return "Settings"
}
}
var label: some View {
Label(self.displayName, systemImage: self.displaySymbol)
}
}
}
struct RootView_Previews: PreviewProvider {
static var previews: some View {
RootView()
}
}

View File

@@ -0,0 +1,146 @@
//
// SettingsView.swift
// SideStoreUI
//
// Created by Fabian Thies on 18.11.22.
// Copyright © 2022 Fabian Thies. All rights reserved.
//
import SwiftUI
import AltStoreCore
import Intents
struct SettingsView: View {
@AppStorage("isBackgroundRefreshEnabled")
var isBackgroundRefreshEnabled: Bool = true
@State var isShowingAddShortcutView = false
var body: some View {
List {
Section {
if let team = DatabaseManager.shared.activeTeam() {
HStack {
Text("Name")
.foregroundColor(.secondary)
Spacer()
Text(team.name)
}
HStack {
Text("E-Mail")
.foregroundColor(.secondary)
Spacer()
Text(team.account.appleID)
}
HStack {
Text("Type")
.foregroundColor(.secondary)
Spacer()
Text(team.type.localizedDescription)
}
}
} header: {
HStack {
Text("Connected Apple ID")
Spacer()
SwiftUI.Button {
} label: {
Text("Sign Out")
.font(.callout)
.bold()
}
}
}
Section {
Toggle(isOn: self.$isBackgroundRefreshEnabled, label: {
Text("Background Refresh")
})
if #available(iOS 14.0, *) {
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)
}
}
}
} 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")
}
} 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: {
Text("SideStore 1.0.0")
.multilineTextAlignment(.center)
.frame(maxWidth: .infinity)
}
}
.listStyle(InsetGroupedListStyle())
.navigationTitle("Settings")
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
SwiftUI.Button {
} label: {
Image(systemName: "person.crop.circle")
.imageScale(.large)
}
}
}
}
func switchToUIKit() {
let storyboard = UIStoryboard(name: "Main", bundle: .main)
let rootVC = storyboard.instantiateViewController(withIdentifier: "tabBarController") as! TabBarController
UIApplication.shared.keyWindow?.rootViewController = rootVC
}
}
struct SettingsView_Previews: PreviewProvider {
static var previews: some View {
SettingsView()
}
}