Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Enable JIT intent #1085

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions AltStore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@
BFECAC9624FD98BB0077C41F /* NSError+ALTServerError.m in Sources */ = {isa = PBXBuildFile; fileRef = BF1E314922A060F400370A3C /* NSError+ALTServerError.m */; };
BFF00D302501BD7D00746320 /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = BFF00D2F2501BD7D00746320 /* Intents.intentdefinition */; };
BFF00D322501BDA100746320 /* BackgroundRefreshAppsOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFF00D312501BDA100746320 /* BackgroundRefreshAppsOperation.swift */; };
BFF00D342501BDCF00746320 /* IntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFF00D332501BDCF00746320 /* IntentHandler.swift */; };
BFF00D342501BDCF00746320 /* RefreshAllIntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFF00D332501BDCF00746320 /* RefreshAllIntentHandler.swift */; };
BFF0394B25F0551600BE607D /* MenuController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFF0394A25F0551600BE607D /* MenuController.swift */; };
BFF0B68E23219520007A79E1 /* PatreonViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFF0B68D23219520007A79E1 /* PatreonViewController.swift */; };
BFF0B69023219C6D007A79E1 /* PatreonComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFF0B68F23219C6D007A79E1 /* PatreonComponents.swift */; };
Expand Down Expand Up @@ -370,6 +370,7 @@
D5F2F6A92720B7C20081CCF5 /* PatchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5F2F6A82720B7C20081CCF5 /* PatchViewController.swift */; };
D5F99A1828D11DB500476A16 /* AltStore10ToAltStore11.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = D5F99A1728D11DB500476A16 /* AltStore10ToAltStore11.xcmappingmodel */; };
D5F99A1A28D12B1400476A16 /* StoreApp10ToStoreApp11Policy.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5F99A1928D12B1400476A16 /* StoreApp10ToStoreApp11Policy.swift */; };
D79F3FE42923206E0005D387 /* EnableJITIntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = D79F3FE32923206E0005D387 /* EnableJITIntentHandler.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -798,7 +799,7 @@
BFE972E2260A8B2700D0BDAC /* NSError+libimobiledevice.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSError+libimobiledevice.mm"; sourceTree = "<group>"; };
BFF00D2F2501BD7D00746320 /* Intents.intentdefinition */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.intentdefinition; path = Intents.intentdefinition; sourceTree = "<group>"; };
BFF00D312501BDA100746320 /* BackgroundRefreshAppsOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BackgroundRefreshAppsOperation.swift; sourceTree = "<group>"; };
BFF00D332501BDCF00746320 /* IntentHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IntentHandler.swift; sourceTree = "<group>"; };
BFF00D332501BDCF00746320 /* RefreshAllIntentHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RefreshAllIntentHandler.swift; sourceTree = "<group>"; };
BFF0394A25F0551600BE607D /* MenuController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuController.swift; sourceTree = "<group>"; };
BFF0B68D23219520007A79E1 /* PatreonViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PatreonViewController.swift; sourceTree = "<group>"; };
BFF0B68F23219C6D007A79E1 /* PatreonComponents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PatreonComponents.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -843,6 +844,7 @@
D5F2F6A82720B7C20081CCF5 /* PatchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PatchViewController.swift; sourceTree = "<group>"; };
D5F99A1728D11DB500476A16 /* AltStore10ToAltStore11.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; path = AltStore10ToAltStore11.xcmappingmodel; sourceTree = "<group>"; };
D5F99A1928D12B1400476A16 /* StoreApp10ToStoreApp11Policy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreApp10ToStoreApp11Policy.swift; sourceTree = "<group>"; };
D79F3FE32923206E0005D387 /* EnableJITIntentHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnableJITIntentHandler.swift; sourceTree = "<group>"; };
EA79A60285C6AF5848AA16E9 /* Pods-AltStore.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AltStore.debug.xcconfig"; path = "Target Support Files/Pods-AltStore/Pods-AltStore.debug.xcconfig"; sourceTree = "<group>"; };
FC3822AB1C4CF1D4CDF7445D /* Pods_AltServer.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AltServer.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -1737,8 +1739,9 @@
BFF00D2E2501BD4B00746320 /* Intents */ = {
isa = PBXGroup;
children = (
D79F3FE32923206E0005D387 /* EnableJITIntentHandler.swift */,
BFF00D2F2501BD7D00746320 /* Intents.intentdefinition */,
BFF00D332501BDCF00746320 /* IntentHandler.swift */,
BFF00D332501BDCF00746320 /* RefreshAllIntentHandler.swift */,
);
path = Intents;
sourceTree = "<group>";
Expand Down Expand Up @@ -2655,7 +2658,7 @@
BFF00D322501BDA100746320 /* BackgroundRefreshAppsOperation.swift in Sources */,
BF0C4EBD22A1BD8B009A2DD7 /* AppManager.swift in Sources */,
BF2901312318F7A800D88A45 /* AppBannerView.swift in Sources */,
BFF00D342501BDCF00746320 /* IntentHandler.swift in Sources */,
BFF00D342501BDCF00746320 /* RefreshAllIntentHandler.swift in Sources */,
BFDBBD80246CB84F004ED2F3 /* RemoveAppBackupOperation.swift in Sources */,
BFF0B6942321CB85007A79E1 /* AuthenticationViewController.swift in Sources */,
BF3432FB246B894F0052F4A1 /* BackupAppOperation.swift in Sources */,
Expand All @@ -2665,6 +2668,7 @@
BFE6326C22A86FF300F30809 /* AuthenticationOperation.swift in Sources */,
BFF435D8255CBDAB00DD724F /* ALTApplication+AltStoreApp.swift in Sources */,
BF4B78FE24B3D1DB008AB4AC /* SceneDelegate.swift in Sources */,
D79F3FE42923206E0005D387 /* EnableJITIntentHandler.swift in Sources */,
BF6C8FB02429599900125131 /* TextCollectionReusableView.swift in Sources */,
BF663C4F2433ED8200DAA738 /* FileManager+DirectorySize.swift in Sources */,
D57DF63F271E51E400677701 /* ALTAppPatcher.m in Sources */,
Expand Down
18 changes: 15 additions & 3 deletions AltStore/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

@available(iOS 14, *)
private var intentHandler: IntentHandler {
get { _intentHandler as! IntentHandler }
private var intentHandler: RefreshAllIntentHandler {
get { _intentHandler as! RefreshAllIntentHandler }
set { _intentHandler = newValue }
}

@available(iOS 14, *)
private var enableJITIntentHandler: EnableJITIntentHandler {
get { _intentHandler as! EnableJITIntentHandler }
set { _intentHandler = newValue }
}

Expand All @@ -47,7 +53,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

private lazy var _intentHandler: Any = {
guard #available(iOS 14, *) else { fatalError() }
return IntentHandler()
return RefreshAllIntentHandler()
}()

private lazy var _enableJITIntentHandler: Any = {
guard #available(iOS 14, *) else { fatalError() }
return EnableJITIntentHandler()
}()

private lazy var _viewAppIntentHandler: Any = {
Expand Down Expand Up @@ -134,6 +145,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
switch intent
{
case is RefreshAllIntent: return self.intentHandler
case is EnableJITIntent: return self.enableJITIntentHandler
case is ViewAppIntent: return self.viewAppIntentHandler
default: return nil
}
Expand Down
1 change: 1 addition & 0 deletions AltStore/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<string>AltStore uses the local network to find and communicate with AltServer.</string>
<key>NSUserActivityTypes</key>
<array>
<string>EnableJITIntent</string>
<string>RefreshAllIntent</string>
<string>ViewAppIntent</string>
</array>
Expand Down
71 changes: 71 additions & 0 deletions AltStore/Intents/EnableJITIntentHandler.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// EnableJITIntentHandler.swift
// AltStore
//
// Created by Jhonatan A. on 11/11/22.
// Copyright © 2022 Riley Testut. All rights reserved.
//

import Foundation

import AltStoreCore
import Intents

@available(iOS 14, *)
class EnableJITIntentHandler: NSObject, EnableJITIntentHandling
{
public func provideAppOptionsCollection(for intent: EnableJITIntent, with completion: @escaping (INObjectCollection<App>?, 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)
}
}
}

func handle(intent: EnableJITIntent, completion: @escaping (EnableJITIntentResponse) -> Void)
{
guard let requestedAppBundleIdentifier = intent.app?.identifier else {
completion(EnableJITIntentResponse(code: .failure, userActivity: nil))
return
}

DatabaseManager.shared.start { (error) in
if let _ = error
{
completion(EnableJITIntentResponse(code: .failure, userActivity: nil))
return
}

DatabaseManager.shared.persistentContainer.performBackgroundTask { (context) in
let predicate = NSPredicate(format: "%K == %@", #keyPath(InstalledApp.bundleIdentifier), requestedAppBundleIdentifier)
guard let installedApp = InstalledApp.first(satisfying: predicate, in: context) else {
completion(EnableJITIntentResponse(code: .failure, userActivity: nil))
return
}

AppManager.shared.enableJIT(for: installedApp) { result in
DispatchQueue.main.async {
switch result
{
case .success:
completion(EnableJITIntentResponse(code: .success, userActivity: nil))
case .failure( _):
completion(EnableJITIntentResponse(code: .failure, userActivity: nil))
}
}
}
}
}
}
}
178 changes: 177 additions & 1 deletion AltStore/Intents/Intents.intentdefinition
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,184 @@
<key>INIntentVerb</key>
<string>Do</string>
</dict>
<dict>
<key>INIntentCategory</key>
<string>generic</string>
<key>INIntentConfigurable</key>
<true/>
<key>INIntentDescriptionID</key>
<string>AammMZ</string>
<key>INIntentIneligibleForSuggestions</key>
<true/>
<key>INIntentLastParameterTag</key>
<integer>2</integer>
<key>INIntentManagedParameterCombinations</key>
<dict>
<key>app</key>
<dict>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
<key>INIntentParameterCombinationTitle</key>
<string>Enable JIT</string>
<key>INIntentParameterCombinationTitleID</key>
<string>zIkmRr</string>
<key>INIntentParameterCombinationUpdatesLinked</key>
<true/>
</dict>
</dict>
<key>INIntentName</key>
<string>EnableJIT</string>
<key>INIntentParameters</key>
<array>
<dict>
<key>INIntentParameterConfigurable</key>
<true/>
<key>INIntentParameterDisplayName</key>
<string>App</string>
<key>INIntentParameterDisplayNameID</key>
<string>k9PKrs</string>
<key>INIntentParameterDisplayPriority</key>
<integer>1</integer>
<key>INIntentParameterName</key>
<string>app</string>
<key>INIntentParameterObjectType</key>
<string>App</string>
<key>INIntentParameterObjectTypeNamespace</key>
<string>KyhEWE</string>
<key>INIntentParameterPromptDialogs</key>
<array>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogType</key>
<string>Configuration</string>
</dict>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogType</key>
<string>Primary</string>
</dict>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogFormatString</key>
<string>There are ${count} options matching ‘${app}’.</string>
<key>INIntentParameterPromptDialogFormatStringID</key>
<string>rqSFTo</string>
<key>INIntentParameterPromptDialogType</key>
<string>DisambiguationIntroduction</string>
</dict>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogFormatString</key>
<string>Just to confirm, you wanted ‘${app}’?</string>
<key>INIntentParameterPromptDialogFormatStringID</key>
<string>OuGBx2</string>
<key>INIntentParameterPromptDialogType</key>
<string>Confirmation</string>
</dict>
</array>
<key>INIntentParameterSupportsDynamicEnumeration</key>
<true/>
<key>INIntentParameterTag</key>
<integer>2</integer>
<key>INIntentParameterType</key>
<string>Object</string>
</dict>
</array>
<key>INIntentResponse</key>
<dict>
<key>INIntentResponseCodes</key>
<array>
<dict>
<key>INIntentResponseCodeName</key>
<string>success</string>
<key>INIntentResponseCodeSuccess</key>
<true/>
</dict>
<dict>
<key>INIntentResponseCodeName</key>
<string>failure</string>
</dict>
</array>
</dict>
<key>INIntentTitle</key>
<string>Enable JIT</string>
<key>INIntentTitleID</key>
<string>qJbxKN</string>
<key>INIntentType</key>
<string>Custom</string>
<key>INIntentVerb</key>
<string>Do</string>
</dict>
</array>
<key>INTypes</key>
<array/>
<array>
<dict>
<key>INTypeDisplayName</key>
<string>App</string>
<key>INTypeDisplayNameID</key>
<string>UqN4iE</string>
<key>INTypeLastPropertyTag</key>
<integer>99</integer>
<key>INTypeName</key>
<string>App</string>
<key>INTypeProperties</key>
<array>
<dict>
<key>INTypePropertyDefault</key>
<true/>
<key>INTypePropertyDisplayPriority</key>
<integer>1</integer>
<key>INTypePropertyName</key>
<string>identifier</string>
<key>INTypePropertyTag</key>
<integer>1</integer>
<key>INTypePropertyType</key>
<string>String</string>
</dict>
<dict>
<key>INTypePropertyDefault</key>
<true/>
<key>INTypePropertyDisplayPriority</key>
<integer>2</integer>
<key>INTypePropertyName</key>
<string>displayString</string>
<key>INTypePropertyTag</key>
<integer>2</integer>
<key>INTypePropertyType</key>
<string>String</string>
</dict>
<dict>
<key>INTypePropertyDefault</key>
<true/>
<key>INTypePropertyDisplayPriority</key>
<integer>3</integer>
<key>INTypePropertyName</key>
<string>pronunciationHint</string>
<key>INTypePropertyTag</key>
<integer>3</integer>
<key>INTypePropertyType</key>
<string>String</string>
</dict>
<dict>
<key>INTypePropertyDefault</key>
<true/>
<key>INTypePropertyDisplayPriority</key>
<integer>4</integer>
<key>INTypePropertyName</key>
<string>alternativeSpeakableMatches</string>
<key>INTypePropertySupportsMultipleValues</key>
<true/>
<key>INTypePropertyTag</key>
<integer>4</integer>
<key>INTypePropertyType</key>
<string>SpeakableString</string>
</dict>
</array>
</dict>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
import AltStoreCore

@available(iOS 14, *)
class IntentHandler: NSObject, RefreshAllIntentHandling
class RefreshAllIntentHandler: NSObject, RefreshAllIntentHandling
{
private let queue = DispatchQueue(label: "io.altstore.IntentHandler")

Expand Down Expand Up @@ -92,7 +92,7 @@ class IntentHandler: NSObject, RefreshAllIntentHandling
}

@available(iOS 14, *)
private extension IntentHandler
private extension RefreshAllIntentHandler
{
func finish(_ intent: RefreshAllIntent, response: RefreshAllIntentResponse)
{
Expand Down
Loading