diff --git a/AltStore.xcodeproj/project.pbxproj b/AltStore.xcodeproj/project.pbxproj index 60847e1f..db88d749 100644 --- a/AltStore.xcodeproj/project.pbxproj +++ b/AltStore.xcodeproj/project.pbxproj @@ -230,6 +230,7 @@ BFB6B220231870B00022A802 /* NewsCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFB6B21F231870B00022A802 /* NewsCollectionViewCell.swift */; }; BFB6B22423187A3D0022A802 /* NewsCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = BFB6B22323187A3D0022A802 /* NewsCollectionViewCell.xib */; }; BFBE0004250ACFFB0080826E /* ViewApp.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = BF989191250AAE86002ACF50 /* ViewApp.intentdefinition */; settings = {ATTRIBUTES = (no_codegen, ); }; }; + BFBE0007250AD0E70080826E /* ViewAppIntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF989190250AAE86002ACF50 /* ViewAppIntentHandler.swift */; }; BFC1F38D22AEE3A4003AC21A /* DownloadAppOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFC1F38C22AEE3A4003AC21A /* DownloadAppOperation.swift */; }; BFC57A652416C72400EB891E /* DeactivateAppOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFC57A642416C72400EB891E /* DeactivateAppOperation.swift */; }; BFC57A6E2416FC5D00EB891E /* InstalledAppsCollectionHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFC57A6D2416FC5D00EB891E /* InstalledAppsCollectionHeaderView.swift */; }; @@ -639,6 +640,7 @@ BF989172250AABF4002ACF50 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; BF98917C250AAC4F002ACF50 /* Countdown.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Countdown.swift; sourceTree = ""; }; BF98917D250AAC4F002ACF50 /* AltWidget.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AltWidget.swift; sourceTree = ""; }; + BF989190250AAE86002ACF50 /* ViewAppIntentHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewAppIntentHandler.swift; sourceTree = ""; }; BF989191250AAE86002ACF50 /* ViewApp.intentdefinition */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.intentdefinition; path = ViewApp.intentdefinition; sourceTree = ""; }; BF9ABA4422DCFF43008935CF /* BrowseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowseViewController.swift; sourceTree = ""; }; BF9ABA4622DD0638008935CF /* BrowseCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowseCollectionViewCell.swift; sourceTree = ""; }; @@ -1284,6 +1286,7 @@ isa = PBXGroup; children = ( BF989191250AAE86002ACF50 /* ViewApp.intentdefinition */, + BF989190250AAE86002ACF50 /* ViewAppIntentHandler.swift */, ); path = Intents; sourceTree = ""; @@ -2377,6 +2380,7 @@ BFC84A4D2421A19100853474 /* SourcesViewController.swift in Sources */, BFF0B696232242D3007A79E1 /* LicensesViewController.swift in Sources */, BFD52BD422A0800A000B7ED1 /* ServerManager.swift in Sources */, + BFBE0007250AD0E70080826E /* ViewAppIntentHandler.swift in Sources */, BFDB6A0822AAED73007EA6D6 /* ResignAppOperation.swift in Sources */, BF770E5122BB1CF6002A40FE /* InstallAppOperation.swift in Sources */, BF9ABA4B22DD1380008935CF /* NavigationBar.swift in Sources */, diff --git a/AltStore/AppDelegate.swift b/AltStore/AppDelegate.swift index 3018668d..ab55aaf3 100644 --- a/AltStore/AppDelegate.swift +++ b/AltStore/AppDelegate.swift @@ -33,7 +33,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? + @available(iOS 14, *) private lazy var intentHandler = IntentHandler() + + @available(iOS 14, *) + private lazy var viewAppIntentHandler = ViewAppIntentHandler() func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { @@ -95,8 +99,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, handlerFor intent: INIntent) -> Any? { - guard intent is RefreshAllIntent else { return nil } - return self.intentHandler + guard #available(iOS 14, *) else { return nil } + + switch intent + { + case is RefreshAllIntent: return self.intentHandler + case is ViewAppIntent: return self.viewAppIntentHandler + default: return nil + } } } diff --git a/AltStore/Info.plist b/AltStore/Info.plist index 46b781a6..8c604985 100644 --- a/AltStore/Info.plist +++ b/AltStore/Info.plist @@ -69,6 +69,7 @@ INIntentsSupported RefreshAllIntent + ViewAppIntent LSApplicationQueriesSchemes @@ -92,6 +93,7 @@ NSUserActivityTypes RefreshAllIntent + ViewAppIntent UIApplicationSceneManifest diff --git a/AltStore/Intents/IntentHandler.swift b/AltStore/Intents/IntentHandler.swift index f42a3924..fc4ebd4f 100644 --- a/AltStore/Intents/IntentHandler.swift +++ b/AltStore/Intents/IntentHandler.swift @@ -10,6 +10,7 @@ import Foundation import AltStoreCore +@available(iOS 14, *) class IntentHandler: NSObject, RefreshAllIntentHandling { private let queue = DispatchQueue(label: "io.altstore.IntentHandler") @@ -75,6 +76,7 @@ class IntentHandler: NSObject, RefreshAllIntentHandling } } +@available(iOS 14, *) private extension IntentHandler { func finish(_ intent: RefreshAllIntent, response: RefreshAllIntentResponse) diff --git a/AltStoreCore/Intents/ViewAppIntentHandler.swift b/AltStoreCore/Intents/ViewAppIntentHandler.swift new file mode 100644 index 00000000..798f2a64 --- /dev/null +++ b/AltStoreCore/Intents/ViewAppIntentHandler.swift @@ -0,0 +1,33 @@ +// +// ViewAppIntentHandler.swift +// ViewAppIntentHandler +// +// Created by Riley Testut on 7/10/20. +// Copyright © 2020 Riley Testut. All rights reserved. +// + +import Intents +import AltStoreCore + +@available(iOS 14, *) +public class ViewAppIntentHandler: NSObject, ViewAppIntentHandling +{ + public func provideAppOptionsCollection(for intent: ViewAppIntent, with completion: @escaping (INObjectCollection?, Error?) -> Void) + { + DatabaseManager.shared.start { (error) in + if let error = error + { + print("Error starting extension:", error) + } + + DatabaseManager.shared.persistentContainer.performBackgroundTask { (context) in + let apps = InstalledApp.all(in: context).map { (installedApp) in + return App(identifier: installedApp.bundleIdentifier, display: installedApp.name) + } + + let collection = INObjectCollection(items: apps) + completion(collection, nil) + } + } + } +}