mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-13 08:43:27 +01:00
[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:
committed by
Joe Mattiello
parent
79d677cf3c
commit
d3e8473f45
18
AltStore/App/SideStoreUIApp.swift
Normal file
18
AltStore/App/SideStoreUIApp.swift
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// SideStoreUIApp.swift
|
||||
// SideStoreUI
|
||||
//
|
||||
// Created by Fabian Thies on 18.11.22.
|
||||
// Copyright © 2022 Fabian Thies. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
@main
|
||||
struct SideStoreUIApp: App {
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
RootView()
|
||||
}
|
||||
}
|
||||
}
|
||||
48
AltStore/Helper/DateFormatterHelper.swift
Normal file
48
AltStore/Helper/DateFormatterHelper.swift
Normal file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// DateFormatterHelper.swift
|
||||
// SideStore
|
||||
//
|
||||
// Created by Fabian Thies on 20.11.22.
|
||||
// Copyright © 2022 Fabian Thies. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct DateFormatterHelper {
|
||||
|
||||
private static let appExpirationDateFormatter: DateComponentsFormatter = {
|
||||
let dateComponentsFormatter = DateComponentsFormatter()
|
||||
dateComponentsFormatter.zeroFormattingBehavior = [.pad]
|
||||
dateComponentsFormatter.collapsesLargestUnit = false
|
||||
return dateComponentsFormatter
|
||||
}()
|
||||
|
||||
|
||||
static func string(forExpirationDate date: Date) -> String {
|
||||
let startDate = Date()
|
||||
let interval = date.timeIntervalSince(startDate)
|
||||
guard interval > 0 else {
|
||||
return ""
|
||||
}
|
||||
|
||||
if interval < (1 * 60 * 60) {
|
||||
self.appExpirationDateFormatter.unitsStyle = .positional
|
||||
self.appExpirationDateFormatter.allowedUnits = [.minute, .second]
|
||||
}
|
||||
else if interval < (2 * 24 * 60 * 60)
|
||||
{
|
||||
self.appExpirationDateFormatter.unitsStyle = .positional
|
||||
self.appExpirationDateFormatter.allowedUnits = [.hour, .minute, .second]
|
||||
}
|
||||
else
|
||||
{
|
||||
self.appExpirationDateFormatter.unitsStyle = .full
|
||||
self.appExpirationDateFormatter.allowedUnits = [.day]
|
||||
|
||||
// let numberOfDays = endDate.numberOfCalendarDays(since: startDate)
|
||||
// text = String(format: NSLocalizedString("%@ DAYS", comment: ""), NSNumber(value: numberOfDays))
|
||||
}
|
||||
|
||||
return self.appExpirationDateFormatter.string(from: startDate, to: date) ?? ""
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import SwiftUI
|
||||
import Roxas
|
||||
import EmotionalDamage
|
||||
import minimuxer
|
||||
@@ -40,7 +41,10 @@ final class LaunchViewController: RSTLaunchViewController, UIDocumentPickerDeleg
|
||||
{
|
||||
defer {
|
||||
// Create destinationViewController now so view controllers can register for receiving Notifications.
|
||||
self.destinationViewController = self.storyboard!.instantiateViewController(withIdentifier: "tabBarController") as! TabBarController
|
||||
// self.destinationViewController = self.storyboard!.instantiateViewController(withIdentifier: "tabBarController") as! TabBarController
|
||||
let rootView = RootView()
|
||||
.environment(\.managedObjectContext, DatabaseManager.shared.viewContext)
|
||||
self.destinationViewController = UIHostingController(rootView: rootView)
|
||||
}
|
||||
super.viewDidLoad()
|
||||
}
|
||||
|
||||
75
AltStore/Manager/NotificationManager.swift
Normal file
75
AltStore/Manager/NotificationManager.swift
Normal file
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// NotificationManager.swift
|
||||
// SideStore
|
||||
//
|
||||
// Created by Fabian Thies on 21.11.22.
|
||||
// Copyright © 2022 Fabian Thies. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import AltStoreCore
|
||||
|
||||
class NotificationManager: ObservableObject {
|
||||
|
||||
struct Notification: Identifiable {
|
||||
let id: UUID
|
||||
let title: String
|
||||
let message: String?
|
||||
}
|
||||
|
||||
static let shared = NotificationManager()
|
||||
|
||||
@Published
|
||||
var notifications: [UUID: Notification] = [:]
|
||||
|
||||
private init() {}
|
||||
|
||||
func reportError(error: Error) {
|
||||
if case OperationError.cancelled = error {
|
||||
// Ignore
|
||||
return
|
||||
}
|
||||
|
||||
var error = error as NSError
|
||||
var underlyingError = error.underlyingError
|
||||
|
||||
if
|
||||
let unwrappedUnderlyingError = underlyingError,
|
||||
error.domain == AltServerErrorDomain && error.code == ALTServerError.Code.underlyingError.rawValue
|
||||
{
|
||||
// Treat underlyingError as the primary error.
|
||||
|
||||
error = unwrappedUnderlyingError as NSError
|
||||
underlyingError = nil
|
||||
}
|
||||
|
||||
let text: String
|
||||
let detailText: String?
|
||||
|
||||
if let failure = error.localizedFailure
|
||||
{
|
||||
text = failure
|
||||
detailText = error.localizedFailureReason ?? error.localizedRecoverySuggestion ?? underlyingError?.localizedDescription ?? error.localizedDescription
|
||||
}
|
||||
else if let reason = error.localizedFailureReason
|
||||
{
|
||||
text = reason
|
||||
detailText = error.localizedRecoverySuggestion ?? underlyingError?.localizedDescription
|
||||
}
|
||||
else
|
||||
{
|
||||
text = error.localizedDescription
|
||||
detailText = underlyingError?.localizedDescription ?? error.localizedRecoverySuggestion
|
||||
}
|
||||
|
||||
|
||||
let notificationId = UUID()
|
||||
|
||||
self.notifications[notificationId] = Notification(id: notificationId, title: text, message: detailText)
|
||||
|
||||
let dismissWorkItem = DispatchWorkItem {
|
||||
self.notifications.removeValue(forKey: notificationId)
|
||||
}
|
||||
DispatchQueue.main.asyncAfter(deadline: .now().advanced(by: .seconds(5)), execute: dismissWorkItem)
|
||||
}
|
||||
}
|
||||
21
AltStore/Protocols/NavigationTab.swift
Normal file
21
AltStore/Protocols/NavigationTab.swift
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// NavigationTab.swift
|
||||
// SideStoreUI
|
||||
//
|
||||
// Created by Fabian Thies on 18.11.22.
|
||||
// Copyright © 2022 Fabian Thies. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol NavigationTab: RawRepresentable, Identifiable, CaseIterable, Hashable where RawValue == Int {
|
||||
static var defaultTab: Self { get }
|
||||
var displaySymbol: String { get }
|
||||
var displayName: String { get }
|
||||
}
|
||||
|
||||
extension NavigationTab {
|
||||
var id: Int {
|
||||
self.rawValue
|
||||
}
|
||||
}
|
||||
11
AltStore/Protocols/ViewModel.swift
Normal file
11
AltStore/Protocols/ViewModel.swift
Normal file
@@ -0,0 +1,11 @@
|
||||
//
|
||||
// ViewModel.swift
|
||||
// SideStoreUI
|
||||
//
|
||||
// Created by Fabian Thies on 18.11.22.
|
||||
// Copyright © 2022 Fabian Thies. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
protocol ViewModel: ObservableObject {}
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"colors" : [
|
||||
{
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"alpha" : "1.000",
|
||||
"blue" : "1.000",
|
||||
"green" : "0.263",
|
||||
"red" : "0.502"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"alpha" : "1.000",
|
||||
"blue" : "0.404",
|
||||
"green" : "0.000",
|
||||
"red" : "0.235"
|
||||
}
|
||||
},
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
35
AltStore/View Components/AppIconView.swift
Normal file
35
AltStore/View Components/AppIconView.swift
Normal file
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// SwiftUIView.swift
|
||||
// SideStore
|
||||
//
|
||||
// Created by Fabian Thies on 18.11.22.
|
||||
// Copyright © 2022 Fabian Thies. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct AppIconView: View {
|
||||
let iconUrl: URL?
|
||||
var size: CGFloat = 64
|
||||
var cornerRadius: CGFloat {
|
||||
size * 0.234
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
if let iconUrl, #available(iOS 15.0, *) {
|
||||
AsyncImage(url: iconUrl) { image in
|
||||
image
|
||||
.resizable()
|
||||
} placeholder: {
|
||||
Color(UIColor.secondarySystemBackground)
|
||||
}
|
||||
.frame(width: size, height: size)
|
||||
.clipShape(RoundedRectangle(cornerRadius: cornerRadius, style: .continuous))
|
||||
} else {
|
||||
RoundedRectangle(cornerRadius: cornerRadius, style: .continuous)
|
||||
.background(Color.secondary)
|
||||
.frame(width: size, height: size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
99
AltStore/View Components/AppPillButton.swift
Normal file
99
AltStore/View Components/AppPillButton.swift
Normal file
@@ -0,0 +1,99 @@
|
||||
//
|
||||
// AppPillButton.swift
|
||||
// SideStore
|
||||
//
|
||||
// Created by Fabian Thies on 20.11.22.
|
||||
// Copyright © 2022 Fabian Thies. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import AltStoreCore
|
||||
|
||||
struct AppPillButton: View {
|
||||
|
||||
@ObservedObject
|
||||
var appManager = AppManager.shared.publisher
|
||||
|
||||
let app: AppProtocol
|
||||
var showRemainingDays = false
|
||||
|
||||
var storeApp: StoreApp? {
|
||||
(app as? StoreApp) ?? (app as? InstalledApp)?.storeApp
|
||||
}
|
||||
|
||||
var installedApp: InstalledApp? {
|
||||
(app as? InstalledApp) ?? (app as? StoreApp)?.installedApp
|
||||
}
|
||||
|
||||
var progress: Progress? {
|
||||
appManager.refreshProgress[app.bundleIdentifier] ?? appManager.installationProgress[app.bundleIdentifier]
|
||||
}
|
||||
// let progress = {
|
||||
// let progress = Progress(totalUnitCount: 100)
|
||||
// progress.completedUnitCount = 20
|
||||
// return progress
|
||||
// }()
|
||||
|
||||
var buttonText: String {
|
||||
// guard progress == nil else {
|
||||
// return ""
|
||||
// }
|
||||
|
||||
if let installedApp {
|
||||
if self.showRemainingDays {
|
||||
return DateFormatterHelper.string(forExpirationDate: installedApp.expirationDate)
|
||||
}
|
||||
|
||||
return "Open"
|
||||
}
|
||||
|
||||
return "Free"
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
SwiftUI.Button(action: handleButton, label: {
|
||||
Text(buttonText.uppercased())
|
||||
.bold()
|
||||
})
|
||||
.buttonStyle(PillButtonStyle(tintColor: storeApp?.tintColor ?? .black, progress: progress))
|
||||
}
|
||||
|
||||
func handleButton() {
|
||||
if let installedApp {
|
||||
self.openApp(installedApp)
|
||||
} else if let storeApp {
|
||||
self.installApp(storeApp)
|
||||
}
|
||||
}
|
||||
|
||||
func openApp(_ installedApp: InstalledApp) {
|
||||
UIApplication.shared.open(installedApp.openAppURL)
|
||||
}
|
||||
|
||||
func installApp(_ storeApp: StoreApp) {
|
||||
let previousProgress = AppManager.shared.installationProgress(for: storeApp)
|
||||
guard previousProgress == nil else {
|
||||
previousProgress?.cancel()
|
||||
return
|
||||
}
|
||||
|
||||
let _ = AppManager.shared.install(storeApp, presentingViewController: UIApplication.shared.keyWindow?.rootViewController) { result in
|
||||
|
||||
switch result {
|
||||
case let .success(installedApp):
|
||||
print("Installed app: \(installedApp.bundleIdentifier)")
|
||||
|
||||
case let .failure(error):
|
||||
print("Failed to install app: \(error.localizedDescription)")
|
||||
NotificationManager.shared.reportError(error: error)
|
||||
AppManager.shared.installationProgress(for: storeApp)?.cancel()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//struct AppPillButton_Previews: PreviewProvider {
|
||||
// static var previews: some View {
|
||||
// AppPillButton()
|
||||
// }
|
||||
//}
|
||||
51
AltStore/View Components/AppRowView.swift
Normal file
51
AltStore/View Components/AppRowView.swift
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// AppRowView.swift
|
||||
// SideStore
|
||||
//
|
||||
// Created by Fabian Thies on 18.11.22.
|
||||
// Copyright © 2022 Fabian Thies. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import AltStoreCore
|
||||
|
||||
struct AppRowView: View {
|
||||
let app: AppProtocol
|
||||
|
||||
var storeApp: StoreApp? {
|
||||
(app as? StoreApp) ?? (app as? InstalledApp)?.storeApp
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
HStack(alignment: .center, spacing: 12) {
|
||||
AppIconView(iconUrl: storeApp?.iconURL)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(app.name)
|
||||
.bold()
|
||||
|
||||
Text(storeApp?.developerName ?? "Sideloaded")
|
||||
.font(.callout)
|
||||
.foregroundColor(.secondary)
|
||||
|
||||
RatingStars(rating: 4)
|
||||
.frame(height: 12)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
.lineLimit(1)
|
||||
|
||||
Spacer()
|
||||
|
||||
AppPillButton(app: app)
|
||||
}
|
||||
.padding()
|
||||
.background(Color(storeApp?.tintColor ?? UIColor.black).opacity(0.5))
|
||||
.clipShape(RoundedRectangle(cornerRadius: 30, style: .circular))
|
||||
}
|
||||
}
|
||||
|
||||
//struct AppRowView_Previews: PreviewProvider {
|
||||
// static var previews: some View {
|
||||
// AppRowView()
|
||||
// }
|
||||
//}
|
||||
47
AltStore/View Components/ObservableScrollView.swift
Normal file
47
AltStore/View Components/ObservableScrollView.swift
Normal file
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// ObservableScrollView.swift
|
||||
// SideStore
|
||||
//
|
||||
// Created by Fabian Thies on 20.11.22.
|
||||
// Copyright © 2022 Fabian Thies. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ObservableScrollView<Content: View>: View {
|
||||
@Namespace var scrollViewNamespace
|
||||
|
||||
@Binding var scrollOffset: CGFloat
|
||||
|
||||
let content: (ScrollViewProxy) -> Content
|
||||
|
||||
init(scrollOffset: Binding<CGFloat>, @ViewBuilder content: @escaping (ScrollViewProxy) -> Content) {
|
||||
self._scrollOffset = scrollOffset
|
||||
self.content = content
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
ScrollViewReader { proxy in
|
||||
content(proxy)
|
||||
.background(GeometryReader { geoReader in
|
||||
let offset = -geoReader.frame(in: .named(scrollViewNamespace)).minY
|
||||
Color.clear
|
||||
.preference(key: ScrollViewOffsetPreferenceKey.self, value: offset)
|
||||
})
|
||||
}
|
||||
}
|
||||
.coordinateSpace(name: scrollViewNamespace)
|
||||
.onPreferenceChange(ScrollViewOffsetPreferenceKey.self) { value in
|
||||
scrollOffset = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ScrollViewOffsetPreferenceKey: PreferenceKey {
|
||||
static var defaultValue = CGFloat.zero
|
||||
|
||||
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
|
||||
value += nextValue()
|
||||
}
|
||||
}
|
||||
30
AltStore/View Components/RatingStars.swift
Normal file
30
AltStore/View Components/RatingStars.swift
Normal file
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// RatingStars.swift
|
||||
// SideStore
|
||||
//
|
||||
// Created by Fabian Thies on 18.11.22.
|
||||
// Copyright © 2022 Fabian Thies. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct RatingStars: View {
|
||||
|
||||
let rating: Int
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 0) {
|
||||
ForEach(0..<5) { i in
|
||||
Image(systemName: i < rating ? "star.fill" : "star")
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct RatingStars_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
RatingStars(rating: 4)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// PillButtonProgressViewStyle.swift
|
||||
// SideStore
|
||||
//
|
||||
// Created by Fabian Thies on 22.11.22.
|
||||
// Copyright © 2022 Fabian Thies. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct PillButtonProgressViewStyle: ProgressViewStyle {
|
||||
let tint: Color
|
||||
|
||||
func makeBody(configuration: Configuration) -> some View {
|
||||
ZStack(alignment: .leading) {
|
||||
Capsule(style: .continuous)
|
||||
.foregroundColor(tint.opacity(0.15))
|
||||
|
||||
GeometryReader { proxy in
|
||||
Capsule(style: .continuous)
|
||||
// .frame(width: proxy.size.width * (configuration.fractionCompleted ?? 0.0))
|
||||
.foregroundColor(tint)
|
||||
.offset(x: -proxy.size.width * (1 - (configuration.fractionCompleted ?? 1)))
|
||||
}
|
||||
}
|
||||
.animation(.easeInOut(duration: 0.2))
|
||||
}
|
||||
}
|
||||
46
AltStore/View Extensions/Styles/PillButtonStyle.swift
Normal file
46
AltStore/View Extensions/Styles/PillButtonStyle.swift
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// PillButtonStyle.swift
|
||||
// SideStore
|
||||
//
|
||||
// Created by Fabian Thies on 18.11.22.
|
||||
// Copyright © 2022 Fabian Thies. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct PillButtonStyle: ButtonStyle {
|
||||
|
||||
let tintColor: UIColor
|
||||
var progress: Progress?
|
||||
|
||||
func makeBody(configuration: Configuration) -> some View {
|
||||
ZStack {
|
||||
if progress == nil {
|
||||
configuration.label
|
||||
.opacity(configuration.isPressed ? 0.4 : 1.0)
|
||||
} else {
|
||||
ProgressView()
|
||||
.progressViewStyle(DefaultProgressViewStyle())
|
||||
}
|
||||
}
|
||||
.frame(minWidth: 40)
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.vertical, 8)
|
||||
.background(background)
|
||||
.foregroundColor(self.progress == nil ? .white : Color(tintColor))
|
||||
.clipShape(Capsule())
|
||||
}
|
||||
|
||||
var background: some View {
|
||||
ZStack {
|
||||
if let progress {
|
||||
Color(tintColor).opacity(0.15)
|
||||
|
||||
ProgressView(progress)
|
||||
.progressViewStyle(PillButtonProgressViewStyle(tint: Color(tintColor)))
|
||||
} else {
|
||||
Color(tintColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// SafariView.swift
|
||||
// SideStore
|
||||
//
|
||||
// Created by Fabian Thies on 18.11.22.
|
||||
// Copyright © 2022 Fabian Thies. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import SafariServices
|
||||
|
||||
struct SafariView: UIViewControllerRepresentable {
|
||||
let url: URL
|
||||
|
||||
func makeUIViewController(context: Context) -> some UIViewController {
|
||||
SFSafariViewController(url: url)
|
||||
}
|
||||
|
||||
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) { }
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// SiriShortcutSetupView.swift
|
||||
// SideStore
|
||||
//
|
||||
// Created by Fabian Thies on 21.11.22.
|
||||
// Copyright © 2022 Fabian Thies. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
import UIKit
|
||||
import Intents
|
||||
import IntentsUI
|
||||
|
||||
struct SiriShortcutSetupView: UIViewControllerRepresentable {
|
||||
|
||||
let shortcut: INShortcut
|
||||
|
||||
func makeUIViewController(context: Context) -> some UIViewController {
|
||||
let viewController = INUIAddVoiceShortcutViewController(shortcut: shortcut)
|
||||
viewController.delegate = context.coordinator
|
||||
viewController.modalPresentationStyle = .formSheet
|
||||
return viewController
|
||||
}
|
||||
|
||||
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) { }
|
||||
|
||||
func makeCoordinator() -> Coordinator {
|
||||
Coordinator(shortcut: shortcut)
|
||||
}
|
||||
|
||||
class Coordinator: NSObject {
|
||||
|
||||
let shortcut: INShortcut
|
||||
|
||||
init(shortcut: INShortcut) {
|
||||
self.shortcut = shortcut
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension SiriShortcutSetupView.Coordinator: INUIAddVoiceShortcutViewControllerDelegate {
|
||||
func addVoiceShortcutViewController(_ controller: INUIAddVoiceShortcutViewController, didFinishWith voiceShortcut: INVoiceShortcut?, error: Error?) {
|
||||
|
||||
// TODO: Handle errors
|
||||
controller.dismiss(animated: true)
|
||||
}
|
||||
|
||||
func addVoiceShortcutViewControllerDidCancel(_ controller: INUIAddVoiceShortcutViewController) {
|
||||
controller.dismiss(animated: true)
|
||||
}
|
||||
}
|
||||
210
AltStore/Views/App Detail/AppDetailView.swift
Normal file
210
AltStore/Views/App Detail/AppDetailView.swift
Normal 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()
|
||||
// }
|
||||
//}
|
||||
54
AltStore/Views/Browse/AddSourceView.swift
Normal file
54
AltStore/Views/Browse/AddSourceView.swift
Normal 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 })
|
||||
}
|
||||
}
|
||||
48
AltStore/Views/Browse/BrowseAppPreviewView.swift
Normal file
48
AltStore/Views/Browse/BrowseAppPreviewView.swift
Normal 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()
|
||||
// }
|
||||
//}
|
||||
99
AltStore/Views/Browse/BrowseView.swift
Normal file
99
AltStore/Views/Browse/BrowseView.swift
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
114
AltStore/Views/Browse/ConfirmAddSourceView.swift
Normal file
114
AltStore/Views/Browse/ConfirmAddSourceView.swift
Normal 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 })
|
||||
}
|
||||
}
|
||||
188
AltStore/Views/Browse/SourcesView.swift
Normal file
188
AltStore/Views/Browse/SourcesView.swift
Normal 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
|
||||
}
|
||||
}
|
||||
27
AltStore/Views/My Apps/MyAppsView.swift
Normal file
27
AltStore/Views/My Apps/MyAppsView.swift
Normal 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()
|
||||
}
|
||||
}
|
||||
101
AltStore/Views/News/NewsItemView.swift
Normal file
101
AltStore/Views/News/NewsItemView.swift
Normal 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()
|
||||
// }
|
||||
//}
|
||||
55
AltStore/Views/News/NewsView.swift
Normal file
55
AltStore/Views/News/NewsView.swift
Normal 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()
|
||||
}
|
||||
}
|
||||
22
AltStore/Views/News/NewsViewModel.swift
Normal file
22
AltStore/Views/News/NewsViewModel.swift
Normal 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() {}
|
||||
}
|
||||
109
AltStore/Views/RootView.swift
Normal file
109
AltStore/Views/RootView.swift
Normal 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()
|
||||
}
|
||||
}
|
||||
146
AltStore/Views/Settings/SettingsView.swift
Normal file
146
AltStore/Views/Settings/SettingsView.swift
Normal 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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user