123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- //
- // Main.swift
- // naiyoup
- //
- // Created by C Auto on 2021/6/2.
- //
- import SwiftUI
- import Combine
- import SwiftyUserDefaults
- struct RouteView : View {
-
- @Binding var IsQuan : Bool
-
- var body: some View {
- HStack{
- Toggle( self.IsQuan ? "智能路由" : "全局", isOn: self.$IsQuan)
- .foregroundColor(Color.white)
- }
- .padding()
- .frame(width: 200,height: 59)
- .background(Color("SelectBackgrouunColor"))
- .cornerRadius(20)
- .shadow(radius: 10)
- }
-
- }
- struct SwicthNodeView :View {
-
- @Binding var Host : String
-
- var body: some View{
- HStack{
- Image(systemName: "bolt.horizontal.icloud")
- .foregroundColor(Color.white)
- Text(Host)
- .foregroundColor(Color.white)
- Spacer()
- }
- .padding()
- .frame(width: 200,height: 59)
- .background(Color("SelectBackgrouunColor"))
- .cornerRadius(20)
- .shadow(radius: 10)
- }
- }
- struct ProUserView :View{
- var body: some View{
- HStack{
- Image(systemName: "person")
- .foregroundColor(Color.white)
- Text("个人中心")
- .foregroundColor(Color.white)
- Spacer()
- }
- .padding()
- .frame(width: 200,height: 59)
- .background(Color("SelectBackgrouunColor"))
- .cornerRadius(20)
- .shadow(radius: 10)
- }
- }
- struct WebNavigationView :View {
- var body: some View{
- HStack{
- Image(systemName: "paperplane.fill")
- .foregroundColor(Color.white)
- Text("网站导航")
- .foregroundColor(Color.white)
- Spacer()
- }
- .padding()
- .frame(width: 200,height: 59)
- .background(Color("SelectBackgrouunColor"))
- .cornerRadius(20)
- .shadow(radius: 10)
-
- }
- }
- struct MainView: View {
- @State var isQuan : Bool = true
- @State var isPop : Bool = false
- @State var isMePop : Bool = false
- @State var isConnectd: Bool = false
- @State var isYsBool : Bool = false
- //@State var nodelModel : NodelModel? = nil
- var nodelViewModel = NodelViewModel.nodel
-
-
- @ObservedObject var mainViewModel = MainViewModel.main
-
- @State var hosts : String = "智能选线"
-
- init() {
- //UINavigationBar.appearance().backgroundImage(for: <#T##UIBarPosition#>, barMetrics: <#T##UIBarMetrics#>)
-
- UIApplication.statusBarBackgroundColor = UIColor.init(named: "BackgroundColor")
- UINavigationBar.appearance().backgroundColor = UIColor.init(named: "BackgroundColor")
- UINavigationBar.appearance().tintColor = UIColor.white
- UINavigationBar.appearance().barTintColor = UIColor.init(named: "BackgroundColor")
- UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor.white]
- UINavigationBar.appearance().largeTitleTextAttributes = [.foregroundColor: UIColor.white]
- UINavigationBar.appearance().isTranslucent = false
- }
-
-
- var body: some View {
-
- NavigationView{
-
-
-
-
- ZStack{
- Color("BackgroundColor").edgesIgnoringSafeArea(.all)
- VStack(spacing: 15){
- //Spacer()
-
- Text(mainViewModel.vpnstatus)
- .foregroundColor(Color("vStatus"))
-
-
- if self.mainViewModel.authting == true
- {
- ActivityIndicator(isAnimating: self.mainViewModel.authting)
- .configure { $0.color = .white}
- .frame(width: 200, height: 200, alignment: .center)
- .padding()
-
-
- } else {
- Image(mainViewModel.serviceOpen ? "btnswitchon" : "btnswitchoff")
- .resizable()
- .frame(width: 200, height: 200, alignment: .center)
- .padding()
- .onTapGesture {
- //链接vpn
- self.ConnectVPN()
- }
- .alert(isPresented: $isYsBool) {
- Alert(title: Text("关于隐私"),
- message: Text("本应用不会向任何无关第三方提供、出售、出租、分享或交易您的个人信息,除非事先得到您的许可,或该第三方和本应用(含本应用关联公司)单独或共同为您提供服务,且在该服务结束后,其将被禁止访问包括其以前能够访问的所有这些资料。\n本应用亦不允许任何第三方以任何手段收集、编辑、出售或者无偿传播您的个人信息。任何本应用平台用户如从事上述活动,一经发现,本应用有权立即终止与该用户的服务协议。\n为服务用户的目的,本应用可能通过使用您的个人信息,向您提供您感兴趣的信息,包括但不限于向您发出产品和服务信息,或者与本应用合作伙伴共享信息以便他们向您发送有关其产品和服务的信息(后者需要您的事先同意)。"),
- primaryButton: .destructive(Text("确定")) {
- Defaults[\.vpnys] = true
- self.isYsBool = false
- ConnectVPN()
-
- },
- secondaryButton: .cancel(Text("取消")))
- }
-
- }
-
- //.onChange(of: <#T##Equatable#>, perform: <#T##(Equatable) -> Void#>)
-
- RouteView(IsQuan: $isQuan)
-
-
-
-
- NavigationLink(
- destination: LazyView(NodeView(hosts: self.$hosts)),
- label: {
-
- SwicthNodeView(Host: self.$hosts)
- // .onChange(of: self.isPop, perform: { value in
- //
- // if let node = self.nodelViewModel.nodeModel {
- // self.hosts = node.name ?? "智能选线"
- // }
- // })
-
- })
- NavigationLink(
- destination: LazyView(MeView()),
- isActive: self.$isMePop,
- label: {
-
- ProUserView()
-
-
- })
-
-
- //WebNavigationView()
-
- Spacer()
-
- }
- .padding()
- .onAppear {
- print("Home On Appear")
- let controller = UIApplication.shared.windows[0].rootViewController as? MyHontingController
- controller?.statusBarStyle = .lightContent
- UITableView.appearance().tableFooterView = UIView()
- UITableView.appearance().separatorStyle = .none
-
- }
- .onDisappear(perform: {
- UITableView.appearance().tableFooterView = nil
- UITableView.appearance().separatorStyle = .singleLine
- })
-
-
-
- }
-
- }
- .navigationBarHidden(true)
- .navigationViewStyle(StackNavigationViewStyle())
-
-
- }
-
-
- func ConnectVPN() {
-
- if !Defaults[\.vpnys] {
- self.isYsBool = true
- return
- }
-
-
- if mainViewModel.serviceOpen {
- mainViewModel.closeService(completion: {
- self.isConnectd = false
- mainViewModel.vpnstatus = "未连接"
- })
- } else {
-
- guard mainViewModel.GetLoginModel() != nil else {
- return
- }
-
- mainViewModel.route = self.isQuan
-
-
- if let node = self.nodelViewModel.nodeModel {
- // mainViewModel.serverip = node.host ?? ""
- // mainViewModel.port = node.port ?? 0
- // mainViewModel.encrypt = node.method ?? ""
- // mainViewModel.password = node.passwd ?? ""
- // mainViewModel.route = self.isQuan
- // //开始链接
- // mainViewModel.openService{ e in
- //
- // log.debug(e)
- // }
-
- mainViewModel.GetAuthNode(nodel: node, success: { name in
- self.hosts = name ?? "智能选线"
- }, completion: { e in
- log.debug(e)
- })
-
- } else {
-
-
- // mainViewModel.GetAuthNode { name in
- // self.hosts = name ?? "智能选线"
- // } completion: { e in
- // log.debug(e)
- // }
- mainViewModel.GetAuthNode(nodel: nil, success: { name in
- self.hosts = name ?? "智能选线"
- }, completion: { e in
- log.debug(e)
- })
-
-
-
- }
-
-
- }
- }
- }
- struct Main_Previews: PreviewProvider {
- static var previews: some View {
- MainView()
- }
- }
|