From b15c6854f205910bdd83349ba7500d5922f1407d Mon Sep 17 00:00:00 2001 From: leminlimez <59540996+leminlimez@users.noreply.github.com> Date: Tue, 3 Jun 2025 19:57:53 -0400 Subject: [PATCH] use LSApplicationWorkspace to open PB --- Pocket Poster/Controllers/PosterBoardManager.swift | 11 +++++++++++ Pocket Poster/Views/ContentView.swift | 6 +++++- Pocket Poster/Views/OnBoarding/OnBoardingPage.swift | 4 ++-- Pocket Poster/Views/SettingsView.swift | 4 ++-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Pocket Poster/Controllers/PosterBoardManager.swift b/Pocket Poster/Controllers/PosterBoardManager.swift index de3f498..b89d0f3 100644 --- a/Pocket Poster/Controllers/PosterBoardManager.swift +++ b/Pocket Poster/Controllers/PosterBoardManager.swift @@ -22,6 +22,17 @@ class PosterBoardManager { return tendiesStoreURL } + static func openPosterBoard() -> Bool { + guard let obj = objc_getClass("LSApplicationWorkspace") as? NSObject else { return false } + let workspace = obj.perform(Selector(("defaultWorkspace")))?.takeUnretainedValue() as? NSObject + + if let success = workspace?.perform(Selector(("openApplicationWithBundleID:")), with: "com.apple.PosterBoard") { + return success != nil + } + + return false + } + private static func unzipFile(at url: URL) throws -> URL { let fileName = url.deletingPathExtension().lastPathComponent let fileData = try Data(contentsOf: url) diff --git a/Pocket Poster/Views/ContentView.swift b/Pocket Poster/Views/ContentView.swift index e308e11..5df679f 100644 --- a/Pocket Poster/Views/ContentView.swift +++ b/Pocket Poster/Views/ContentView.swift @@ -76,7 +76,11 @@ struct ContentView: View { Haptic.shared.notify(.success) UIApplication.shared.dismissAlert(animated: false) UIApplication.shared.confirmAlert(title: "Success!", body: "The PosterBoard app will now open. Please close it from the app switcher.", onOK: { - PosterBoardManager.runShortcut(named: "PosterBoard") + if !PosterBoardManager.openPosterBoard() { + UIApplication.shared.confirmAlert(title: "Falling Back to Shortcut", body: "PosterBoard failed to open directly. The fallback shortcut will now be opened.", onOK: { + PosterBoardManager.runShortcut(named: "PosterBoard") + }, noCancel: true) + } }, noCancel: true) } catch { Haptic.shared.notify(.error) diff --git a/Pocket Poster/Views/OnBoarding/OnBoardingPage.swift b/Pocket Poster/Views/OnBoarding/OnBoardingPage.swift index ccc62ed..c4ae929 100644 --- a/Pocket Poster/Views/OnBoarding/OnBoardingPage.swift +++ b/Pocket Poster/Views/OnBoarding/OnBoardingPage.swift @@ -34,8 +34,8 @@ let onBoardingCards: [OnBoardingPage] = [ image: "Logo" ), .init( - title: "Install the Shortcut", - description: "To apply, you will need a shortcut that opens PosterBoard.", + title: "Install the Fallback Shortcut (Optional)", + description: "To apply, PosterBoard will need to open.\n\nYou can install an optional shortcut if the original method fails.", image: "Shortcuts", link: URL(string: PosterBoardManager.ShortcutURL), linkName: "Get Shortcut" diff --git a/Pocket Poster/Views/SettingsView.swift b/Pocket Poster/Views/SettingsView.swift index a5d7221..bd0c46e 100644 --- a/Pocket Poster/Views/SettingsView.swift +++ b/Pocket Poster/Views/SettingsView.swift @@ -83,12 +83,12 @@ struct SettingsView: View { Section { if let scURL = URL(string: PosterBoardManager.ShortcutURL) { Link(destination: scURL) { - Label("Download Shortcut", systemImage: "arrow.down.circle") + Label("Download Fallback Shortcut", systemImage: "arrow.down.circle") } } if let fbURL = URL(string: "shortcuts://run-shortcut?name=PosterBoard&input=text&text=troubleshoot") { Link(destination: fbURL) { - Label("Create Fallback Method", systemImage: "appclip") + Label("Create Additional Fallback Method", systemImage: "appclip") } } if let wpURL = URL(string: PosterBoardManager.WallpapersURL) {