diff --git a/Pocket Poster/Controllers/PosterBoardManager.swift b/Pocket Poster/Controllers/PosterBoardManager.swift index 2b4d449..7ea6439 100644 --- a/Pocket Poster/Controllers/PosterBoardManager.swift +++ b/Pocket Poster/Controllers/PosterBoardManager.swift @@ -7,6 +7,7 @@ import Foundation import ZIPFoundation +import UIKit class PosterBoardManager { private static func unzipFile(at url: URL) throws -> URL { @@ -40,6 +41,12 @@ class PosterBoardManager { return destinationURL } + static func runShortcut(named name: String) { + guard let urlEncodedName = name.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), + let url = URL(string: "shortcuts://run-shortcut?name=\(name)") else { return } + UIApplication.shared.open(url, options: [:], completionHandler: nil) + } + static func getDescriptorsFromTendie(_ url: URL) throws -> URL? { let unzippedDir = try unzipFile(at: url) diff --git a/Pocket Poster/Views/ContentView.swift b/Pocket Poster/Views/ContentView.swift index 1de2d64..baf15c8 100644 --- a/Pocket Poster/Views/ContentView.swift +++ b/Pocket Poster/Views/ContentView.swift @@ -60,7 +60,7 @@ struct ContentView: View { Button(action: { do { try PosterBoardManager.applyTendies(selectedTendies, appHash: pbHash) - lastError = "Please open PosterBoard in the Shortcuts app and then close it from the app switcher." + lastError = "The PosterBoard app will now open. Please close it from the app switcher." showSuccessAlert.toggle() } catch { lastError = error.localizedDescription @@ -91,7 +91,9 @@ struct ContentView: View { Text(lastError ?? "???") } .alert("Success!", isPresented: $showSuccessAlert) { - Button("OK") {} + Button("OK") { + PosterBoardManager.runShortcut(named: "PosterBoard") // shortcut url: https://www.icloud.com/shortcuts/9035ef1d51c247dba8c9861dc10b4aa7 + } } message: { Text(lastError ?? "???") }