use LSApplicationWorkspace to open PB

This commit is contained in:
leminlimez committed 2025-06-03 19:57:53 -04:00
1 parent 582efbacbf
commit b15c6854f2
4 files changed
+20 -5

No files matched your search

@@ -22,6 +22,17 @@ class PosterBoardManager {
return tendiesStoreURL 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 { private static func unzipFile(at url: URL) throws -> URL {
let fileName = url.deletingPathExtension().lastPathComponent let fileName = url.deletingPathExtension().lastPathComponent
let fileData = try Data(contentsOf: url) let fileData = try Data(contentsOf: url)
+5 -1
View File
@@ -76,7 +76,11 @@ struct ContentView: View {
Haptic.shared.notify(.success) Haptic.shared.notify(.success)
UIApplication.shared.dismissAlert(animated: false) 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: { 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) }, noCancel: true)
} catch { } catch {
Haptic.shared.notify(.error) Haptic.shared.notify(.error)
@@ -34,8 +34,8 @@ let onBoardingCards: [OnBoardingPage] = [
image: "Logo" image: "Logo"
), ),
.init( .init(
title: "Install the Shortcut", title: "Install the Fallback Shortcut (Optional)",
description: "To apply, you will need a shortcut that opens PosterBoard.", description: "To apply, PosterBoard will need to open.\n\nYou can install an optional shortcut if the original method fails.",
image: "Shortcuts", image: "Shortcuts",
link: URL(string: PosterBoardManager.ShortcutURL), link: URL(string: PosterBoardManager.ShortcutURL),
linkName: "Get Shortcut" linkName: "Get Shortcut"
+2 -2
View File
@@ -83,12 +83,12 @@ struct SettingsView: View {
Section { Section {
if let scURL = URL(string: PosterBoardManager.ShortcutURL) { if let scURL = URL(string: PosterBoardManager.ShortcutURL) {
Link(destination: scURL) { 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") { if let fbURL = URL(string: "shortcuts://run-shortcut?name=PosterBoard&input=text&text=troubleshoot") {
Link(destination: fbURL) { Link(destination: fbURL) {
Label("Create Fallback Method", systemImage: "appclip") Label("Create Additional Fallback Method", systemImage: "appclip")
} }
} }
if let wpURL = URL(string: PosterBoardManager.WallpapersURL) { if let wpURL = URL(string: PosterBoardManager.WallpapersURL) {