punchnet-macos/punchnet/Views/Network/NetworkDisconnctedView.swift
2026-01-28 23:43:19 +08:00

75 lines
2.3 KiB
Swift

//
// NetworkDisconnctedView.swift
// punchnet
//
// Created by on 2026/1/16.
//
import SwiftUI
struct NetworkDisconnctedView: View {
@Bindable var state: NetworkState
var body: some View {
ZStack {
Color.clear
VStack {
Button {
Task {
try await startVpn()
}
} label: {
Text("连接")
.font(.system(size: 14, weight: .regular))
.padding([.top, .bottom], 8)
.padding([.leading, .trailing], 30)
.foregroundColor(.white)
}
.background(Color(red: 74/255, green: 207/255, blue: 154/255))
.cornerRadius(5)
.frame(width: 120, height: 35)
Button {
Task {
try await VPNManager.shared.disableVpn()
}
} label: {
Text("关闭")
.font(.system(size: 14, weight: .regular))
.padding([.top, .bottom], 8)
.padding([.leading, .trailing], 30)
.foregroundColor(.white)
}
.background(Color(red: 74/255, green: 207/255, blue: 154/255))
.cornerRadius(5)
.frame(width: 120, height: 35)
}
}
}
//
private func startVpn() async throws {
let clientId = SystemConfig.getClientId()
let options = SystemConfig.getOptions(networkId: 8,
networkDomain: "punchnet.com",
ip: "10.211.179.1",
maskLen: 24,
accessToken: "accessToken1234",
hostname: "mysql",
noticePort: 123456)
// token使token
try await VPNManager.shared.enableVpn(options: options!)
}
}
//#Preview {
// NetworkDisconnctedView()
//}