Show Tailscale sign-in in an in-app web view
This commit is contained in:
@@ -3,6 +3,9 @@ import Network
|
||||
import Observation
|
||||
import SwiftUI
|
||||
import TailscaleKit
|
||||
#if os(iOS)
|
||||
import SafariServices
|
||||
#endif
|
||||
|
||||
func slug(_ text: String) -> String {
|
||||
var out = ""
|
||||
@@ -288,6 +291,7 @@ private struct NodeLoginRow: View {
|
||||
let role: String
|
||||
let state: String
|
||||
let authURL: URL?
|
||||
@State private var signingIn = false
|
||||
|
||||
var body: some View {
|
||||
HStack(alignment: .center, spacing: 12) {
|
||||
@@ -307,9 +311,13 @@ private struct NodeLoginRow: View {
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
if state != "Running" {
|
||||
Button("Sign in") {
|
||||
#if os(macOS)
|
||||
if let authURL {
|
||||
openExternal(authURL)
|
||||
}
|
||||
#else
|
||||
signingIn = true
|
||||
#endif
|
||||
}
|
||||
.buttonStyle(WebButtonStyle(primary: true))
|
||||
.disabled(authURL == nil)
|
||||
@@ -319,5 +327,30 @@ private struct NodeLoginRow: View {
|
||||
.padding(12)
|
||||
.background(Palette.bg, in: RoundedRectangle(cornerRadius: 8))
|
||||
.overlay(RoundedRectangle(cornerRadius: 8).stroke(Palette.border))
|
||||
#if os(iOS)
|
||||
.sheet(isPresented: $signingIn) {
|
||||
if let authURL {
|
||||
SafariView(url: authURL)
|
||||
.ignoresSafeArea()
|
||||
}
|
||||
}
|
||||
.onChange(of: state) {
|
||||
if state == "Running" {
|
||||
signingIn = false
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
private struct SafariView: UIViewControllerRepresentable {
|
||||
let url: URL
|
||||
|
||||
func makeUIViewController(context: Context) -> SFSafariViewController {
|
||||
SFSafariViewController(url: url)
|
||||
}
|
||||
|
||||
func updateUIViewController(_ controller: SFSafariViewController, context: Context) {}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user