Skip to content

Commit

Permalink
fix(ios): add note to anki in action extension not working
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueGreenMagick committed Mar 21, 2024
1 parent f460c80 commit 245ea6d
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions safari/Yomikiri Action/ActionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,25 @@ class ActionViewController: UIViewController {
}

private func makeMessageHandler() -> UIYomikiriWebView.AdditionalMessageHandler {
{ [weak self] (key: String, _: Any) in
{ [weak self] (key: String, request: Any) in
guard let self = self else {
return nil
}
switch key {
case "close":
if let s = self {
s.done()
return Optional.some(nil)
} else {
return nil
self.done()
return Optional.some(nil)
case "openLink":
guard let urlString = request as? String else {
throw "'openLink' url is not string"
}
guard let url = URL(string: urlString) else {
throw "'openLink' url is not valid: \(urlString)"
}
DispatchQueue.main.async {
self.openURL(url)
}
return Optional.some(nil)
default:
return nil
}
Expand All @@ -94,6 +104,21 @@ class ActionViewController: UIViewController {
// This template doesn't do anything, so we just echo the passed in items.
self.extensionContext!.completeRequest(returningItems: self.extensionContext!.inputItems, completionHandler: nil)
}

func openURL(_ url: URL) {
guard let ctx = self.extensionContext else {
return
}
ctx.open(url)
var responder = self as UIResponder?
let selectorOpenURL = sel_registerName("openURL:")
while responder != nil {
if responder?.responds(to: selectorOpenURL) == true {
responder?.perform(selectorOpenURL, with: url)
}
responder = responder!.next
}
}
}

struct SwiftUIView: View {
Expand Down

0 comments on commit 245ea6d

Please sign in to comment.