Files
SideStore/SideStoreApp/Sources/SideStoreAppKit/Authentication/Intents/ViewAppIntentHandler.swift

35 lines
1.1 KiB
Swift
Raw Normal View History

//
// ViewAppIntentHandler.swift
// ViewAppIntentHandler
//
// Created by Riley Testut on 7/10/20.
// Copyright © 2020 Riley Testut. All rights reserved.
//
import Intents
2023-03-01 14:36:52 -05:00
import Shared
import SideStoreCore
2023-03-02 00:40:11 -05:00
import os.log
@available(iOS 14, *)
2023-03-01 00:48:36 -05:00
public class ViewAppIntentHandler: NSObject, ViewAppIntentHandling {
2023-03-02 00:40:11 -05:00
public func provideAppOptionsCollection(for intent: ViewAppIntent, with completion: @escaping (INObjectCollection<App>?, Error?) -> Void) {
2023-03-01 00:48:36 -05:00
DatabaseManager.shared.start { error in
if let error = error {
2023-03-02 00:40:11 -05:00
os_log("Error starting extension: %@", type: .error , error.localizedDescription)
} else {
os_log("Started extension: %@", type: .info , intent.debugDescription)
}
2023-03-01 00:48:36 -05:00
DatabaseManager.shared.persistentContainer.performBackgroundTask { context in
let apps = InstalledApp.all(in: context).map { installedApp in
App(identifier: installedApp.bundleIdentifier, display: installedApp.name)
}
2023-03-01 00:48:36 -05:00
let collection = INObjectCollection(items: apps)
completion(collection, nil)
}
}
}
}