File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33<plist version =" 1.0" >
44<dict >
5+ <key >CFBundleURLTypes </key >
6+ <array >
7+ <dict >
8+ <key >CFBundleURLName </key >
9+ <string >com.localdevvpn </string >
10+ <key >CFBundleURLSchemes </key >
11+ <array >
12+ <string >localdevvpn </string >
13+ </array >
14+ </dict >
15+ </array >
516 <key >NSBonjourServices </key >
617 <array >
718 <string >_apple-mobdev2._tcp </string >
Original file line number Diff line number Diff line change @@ -12,6 +12,38 @@ struct LocalDevVPNApp: App {
1212 var body : some Scene {
1313 WindowGroup {
1414 ContentView ( )
15+ . onOpenURL { url in
16+ handleURL ( url)
17+ }
18+ }
19+ }
20+
21+ private func handleURL( _ url: URL ) {
22+ guard url. scheme == " localdevvpn " else { return }
23+
24+ let tunnelManager = TunnelManager . shared
25+
26+ switch url. host {
27+ case " enable " :
28+ tunnelManager. startVPN ( )
29+ if let components = URLComponents ( url: url, resolvingAgainstBaseURL: false ) ,
30+ let schemeParam = components. queryItems? . first ( where: { $0. name == " scheme " } ) ? . value {
31+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + 1.0 ) {
32+ let callbackURL = URL ( string: " \( schemeParam) :// " ) !
33+ UIApplication . shared. open ( callbackURL)
34+ }
35+ }
36+ case " disable " :
37+ tunnelManager. stopVPN ( )
38+ if let components = URLComponents ( url: url, resolvingAgainstBaseURL: false ) ,
39+ let schemeParam = components. queryItems? . first ( where: { $0. name == " scheme " } ) ? . value {
40+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + 1.0 ) {
41+ let callbackURL = URL ( string: " \( schemeParam) :// " ) !
42+ UIApplication . shared. open ( callbackURL)
43+ }
44+ }
45+ default :
46+ break
1547 }
1648 }
1749}
You can’t perform that action at this time.
0 commit comments