blink for ios-vpn app
This commit is contained in:
1 parent
412531861b
commit
3eb46f6ebf
8 files changed
+188
No files matched your search
@@ -13,6 +13,7 @@ enum JoinerFactory {
|
||||
case .dion: return DionJoiner()
|
||||
case .vk: return VKJoiner()
|
||||
case .bitrix: return BitrixJoiner()
|
||||
case .blink: return BlinkJoiner()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,6 +116,31 @@ struct BitrixJoiner: HeadlessJoiner {
|
||||
}
|
||||
}
|
||||
|
||||
struct BlinkJoiner: HeadlessJoiner {
|
||||
private struct Params: Encodable {
|
||||
let joinLink: String
|
||||
let cookiesPath: String
|
||||
let tunnelMode: String
|
||||
let vp8Fps: Int
|
||||
let vp8Batch: Int
|
||||
let dualTrack: Bool
|
||||
let reliable: Bool
|
||||
}
|
||||
|
||||
func start(_ config: TunnelConfig, callback: IosHeadlessCallbackProtocol) {
|
||||
IosStartBlinkHeadless(config.socksPort, config.socksUser, config.socksPass, callback)
|
||||
sendJoinParams(Params(
|
||||
joinLink: config.url,
|
||||
cookiesPath: AppIdentifiers.blinkCookiesURL?.path ?? "",
|
||||
tunnelMode: config.tunnelMode.rawValue,
|
||||
vp8Fps: config.vp8Fps,
|
||||
vp8Batch: config.vp8Batch,
|
||||
dualTrack: config.dualTrack,
|
||||
reliable: config.reliable
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
struct VKJoiner: HeadlessJoiner {
|
||||
func start(_ config: TunnelConfig, callback: IosHeadlessCallbackProtocol) {
|
||||
IosStartVKHeadless(
|
||||
|
||||
@@ -48,6 +48,14 @@ struct ContentView: View {
|
||||
CaptchaScreen(url: url) { vpn.disconnect() }
|
||||
}
|
||||
}
|
||||
.fullScreenCover(isPresented: Binding(
|
||||
get: { vpn.loginLink != nil },
|
||||
set: { if !$0 { vpn.loginLink = nil } }
|
||||
)) {
|
||||
if let link = vpn.loginLink {
|
||||
BlinkLoginScreen(link: link) { vpn.disconnect() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
import SwiftUI
|
||||
import CoreImage.CIFilterBuiltins
|
||||
|
||||
struct BlinkLoginScreen: View {
|
||||
let link: String
|
||||
let onClose: () -> Void
|
||||
|
||||
@State private var copied = false
|
||||
|
||||
private static let qrContext = CIContext()
|
||||
private static let qrSize: CGFloat = 204
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
HStack(spacing: 10) {
|
||||
Image(systemName: "person.badge.key")
|
||||
.font(.system(size: 14))
|
||||
.foregroundStyle(Palette.accent)
|
||||
Text(NSLocalizedString("blink_login_title", comment: ""))
|
||||
.font(Mono.label(12))
|
||||
.foregroundStyle(Palette.ink)
|
||||
Spacer()
|
||||
Button(action: onClose) {
|
||||
Image(systemName: "xmark")
|
||||
.font(.system(size: 15, weight: .semibold))
|
||||
.foregroundStyle(Palette.ink2)
|
||||
.frame(width: 36, height: 36)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 10, style: .continuous)
|
||||
.fill(Palette.panel2)
|
||||
)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 10, style: .continuous)
|
||||
.stroke(Palette.hair, lineWidth: 1)
|
||||
)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.vertical, 12)
|
||||
|
||||
Rectangle().fill(Palette.hair).frame(height: 1)
|
||||
|
||||
ScrollView {
|
||||
VStack(spacing: 16) {
|
||||
Text(NSLocalizedString("blink_login_subtitle", comment: ""))
|
||||
.font(.system(size: 13))
|
||||
.foregroundStyle(Palette.ink2)
|
||||
.multilineTextAlignment(.center)
|
||||
|
||||
if let qr = qrImage(link) {
|
||||
Image(uiImage: qr)
|
||||
.interpolation(.none)
|
||||
.resizable()
|
||||
.frame(width: Self.qrSize, height: Self.qrSize)
|
||||
.padding(8)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 12, style: .continuous)
|
||||
.fill(Color.white)
|
||||
)
|
||||
}
|
||||
|
||||
Text(link)
|
||||
.font(Mono.label(11))
|
||||
.foregroundStyle(Palette.ink2)
|
||||
.textSelection(.enabled)
|
||||
|
||||
HStack(spacing: 8) {
|
||||
Button {
|
||||
UIPasteboard.general.string = link
|
||||
copied = true
|
||||
} label: {
|
||||
loginButton(icon: "doc.on.doc", title: NSLocalizedString(copied ? "blink_login_copied" : "blink_login_copy", comment: ""))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
|
||||
Button {
|
||||
if let url = URL(string: link) {
|
||||
UIApplication.shared.open(url)
|
||||
}
|
||||
} label: {
|
||||
loginButton(icon: "arrow.up.forward.app", title: NSLocalizedString("blink_login_open", comment: ""))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
.padding(20)
|
||||
}
|
||||
}
|
||||
.background(Palette.surface.ignoresSafeArea())
|
||||
.onChange(of: link) { _ in copied = false }
|
||||
}
|
||||
|
||||
private func loginButton(icon: String, title: String) -> some View {
|
||||
HStack(spacing: 8) {
|
||||
Image(systemName: icon).font(.system(size: 14))
|
||||
Text(title).font(.system(size: 13, weight: .semibold))
|
||||
}
|
||||
.foregroundStyle(Palette.ink)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 11)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 12, style: .continuous)
|
||||
.stroke(Palette.hairStrong, lineWidth: 1)
|
||||
)
|
||||
}
|
||||
|
||||
private func qrImage(_ text: String) -> UIImage? {
|
||||
let filter = CIFilter.qrCodeGenerator()
|
||||
filter.message = Data(text.utf8)
|
||||
guard let output = filter.outputImage,
|
||||
let cgImage = Self.qrContext.createCGImage(output, from: output.extent) else { return nil }
|
||||
return UIImage(cgImage: cgImage)
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,7 @@
|
||||
"suggest_name_wbstream" = "WB Stream";
|
||||
"suggest_name_dion" = "DION";
|
||||
"suggest_name_bitrix" = "Bitrix";
|
||||
"suggest_name_blink" = "Blink";
|
||||
|
||||
"destination_menu_rename" = "Rename";
|
||||
"destination_menu_delete" = "Delete";
|
||||
@@ -149,3 +150,10 @@
|
||||
"status_error" = "Error";
|
||||
"status_captcha" = "Action required (captcha)";
|
||||
"status_solve_captcha" = "Solve the captcha:";
|
||||
"status_blink_login" = "Action required (Blink login)";
|
||||
|
||||
"blink_login_title" = "Log in to Blink";
|
||||
"blink_login_subtitle" = "Scan the QR with the Blink app on another phone, open the link on this phone, or copy it and send it to whoever has Blink.";
|
||||
"blink_login_open" = "Open in Blink";
|
||||
"blink_login_copy" = "Copy link";
|
||||
"blink_login_copied" = "Login link copied";
|
||||
@@ -8,6 +8,7 @@ extension CallPlatform {
|
||||
case .wbstream: return "WB Stream"
|
||||
case .dion: return "DION"
|
||||
case .bitrix: return "Bitrix"
|
||||
case .blink: return "Blink"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +19,7 @@ extension CallPlatform {
|
||||
case .wbstream: return NSLocalizedString("suggest_name_wbstream", comment: "")
|
||||
case .dion: return NSLocalizedString("suggest_name_dion", comment: "")
|
||||
case .bitrix: return NSLocalizedString("suggest_name_bitrix", comment: "")
|
||||
case .blink: return NSLocalizedString("suggest_name_blink", comment: "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,10 @@ enum AppIdentifiers {
|
||||
static var relayLogURL: URL? {
|
||||
FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup)?.appendingPathComponent("relay.log")
|
||||
}
|
||||
|
||||
static var blinkCookiesURL: URL? {
|
||||
FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup)?.appendingPathComponent("cookies-blink.json")
|
||||
}
|
||||
}
|
||||
|
||||
enum VpnConfig {
|
||||
@@ -70,16 +74,19 @@ enum CallPlatform: String {
|
||||
case wbstream
|
||||
case dion
|
||||
case bitrix
|
||||
case blink
|
||||
|
||||
static let wbstreamPrefix = "wbstream://"
|
||||
static let dionPrefix = "dion://"
|
||||
static let dionEventInfix = "dion.vc/event/"
|
||||
static let bitrixMarker = "/video/"
|
||||
static let blinkPrefix = "blink://"
|
||||
|
||||
static func detect(url: String) -> CallPlatform {
|
||||
if url.hasPrefix(dionPrefix) || url.contains(dionEventInfix) { return .dion }
|
||||
if url.hasPrefix(wbstreamPrefix) { return .wbstream }
|
||||
if url.contains("bitrix24") && url.contains(bitrixMarker) { return .bitrix }
|
||||
if url.hasPrefix(blinkPrefix) || (url.contains("blinkmap.com") && url.contains("/join/")) { return .blink }
|
||||
if url.contains("telemost") { return .telemost }
|
||||
return .vk
|
||||
}
|
||||
@@ -108,6 +115,7 @@ enum CallPlatform: String {
|
||||
case .wbstream: return "WB"
|
||||
case .dion: return "DN"
|
||||
case .bitrix: return "BX"
|
||||
case .blink: return "BL"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ final class VPNController: ObservableObject {
|
||||
@Published var logs: [String] = []
|
||||
@Published var lastError: String?
|
||||
@Published var captchaURL: String?
|
||||
@Published var loginLink: String?
|
||||
|
||||
var appState: AppState?
|
||||
|
||||
@@ -55,6 +56,7 @@ final class VPNController: ObservableObject {
|
||||
Log.app.log("connect requested: platform=\(config.platform.rawValue, privacy: .public) room=\(config.roomId, privacy: .public)")
|
||||
lastError = nil
|
||||
captchaURL = nil
|
||||
loginLink = nil
|
||||
relayUp = false
|
||||
connectedSince = nil
|
||||
logs = []
|
||||
@@ -105,6 +107,7 @@ final class VPNController: ObservableObject {
|
||||
refreshStatus()
|
||||
if phase == .disconnected || phase == .failed {
|
||||
captchaURL = nil
|
||||
loginLink = nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +126,7 @@ final class VPNController: ObservableObject {
|
||||
case .disconnected, .invalid:
|
||||
relayUp = false
|
||||
connectedSince = nil
|
||||
loginLink = nil
|
||||
uptimeText = "00:00:00"
|
||||
phase = lastStatus.hasPrefix(GoStatus.error) ? .failed : .disconnected
|
||||
@unknown default:
|
||||
@@ -172,6 +176,7 @@ final class VPNController: ObservableObject {
|
||||
statusDetail = msg.isEmpty ? NSLocalizedString("status_error", comment: "") : msg
|
||||
lastError = statusDetail
|
||||
captchaURL = nil
|
||||
loginLink = nil
|
||||
relayUp = false
|
||||
return
|
||||
}
|
||||
@@ -184,9 +189,21 @@ final class VPNController: ObservableObject {
|
||||
}
|
||||
return
|
||||
}
|
||||
if status.hasPrefix("LOGIN_LINK:") {
|
||||
if phase == .connecting || phase == .connected {
|
||||
loginLink = String(status.dropFirst("LOGIN_LINK:".count))
|
||||
statusDetail = NSLocalizedString("status_blink_login", comment: "")
|
||||
} else {
|
||||
loginLink = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
if captchaURL != nil, status != "CAPTCHA" {
|
||||
captchaURL = nil
|
||||
}
|
||||
if loginLink != nil {
|
||||
loginLink = nil
|
||||
}
|
||||
switch status {
|
||||
case GoStatus.tunnelConnected:
|
||||
if !relayUp {
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
0000000000000000000000B4 /* PacketFlowSink.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0000000000000000000000A4 /* PacketFlowSink.swift */; };
|
||||
0000000000000000000000B5 /* CallRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0000000000000000000000A5 /* CallRow.swift */; };
|
||||
0000000000000000000000B6 /* HeroRing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0000000000000000000000A6 /* HeroRing.swift */; };
|
||||
0000000000000000000000B7 /* BlinkLoginScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0000000000000000000000A7 /* BlinkLoginScreen.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
@@ -110,6 +111,7 @@
|
||||
0000000000000000000000A4 /* PacketFlowSink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PacketFlowSink.swift; sourceTree = "<group>"; };
|
||||
0000000000000000000000A5 /* CallRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallRow.swift; sourceTree = "<group>"; };
|
||||
0000000000000000000000A6 /* HeroRing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeroRing.swift; sourceTree = "<group>"; };
|
||||
0000000000000000000000A7 /* BlinkLoginScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlinkLoginScreen.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -218,6 +220,7 @@
|
||||
000000000000000000000055 /* Sheets.swift */,
|
||||
000000000000000000000056 /* FeatureSheets.swift */,
|
||||
000000000000000000000059 /* CaptchaWebView.swift */,
|
||||
0000000000000000000000A7 /* BlinkLoginScreen.swift */,
|
||||
000000000000000000000052 /* QRScanner.swift */,
|
||||
);
|
||||
path = Components;
|
||||
@@ -355,6 +358,7 @@
|
||||
000000000000000000000077 /* CaptchaWebView.swift in Sources */,
|
||||
0000000000000000000000B5 /* CallRow.swift in Sources */,
|
||||
0000000000000000000000B6 /* HeroRing.swift in Sources */,
|
||||
0000000000000000000000B7 /* BlinkLoginScreen.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user