open mac app when read now button is tapped from share extension

This commit is contained in:
Satindar Dhillon
2022-06-30 16:02:19 -07:00
parent 62a7b41ccc
commit b752fdc9d0
2 changed files with 16 additions and 2 deletions

View File

@ -26,12 +26,17 @@ public class ShareExtensionViewModel: ObservableObject {
let saveService = ExtensionSaveService()
func handleReadNowAction(requestId: String, extensionContext: NSExtensionContext?) {
// TODO: write macos version
#if os(iOS)
let deepLinkUrl = NSURL(string: "omnivore://shareExtensionRequestID/\(requestId)")
if let application = UIApplication.value(forKeyPath: #keyPath(UIApplication.shared)) as? UIApplication {
let deepLinkUrl = NSURL(string: "omnivore://shareExtensionRequestID/\(requestId)")
application.perform(NSSelectorFromString("openURL:"), with: deepLinkUrl)
}
#else
let deepLinkUrl = URL(string: "omnivore://shareExtensionRequestID/\(requestId)")
let workspace = NSWorkspace.value(forKeyPath: #keyPath(NSWorkspace.shared)) as? NSWorkspace
if let workspace = workspace, let deepLinkUrl = deepLinkUrl {
workspace.open(deepLinkUrl)
}
#endif
extensionContext?.completeRequest(returningItems: [], completionHandler: nil)
}

View File

@ -131,6 +131,15 @@ import Views
loadItems(isRefresh: true)
}
}
.handlesExternalEvents(preferring: Set(["shareExtensionRequestID"]), allowing: Set(["*"]))
.onOpenURL { url in
viewModel.linkRequest = nil
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) {
if let linkRequestID = DeepLink.make(from: url)?.linkRequestID {
viewModel.linkRequest = LinkRequest(id: UUID(), serverID: linkRequestID)
}
}
}
}
}