-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from allenai/playground-access-for-unsupporte…
…d-devices Playground access for unsupported devices
- Loading branch information
Showing
6 changed files
with
206 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
OLMoE.swift/Assets.xcassets/Warning.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"color" : { | ||
"color-space" : "srgb", | ||
"components" : { | ||
"alpha" : "1.000", | ||
"red" : "0xFF", | ||
"green" : "0xA3", | ||
"blue" : "0x1C" | ||
} | ||
}, | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import SwiftUI | ||
import WebKit | ||
|
||
struct WebView: UIViewRepresentable { | ||
let url: URL | ||
|
||
func makeUIView(context: UIViewRepresentableContext<WebView>) -> WKWebView { | ||
let webView = WKWebView() | ||
webView.navigationDelegate = context.coordinator | ||
return webView | ||
} | ||
|
||
func updateUIView(_ uiView: WKWebView, context: UIViewRepresentableContext<WebView>) { | ||
let request = URLRequest(url: url) | ||
uiView.load(request) | ||
} | ||
|
||
class Coordinator: NSObject, WKNavigationDelegate { | ||
var parent: WebView | ||
|
||
init(_ parent: WebView) { | ||
self.parent = parent | ||
} | ||
|
||
// MARK: - WKNavigationDelegate | ||
|
||
/// Intercepts navigation actions in the WKWebView. | ||
func webView(_ webView: WKWebView, | ||
decidePolicyFor navigationAction: WKNavigationAction, | ||
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { | ||
|
||
print("Navigation action type: \(navigationAction.navigationType)") | ||
|
||
// Log the destination URL if available. | ||
if let url = navigationAction.request.url { | ||
print("Destination URL: \(url.absoluteString)") | ||
} | ||
|
||
// Check if the navigation action is triggered by a link click or form submission, | ||
// and the URL contains "http" | ||
if let url = navigationAction.request.url, | ||
url.absoluteString.contains("http") || | ||
navigationAction.navigationType == .linkActivated || navigationAction.navigationType == .formSubmitted, | ||
!url.absoluteString.contains("https://playground.allenai.org") { | ||
// Open the URL in Safari. | ||
UIApplication.shared.open(url, options: [:], completionHandler: nil) | ||
// Cancel the navigation within the web view. | ||
decisionHandler(.cancel) | ||
return | ||
} | ||
|
||
// Allow all other types of navigation. | ||
decisionHandler(.allow) | ||
} | ||
} | ||
|
||
func makeCoordinator() -> Coordinator { | ||
Coordinator(self) | ||
} | ||
} | ||
|
||
struct WebViewWithBanner: View { | ||
let url: URL | ||
let onDismiss: () -> Void | ||
|
||
var body: some View { | ||
VStack(spacing: 0) { | ||
HStack { | ||
Text("⚠️ Running on AI2's servers - not on your device") | ||
.font(.footnote) | ||
|
||
Spacer() | ||
|
||
Button(action: onDismiss) { | ||
Image(systemName: "xmark.circle.fill") | ||
.foregroundColor(.black) | ||
} | ||
} | ||
.padding(8) | ||
.frame(maxWidth: .infinity) | ||
.background(Color("Warning")) | ||
.foregroundColor(.black) | ||
|
||
WebView(url: url) | ||
} | ||
} | ||
} |