diff --git a/AltStore/View Components/AppIconView.swift b/AltStore/View Components/AppIconView.swift index acec82d1..cafd9af9 100644 --- a/AltStore/View Components/AppIconView.swift +++ b/AltStore/View Components/AppIconView.swift @@ -36,3 +36,26 @@ extension AppIconView: Equatable { lhs.iconUrl == rhs.iconUrl && lhs.cornerRadius == rhs.cornerRadius } } + + +import AltStoreCore + +struct AppIconView_Previews: PreviewProvider { + + static let context = DatabaseManager.shared.viewContext + static let app = StoreApp.makeAltStoreApp(in: context) + + static var previews: some View { + HStack { + AppIconView(iconUrl: app.iconURL) + + VStack(alignment: .leading) { + Text(app.name) + .bold() + Text(app.developerName) + .font(.callout) + .foregroundColor(.secondary) + } + } + } +} diff --git a/AltStore/View Components/AppPillButton.swift b/AltStore/View Components/AppPillButton.swift index 4530361c..66516c9b 100644 --- a/AltStore/View Components/AppPillButton.swift +++ b/AltStore/View Components/AppPillButton.swift @@ -100,8 +100,45 @@ struct AppPillButton: View { } } -//struct AppPillButton_Previews: PreviewProvider { -// static var previews: some View { -// AppPillButton() -// } -//} +struct AppPillButton_Previews: PreviewProvider { + + static let context = DatabaseManager.shared.viewContext + static let app = StoreApp.makeAltStoreApp(in: context) + static let installedApp = InstalledApp.fetchAltStore(in: context) + + static var previews: some View { + VStack { + self.preview(for: app) + + self.preview(for: installedApp!) + + self.preview(for: installedApp!, showRemainingDays: true) + } + .padding() + } + + @ViewBuilder + static func preview(for app: AppProtocol, showRemainingDays: Bool = false) -> some View { + HintView(backgroundColor: Color(UIColor.secondarySystemBackground)) { + HStack { + AppIconView(iconUrl: self.app.iconURL) + + VStack(alignment: .leading) { + Text(app is StoreApp ? "Store App" : "Installed App") + .bold() + Text( + app is StoreApp ? + "Can be installed" : + showRemainingDays ? "Can be refreshed" : "Can be opened" + ) + .font(.callout) + .foregroundColor(.secondary) + } + + Spacer() + + AppPillButton(app: app, showRemainingDays: showRemainingDays) + } + } + } +} diff --git a/AltStore/View Components/AppScreenshot.swift b/AltStore/View Components/AppScreenshot.swift index 459b9781..f7bc1abd 100644 --- a/AltStore/View Components/AppScreenshot.swift +++ b/AltStore/View Components/AppScreenshot.swift @@ -41,9 +41,15 @@ extension AppScreenshot { } +import AltStoreCore + struct AppScreenshot_Previews: PreviewProvider { + static let context = DatabaseManager.shared.viewContext + static let app = StoreApp.makeAltStoreApp(in: context) + static var previews: some View { - AppScreenshot(url: URL(string: "https://apps.sidestore.io/apps/sidestore/v0.1.1/browse-dark.png")!) + AppScreenshot(url: app.screenshotURLs[0]) + .padding() } } diff --git a/AltStore/View Components/ModalNavigationLink.swift b/AltStore/View Components/ModalNavigationLink.swift index e8a9d621..fce881da 100644 --- a/AltStore/View Components/ModalNavigationLink.swift +++ b/AltStore/View Components/ModalNavigationLink.swift @@ -14,6 +14,16 @@ struct ModalNavigationLink: View { @State var isPresentingModal: Bool = false + init(@ViewBuilder modal: @escaping () -> Modal, @ViewBuilder label: @escaping () -> Label) { + self.modal = modal + self.label = label + } + + init(_ title: String, @ViewBuilder modal: @escaping () -> Modal) where Label == Text { + self.modal = modal + self.label = { Text(title) } + } + var body: some View { SwiftUI.Button { self.isPresentingModal = true @@ -26,8 +36,10 @@ struct ModalNavigationLink: View { } } -//struct ModalNavigationLink_Previews: PreviewProvider { -// static var previews: some View { -// ModalNavigationLink() -// } -//} +struct ModalNavigationLink_Previews: PreviewProvider { + static var previews: some View { + ModalNavigationLink("Present Modal") { + Text("Modal") + } + } +} diff --git a/AltStore/View Extensions/Modifiers.swift b/AltStore/View Extensions/Modifiers.swift index e55ca119..dfae90ef 100644 --- a/AltStore/View Extensions/Modifiers.swift +++ b/AltStore/View Extensions/Modifiers.swift @@ -10,7 +10,7 @@ import SwiftUI extension View { - @ViewBuilder func `if`(_ condition: Bool, transform: (Self) -> Content) -> some View { + @ViewBuilder func `if`(_ condition: Bool, @ViewBuilder transform: (Self) -> Content) -> some View { if condition { transform(self) } else { diff --git a/AltStore/Views/App Detail/AppDetailView.swift b/AltStore/Views/App Detail/AppDetailView.swift index 0347115d..741010ab 100644 --- a/AltStore/Views/App Detail/AppDetailView.swift +++ b/AltStore/Views/App Detail/AppDetailView.swift @@ -418,3 +418,16 @@ struct AppDetailView: View { } } } + + +struct AppDetailView_Previews: PreviewProvider { + + static let context = DatabaseManager.shared.viewContext + static let app = StoreApp.makeAltStoreApp(in: context) + + static var previews: some View { + NavigationView { + AppDetailView(storeApp: app) + } + } +} diff --git a/AltStore/Views/App Detail/AppScreenshotsPreview.swift b/AltStore/Views/App Detail/AppScreenshotsPreview.swift index 1056251d..fa33e698 100644 --- a/AltStore/Views/App Detail/AppScreenshotsPreview.swift +++ b/AltStore/Views/App Detail/AppScreenshotsPreview.swift @@ -55,8 +55,17 @@ extension AppScreenshotsPreview: Equatable { } } -//struct AppScreenshotsPreview_Previews: PreviewProvider { -// static var previews: some View { -// AppScreenshotsPreview() -// } -//} +struct AppScreenshotsPreview_Previews: PreviewProvider { + + static let context = DatabaseManager.shared.viewContext + static let app = StoreApp.makeAltStoreApp(in: context) + + static var previews: some View { + Color.clear + .sheet(isPresented: .constant(true)) { + NavigationView { + AppScreenshotsPreview(urls: app.screenshotURLs) + } + } + } +} diff --git a/AltStore/Views/App Detail/AppScreenshotsScrollView.swift b/AltStore/Views/App Detail/AppScreenshotsScrollView.swift index 705b87aa..d3eeed2a 100644 --- a/AltStore/Views/App Detail/AppScreenshotsScrollView.swift +++ b/AltStore/Views/App Detail/AppScreenshotsScrollView.swift @@ -56,3 +56,16 @@ extension Int: Identifiable { self } } + + +import AltStoreCore + +struct AppScreenshotsScrollView_Previews: PreviewProvider { + + static let context = DatabaseManager.shared.viewContext + static let app = StoreApp.makeAltStoreApp(in: context) + + static var previews: some View { + AppScreenshotsScrollView(urls: app.screenshotURLs) + } +} diff --git a/AltStore/Views/App Detail/AppVersionHistoryView.swift b/AltStore/Views/App Detail/AppVersionHistoryView.swift index f0448326..ac95e88a 100644 --- a/AltStore/Views/App Detail/AppVersionHistoryView.swift +++ b/AltStore/Views/App Detail/AppVersionHistoryView.swift @@ -42,8 +42,14 @@ struct AppVersionHistoryView: View { } } -//struct AppVersionHistoryView_Previews: PreviewProvider { -// static var previews: some View { -// AppVersionHistoryView(storeApp: ) -// } -//} +struct AppVersionHistoryView_Previews: PreviewProvider { + + static let context = DatabaseManager.shared.viewContext + static let app = StoreApp.makeAltStoreApp(in: context) + + static var previews: some View { + NavigationView { + AppVersionHistoryView(storeApp: app) + } + } +} diff --git a/AltStore/Views/My Apps/MyAppsView.swift b/AltStore/Views/My Apps/MyAppsView.swift index 0b0342b5..90603753 100644 --- a/AltStore/Views/My Apps/MyAppsView.swift +++ b/AltStore/Views/My Apps/MyAppsView.swift @@ -41,8 +41,6 @@ struct MyAppsView: View { @State var isRefreshingAllApps: Bool = false @State var selectedSideloadingIpaURL: URL? - @State var isShowingAppIDsView: Bool = false - var remainingAppIDs: Int { guard let team = DatabaseManager.shared.activeTeam() else { return 0 @@ -91,7 +89,7 @@ struct MyAppsView: View { .bold() Spacer() - + if !self.isRefreshingAllApps { SwiftUI.Button(L10n.MyAppsView.refreshAll, action: self.refreshAllApps) } else { @@ -121,12 +119,7 @@ struct MyAppsView: View { .foregroundColor(.secondary) } - SwiftUI.Button { - self.isShowingAppIDsView = true - } label: { - Text(L10n.MyAppsView.viewAppIDs) - } - .sheet(isPresented: self.$isShowingAppIDsView) { + ModalNavigationLink(L10n.MyAppsView.viewAppIDs) { NavigationView { AppIDsView() } @@ -140,16 +133,13 @@ struct MyAppsView: View { .navigationTitle(L10n.MyAppsView.myApps) .toolbar { ToolbarItem(placement: .navigationBarLeading) { - SwiftUI.Button { - self.isShowingFilePicker = true + ModalNavigationLink { + DocumentPicker(selectedUrl: $selectedSideloadingIpaURL, supportedTypes: sideloadFileTypes) + .ignoresSafeArea() } label: { Image(systemSymbol: .plus) .imageScale(.large) } - .sheet(isPresented: self.$isShowingFilePicker) { - DocumentPicker(selectedUrl: $selectedSideloadingIpaURL, supportedTypes: sideloadFileTypes) - .ignoresSafeArea() - } .onChange(of: self.selectedSideloadingIpaURL) { newValue in guard let url = newValue else { return @@ -208,7 +198,7 @@ struct MyAppsView: View { func refreshAllApps() { let installedApps = InstalledApp.fetchAppsForRefreshingAll(in: DatabaseManager.shared.viewContext) - + self.isRefreshingAllApps = true self.refresh(installedApps) { result in self.isRefreshingAllApps = false @@ -254,9 +244,9 @@ extension MyAppsView { NotificationManager.shared.showNotification(title: title, detailText: message) } - - self.viewModel.refreshGroup = nil - completionHandler(results) + + self.viewModel.refreshGroup = nil + completionHandler(results) } } @@ -435,6 +425,10 @@ extension MyAppsView { } struct MyAppsView_Previews: PreviewProvider { + + static let context = DatabaseManager.shared.viewContext + static let app = StoreApp.makeAltStoreApp(in: context) + static var previews: some View { NavigationView { MyAppsView() diff --git a/AltStore/Views/Settings/SettingsView.swift b/AltStore/Views/Settings/SettingsView.swift index 97e1891d..30282293 100644 --- a/AltStore/Views/Settings/SettingsView.swift +++ b/AltStore/Views/Settings/SettingsView.swift @@ -27,13 +27,11 @@ struct SettingsView: View { var isBackgroundRefreshEnabled: Bool = true @State var isShowingConnectAppleIDView = false - @State var isShowingAddShortcutView = false - @State var isShowingFeedbackMailView = false @State var isShowingResetPairingFileConfirmation = false @State var externalURLToShow: URL? - let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "" + let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "Unknown Version" var body: some View { List { @@ -93,13 +91,8 @@ struct SettingsView: View { Toggle(isOn: self.$isBackgroundRefreshEnabled, label: { Text(L10n.SettingsView.backgroundRefresh) }) - - SwiftUI.Button { - self.isShowingAddShortcutView = true - } label: { - Text(L10n.SettingsView.addToSiri) - } - .sheet(isPresented: self.$isShowingAddShortcutView) { + + ModalNavigationLink(L10n.SettingsView.addToSiri) { if let shortcut = INShortcut(intent: INInteraction.refreshAllApps().intent) { SiriShortcutSetupView(shortcut: shortcut) } @@ -163,10 +156,7 @@ struct SettingsView: View { } if MailComposeView.canSendMail { - SwiftUI.Button("Send Feedback") { - self.isShowingFeedbackMailView = true - } - .sheet(isPresented: self.$isShowingFeedbackMailView) { + ModalNavigationLink("Send Feedback") { MailComposeView(recipients: ["support@sidestore.io"], subject: "SideStore Beta \(appVersion) Feedback") { NotificationManager.shared.showNotification(title: "Thank you for your feedback!") diff --git a/AltStoreCore/Model/StoreApp.swift b/AltStoreCore/Model/StoreApp.swift index 2e38b57d..a8531a0f 100644 --- a/AltStoreCore/Model/StoreApp.swift +++ b/AltStoreCore/Model/StoreApp.swift @@ -342,25 +342,31 @@ public extension StoreApp class func makeAltStoreApp(in context: NSManagedObjectContext) -> StoreApp { let app = StoreApp(context: context) + app.source = Source.makeAltStoreSource(in: context) app.name = "SideStore" app.bundleIdentifier = StoreApp.altstoreAppID app.developerName = "Side Team" app.localizedDescription = "SideStore is an alternative App Store." - app.iconURL = URL(string: "https://user-images.githubusercontent.com/705880/63392210-540c5980-c37b-11e9-968c-8742fc68ab2e.png")! - app.screenshotURLs = [] - app.sourceIdentifier = Source.altStoreIdentifier + app.iconURL = URL(string: "https://apps.sidestore.io/apps/sidestore/v0.1.1/icon.png")! + app.screenshotURLs = [ + URL(string: "https://apps.sidestore.io/apps/sidestore/v0.1.1/browse-dark.png")!, + URL(string: "https://apps.sidestore.io/apps/sidestore/v0.1.1/apps-dark.png")!, + URL(string: "https://apps.sidestore.io/apps/sidestore/v0.1.1/news-dark.png")!, + URL(string: "https://apps.sidestore.io/apps/sidestore/v0.1.1/browse-light.png")!, + URL(string: "https://apps.sidestore.io/apps/sidestore/v0.1.1/apps-light.png")!, + URL(string: "https://apps.sidestore.io/apps/sidestore/v0.1.1/news-light.png")!, + ] + app.tintColor = UIColor(named: "AccentColor") - let appVersion = AppVersion.makeAppVersion(version: "0.3.0", + let appVersion = AppVersion.makeAppVersion(version: Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "Unknown", date: Date(), - downloadURL: URL(string: "http://rileytestut.com")!, + downloadURL: URL(string: "https://github.com/SideStore/SideStore/releases/download/0.1.1/SideStore.ipa")!, size: 0, appBundleID: app.bundleIdentifier, sourceID: Source.altStoreIdentifier, in: context) app.setVersions([appVersion]) - print("makeAltStoreApp StoreApp: \(String(describing: app))") - #if BETA app.isBeta = true #endif