diff --git a/.BUILDING.md.swp b/.BUILDING.md.swp new file mode 100644 index 000000000..77b24fbc7 Binary files /dev/null and b/.BUILDING.md.swp differ diff --git a/.gitmodules b/.gitmodules index 4a1854f00..1d81d923c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "landing-github-pages"] path = landing-github-pages url = git@github.com:blokadaorg/landing-github-pages.git +[submodule "translate"] + path = translate + url = git@github.com:blokadaorg/translate.git diff --git a/common/BUILDING.md b/BUILDING.md similarity index 100% rename from common/BUILDING.md rename to BUILDING.md diff --git a/common/CONTRIBUTING.md b/CONTRIBUTING.md similarity index 100% rename from common/CONTRIBUTING.md rename to CONTRIBUTING.md diff --git a/common/LICENSE b/LICENSE similarity index 100% rename from common/LICENSE rename to LICENSE diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..8516d8454 --- /dev/null +++ b/Makefile @@ -0,0 +1,75 @@ +all: sixcommon wireguard aab + +common-android: + @cd six-common; \ + make common-android; \ + cd ../ + +sixcommon: + @if test -d "six-common"; then \ + if test ! -d "app/six-common" || test "six-common" -nt "app/six-common/marker"; then \ + echo "Building six-common..."; \ + cd six-common && make get gen && cd ../ ; \ + cd six-common && flutter build aar --no-profile && cd ../ ; \ + mkdir -p app/six-common; \ + cp -r six-common/build/host/outputs/repo app/six-common; \ + touch app/six-common/marker; \ + fi \ + fi + +sixcommon-fvm: + @if test -d "six-common"; then \ + if test ! -d "app/six-common" || test "six-common" -nt "app/six-common/marker"; then \ + echo "Building six-common..."; \ + cd six-common && make get gen && cd ../ ; \ + cd six-common && fvm flutter build aar --no-profile && cd ../ ; \ + mkdir -p app/six-common; \ + cp -r six-common/build/host/outputs/repo app/six-common; \ + touch app/six-common/marker; \ + fi \ + fi + +wireguard: + @if test -d "wireguard-android"; then \ + if test ! -d "app/wireguard-android/lib" || test "wireguard-android" -nt "app/wireguard-android/lib/marker"; then \ + echo "Building wireguard-android..."; \ + cd wireguard-android && ./gradlew tunnel:build && cd ../ ; \ + mkdir -p app/wireguard-android/lib; \ + cp wireguard-android/tunnel/build/outputs/aar/tunnel-release.aar app/wireguard-android/lib/wg-tunnel.aar; \ + touch app/wireguard-android/lib/marker; \ + fi \ + fi + +pull-sixcommon: + @cd six-common; \ + git pull; \ + cd ../ + +devsc: pull-sixcommon clean-sixcommon sixcommon +devsc-fvm: pull-sixcommon clean-sixcommon sixcommon-fvm + +apk: + ./gradlew assembleSixRelease; + +aab: + ./gradlew bundleSixRelease; + +aabfamily: + ./gradlew bundleFamilyRelease; + +clean: + @rm -rf app/six-common; \ + rm -rf app/wireguard-android/lib; \ + ./gradlew clean; \ + cd six-common && flutter clean; \ + cd ..; \ + cd wireguard-android && ./gradlew clean; \ + +clean-sixcommon: + @rm -rf app/six-common; \ + +install: + ./gradlew installSixRelease + +test: + ./gradlew testSixRelease diff --git a/common/.fvmrc b/common/.fvmrc index 4efffa7b1..ff263c64c 100644 --- a/common/.fvmrc +++ b/common/.fvmrc @@ -1,3 +1,3 @@ { - "flutter": "3.22.1" + "flutter": "3.24.4" } \ No newline at end of file diff --git a/common/Makefile b/common/Makefile index 0f6dbd153..5d071c64c 100644 --- a/common/Makefile +++ b/common/Makefile @@ -1,24 +1,62 @@ -.PHONY: build get gen web android ios test clean +# Define common variables +FLUTTER := flutter +PIGEON := ./scripts/pigeon.py +DART := dart +OUTPUT_DIR := build/ -build: get gen web +# Default target +.DEFAULT_GOAL := build-ci -web: - flutter build web +.PHONY: test clean get-deps gen-pigeon-android gen-pigeon-ios gen-build-runner \ + lib-android-debug lib-ios-debug lib-android-release lib-ios-release \ + build-android-lib build-ios-lib build-ci build-web -android: - flutter build aar --no-profile --no-debug +test: + $(FLUTTER) test -ios: - flutter build ios-framework --no-profile --no-debug +clean: + $(FLUTTER) clean -get: - flutter pub get -gen: - ./sync-generated-files.sh +# Dependency installation +get-deps: + $(FLUTTER) pub get -test: - flutter test +# Code generation +gen-pigeon-android: + $(PIGEON) --android --output=$(OUTPUT_DIR) --cmd=$(DART) -clean: - flutter clean +gen-pigeon-ios: + $(PIGEON) --output=$(OUTPUT_DIR) --cmd=$(DART) + +gen-build-runner: + $(DART) run build_runner build --delete-conflicting-outputs + + +# Android and iOS builds +lib-android-debug: + $(FLUTTER) build aar --no-profile --no-release + +lib-ios-debug: + $(FLUTTER) build ios-framework --no-profile --no-release + +lib-android-release: + $(FLUTTER) build aar --no-profile --no-debug + +lib-ios-release: + $(FLUTTER) build ios-framework --no-profile --no-debug + + +# Build Android and iOS library with dependencies +build-android-lib: get-deps gen-build-runner gen-pigeon-android lib-android-release + +build-ios-lib: get-deps gen-build-runner gen-pigeon-ios lib-ios-release + +# Build everything in CI +build-ci: get-deps gen-build-runner test gen-pigeon-android lib-android-release \ + gen-pigeon-ios lib-ios-release + + +# Web build (not used yet) +build-web: + $(FLUTTER) build web diff --git a/common/ios/App.swift b/common/ios/App.swift new file mode 100644 index 000000000..451591d4d --- /dev/null +++ b/common/ios/App.swift @@ -0,0 +1,80 @@ +// Autogenerated from Pigeon (v12.0.1), do not edit directly. +// See also: https://pub.dev/packages/pigeon + +import Foundation +#if os(iOS) +import Flutter +#elseif os(macOS) +import FlutterMacOS +#else +#error("Unsupported platform.") +#endif + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + +private func wrapResult(_ result: Any?) -> [Any?] { + return [result] +} + +private func wrapError(_ error: Any) -> [Any?] { + if let flutterError = error as? FlutterError { + return [ + flutterError.code, + flutterError.message, + flutterError.details + ] + } + return [ + "\(error)", + "\(type(of: error))", + "Stacktrace: \(Thread.callStackSymbols)" + ] +} + +private func nilOrValue(_ value: Any?) -> T? { + if value is NSNull { return nil } + return value as! T? +} + +enum AppStatus: Int { + case unknown = 0 + case initializing = 1 + case initFail = 2 + case reconfiguring = 3 + case deactivated = 4 + case paused = 5 + case activatedCloud = 6 + case activatedPlus = 7 +} + +/// Generated protocol from Pigeon that represents a handler of messages from Flutter. +protocol AppOps { + func doAppStatusChanged(status: AppStatus, completion: @escaping (Result) -> Void) +} + +/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. +class AppOpsSetup { + /// The codec used by AppOps. + /// Sets up an instance of `AppOps` to handle messages through the `binaryMessenger`. + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: AppOps?) { + let doAppStatusChangedChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.AppOps.doAppStatusChanged", binaryMessenger: binaryMessenger) + if let api = api { + doAppStatusChangedChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let statusArg = AppStatus(rawValue: args[0] as! Int)! + api.doAppStatusChanged(status: statusArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doAppStatusChangedChannel.setMessageHandler(nil) + } + } +} diff --git a/common/ios/Command.swift b/common/ios/Command.swift new file mode 100644 index 000000000..774aef1bd --- /dev/null +++ b/common/ios/Command.swift @@ -0,0 +1,131 @@ +// Autogenerated from Pigeon (v12.0.1), do not edit directly. +// See also: https://pub.dev/packages/pigeon + +import Foundation +#if os(iOS) +import Flutter +#elseif os(macOS) +import FlutterMacOS +#else +#error("Unsupported platform.") +#endif + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + +private func wrapResult(_ result: Any?) -> [Any?] { + return [result] +} + +private func wrapError(_ error: Any) -> [Any?] { + if let flutterError = error as? FlutterError { + return [ + flutterError.code, + flutterError.message, + flutterError.details + ] + } + return [ + "\(error)", + "\(type(of: error))", + "Stacktrace: \(Thread.callStackSymbols)" + ] +} + +private func nilOrValue(_ value: Any?) -> T? { + if value is NSNull { return nil } + return value as! T? +} + +enum CommandName: Int { + case url = 0 + case restore = 1 + case account = 2 + case receipt = 3 + case fetchProducts = 4 + case purchase = 5 + case changeProduct = 6 + case restorePayment = 7 + case pause = 8 + case unpause = 9 + case remoteNotification = 10 + case foreground = 11 + case background = 12 + case route = 13 + case modalShow = 14 + case modalShown = 15 + case modalDismiss = 16 + case modalDismissed = 17 + case back = 18 + case fatal = 19 + case warning = 20 + case log = 21 + case crashLog = 22 + case familyLink = 23 + case supportNotify = 24 + case supportAskNotificationPerms = 25 + case schedulerPing = 26 + case newPlus = 27 + case vpnStatus = 28 + case notificationTapped = 29 + case appleNotificationToken = 30 +} + +/// Generated protocol from Pigeon that represents a handler of messages from Flutter. +protocol CommandOps { + func doCanAcceptCommands(completion: @escaping (Result) -> Void) +} + +/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. +class CommandOpsSetup { + /// The codec used by CommandOps. + /// Sets up an instance of `CommandOps` to handle messages through the `binaryMessenger`. + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: CommandOps?) { + let doCanAcceptCommandsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.CommandOps.doCanAcceptCommands", binaryMessenger: binaryMessenger) + if let api = api { + doCanAcceptCommandsChannel.setMessageHandler { _, reply in + api.doCanAcceptCommands() { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doCanAcceptCommandsChannel.setMessageHandler(nil) + } + } +} +/// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift. +protocol CommandEventsProtocol { + func onCommand(command commandArg: String, m mArg: Int64, completion: @escaping (Result) -> Void) + func onCommandWithParam(command commandArg: String, p1 p1Arg: String, m mArg: Int64, completion: @escaping (Result) -> Void) + func onCommandWithParams(command commandArg: String, p1 p1Arg: String, p2 p2Arg: String, m mArg: Int64, completion: @escaping (Result) -> Void) +} +class CommandEvents: CommandEventsProtocol { + private let binaryMessenger: FlutterBinaryMessenger + init(binaryMessenger: FlutterBinaryMessenger){ + self.binaryMessenger = binaryMessenger + } + func onCommand(command commandArg: String, m mArg: Int64, completion: @escaping (Result) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.CommandEvents.onCommand", binaryMessenger: binaryMessenger) + channel.sendMessage([commandArg, mArg] as [Any?]) { _ in + completion(.success(Void())) + } + } + func onCommandWithParam(command commandArg: String, p1 p1Arg: String, m mArg: Int64, completion: @escaping (Result) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.CommandEvents.onCommandWithParam", binaryMessenger: binaryMessenger) + channel.sendMessage([commandArg, p1Arg, mArg] as [Any?]) { _ in + completion(.success(Void())) + } + } + func onCommandWithParams(command commandArg: String, p1 p1Arg: String, p2 p2Arg: String, m mArg: Int64, completion: @escaping (Result) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.CommandEvents.onCommandWithParams", binaryMessenger: binaryMessenger) + channel.sendMessage([commandArg, p1Arg, p2Arg, mArg] as [Any?]) { _ in + completion(.success(Void())) + } + } +} diff --git a/common/ios/Common.swift b/common/ios/Common.swift new file mode 100644 index 000000000..675e0e6bc --- /dev/null +++ b/common/ios/Common.swift @@ -0,0 +1,306 @@ +// Autogenerated from Pigeon (v12.0.1), do not edit directly. +// See also: https://pub.dev/packages/pigeon + +import Foundation +#if os(iOS) +import Flutter +#elseif os(macOS) +import FlutterMacOS +#else +#error("Unsupported platform.") +#endif + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + +private func wrapResult(_ result: Any?) -> [Any?] { + return [result] +} + +private func wrapError(_ error: Any) -> [Any?] { + if let flutterError = error as? FlutterError { + return [ + flutterError.code, + flutterError.message, + flutterError.details + ] + } + return [ + "\(error)", + "\(type(of: error))", + "Stacktrace: \(Thread.callStackSymbols)" + ] +} + +private func nilOrValue(_ value: Any?) -> T? { + if value is NSNull { return nil } + return value as! T? +} + +/// Generated class from Pigeon that represents data sent in messages. +struct OpsEnvInfo { + var appVersion: String + var osVersion: String + var buildFlavor: String + var buildType: String + var cpu: String + var deviceBrand: String + var deviceModel: String + var deviceName: String + + static func fromList(_ list: [Any?]) -> OpsEnvInfo? { + let appVersion = list[0] as! String + let osVersion = list[1] as! String + let buildFlavor = list[2] as! String + let buildType = list[3] as! String + let cpu = list[4] as! String + let deviceBrand = list[5] as! String + let deviceModel = list[6] as! String + let deviceName = list[7] as! String + + return OpsEnvInfo( + appVersion: appVersion, + osVersion: osVersion, + buildFlavor: buildFlavor, + buildType: buildType, + cpu: cpu, + deviceBrand: deviceBrand, + deviceModel: deviceModel, + deviceName: deviceName + ) + } + func toList() -> [Any?] { + return [ + appVersion, + osVersion, + buildFlavor, + buildType, + cpu, + deviceBrand, + deviceModel, + deviceName, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct OpsLink { + var id: String + var url: String + + static func fromList(_ list: [Any?]) -> OpsLink? { + let id = list[0] as! String + let url = list[1] as! String + + return OpsLink( + id: id, + url: url + ) + } + func toList() -> [Any?] { + return [ + id, + url, + ] + } +} + +private class CommonOpsCodecReader: FlutterStandardReader { + override func readValue(ofType type: UInt8) -> Any? { + switch type { + case 128: + return OpsEnvInfo.fromList(self.readValue() as! [Any?]) + case 129: + return OpsLink.fromList(self.readValue() as! [Any?]) + default: + return super.readValue(ofType: type) + } + } +} + +private class CommonOpsCodecWriter: FlutterStandardWriter { + override func writeValue(_ value: Any) { + if let value = value as? OpsEnvInfo { + super.writeByte(128) + super.writeValue(value.toList()) + } else if let value = value as? OpsLink { + super.writeByte(129) + super.writeValue(value.toList()) + } else { + super.writeValue(value) + } + } +} + +private class CommonOpsCodecReaderWriter: FlutterStandardReaderWriter { + override func reader(with data: Data) -> FlutterStandardReader { + return CommonOpsCodecReader(data: data) + } + + override func writer(with data: NSMutableData) -> FlutterStandardWriter { + return CommonOpsCodecWriter(data: data) + } +} + +class CommonOpsCodec: FlutterStandardMessageCodec { + static let shared = CommonOpsCodec(readerWriter: CommonOpsCodecReaderWriter()) +} + +/// Generated protocol from Pigeon that represents a handler of messages from Flutter. +protocol CommonOps { + func doGet(url: String, completion: @escaping (Result) -> Void) + func doRequest(url: String, payload: String?, type: String, completion: @escaping (Result) -> Void) + func doRequestWithHeaders(url: String, payload: String?, type: String, headers: [String?: String?], completion: @escaping (Result) -> Void) + func doGetEnvInfo(completion: @escaping (Result) -> Void) + func doShowRateDialog(completion: @escaping (Result) -> Void) + func doLinksChanged(links: [OpsLink], completion: @escaping (Result) -> Void) + func doShow(notificationId: String, atWhen: String, body: String?, completion: @escaping (Result) -> Void) + func doDismissAll(completion: @escaping (Result) -> Void) +} + +/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. +class CommonOpsSetup { + /// The codec used by CommonOps. + static var codec: FlutterStandardMessageCodec { CommonOpsCodec.shared } + /// Sets up an instance of `CommonOps` to handle messages through the `binaryMessenger`. + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: CommonOps?) { + let doGetChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.CommonOps.doGet", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doGetChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let urlArg = args[0] as! String + api.doGet(url: urlArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doGetChannel.setMessageHandler(nil) + } + let doRequestChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.CommonOps.doRequest", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doRequestChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let urlArg = args[0] as! String + let payloadArg: String? = nilOrValue(args[1]) + let typeArg = args[2] as! String + api.doRequest(url: urlArg, payload: payloadArg, type: typeArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doRequestChannel.setMessageHandler(nil) + } + let doRequestWithHeadersChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.CommonOps.doRequestWithHeaders", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doRequestWithHeadersChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let urlArg = args[0] as! String + let payloadArg: String? = nilOrValue(args[1]) + let typeArg = args[2] as! String + let headersArg = args[3] as! [String?: String?] + api.doRequestWithHeaders(url: urlArg, payload: payloadArg, type: typeArg, headers: headersArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doRequestWithHeadersChannel.setMessageHandler(nil) + } + let doGetEnvInfoChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.CommonOps.doGetEnvInfo", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doGetEnvInfoChannel.setMessageHandler { _, reply in + api.doGetEnvInfo() { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doGetEnvInfoChannel.setMessageHandler(nil) + } + let doShowRateDialogChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.CommonOps.doShowRateDialog", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doShowRateDialogChannel.setMessageHandler { _, reply in + api.doShowRateDialog() { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doShowRateDialogChannel.setMessageHandler(nil) + } + let doLinksChangedChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.CommonOps.doLinksChanged", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doLinksChangedChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let linksArg = args[0] as! [OpsLink] + api.doLinksChanged(links: linksArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doLinksChangedChannel.setMessageHandler(nil) + } + let doShowChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.CommonOps.doShow", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doShowChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let notificationIdArg = args[0] as! String + let atWhenArg = args[1] as! String + let bodyArg: String? = nilOrValue(args[2]) + api.doShow(notificationId: notificationIdArg, atWhen: atWhenArg, body: bodyArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doShowChannel.setMessageHandler(nil) + } + let doDismissAllChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.CommonOps.doDismissAll", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doDismissAllChannel.setMessageHandler { _, reply in + api.doDismissAll() { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doDismissAllChannel.setMessageHandler(nil) + } + } +} diff --git a/common/ios/Core.swift b/common/ios/Core.swift new file mode 100644 index 000000000..bb4f46d78 --- /dev/null +++ b/common/ios/Core.swift @@ -0,0 +1,166 @@ +// Autogenerated from Pigeon (v12.0.1), do not edit directly. +// See also: https://pub.dev/packages/pigeon + +import Foundation +#if os(iOS) +import Flutter +#elseif os(macOS) +import FlutterMacOS +#else +#error("Unsupported platform.") +#endif + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + +private func wrapResult(_ result: Any?) -> [Any?] { + return [result] +} + +private func wrapError(_ error: Any) -> [Any?] { + if let flutterError = error as? FlutterError { + return [ + flutterError.code, + flutterError.message, + flutterError.details + ] + } + return [ + "\(error)", + "\(type(of: error))", + "Stacktrace: \(Thread.callStackSymbols)" + ] +} + +private func nilOrValue(_ value: Any?) -> T? { + if value is NSNull { return nil } + return value as! T? +} + +/// Used by Pigeon to generate the bindings to the platform code. +/// +/// Generated protocol from Pigeon that represents a handler of messages from Flutter. +protocol CoreOps { + func doSave(key: String, value: String, isSecure: Bool, isBackup: Bool, completion: @escaping (Result) -> Void) + func doLoad(key: String, isSecure: Bool, isBackup: Bool, completion: @escaping (Result) -> Void) + func doDelete(key: String, isSecure: Bool, isBackup: Bool, completion: @escaping (Result) -> Void) + func doUseFilename(filename: String, completion: @escaping (Result) -> Void) + func doSaveBatch(batch: String, completion: @escaping (Result) -> Void) + func doShareFile(completion: @escaping (Result) -> Void) +} + +/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. +class CoreOpsSetup { + /// The codec used by CoreOps. + /// Sets up an instance of `CoreOps` to handle messages through the `binaryMessenger`. + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: CoreOps?) { + let doSaveChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.CoreOps.doSave", binaryMessenger: binaryMessenger) + if let api = api { + doSaveChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let keyArg = args[0] as! String + let valueArg = args[1] as! String + let isSecureArg = args[2] as! Bool + let isBackupArg = args[3] as! Bool + api.doSave(key: keyArg, value: valueArg, isSecure: isSecureArg, isBackup: isBackupArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doSaveChannel.setMessageHandler(nil) + } + let doLoadChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.CoreOps.doLoad", binaryMessenger: binaryMessenger) + if let api = api { + doLoadChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let keyArg = args[0] as! String + let isSecureArg = args[1] as! Bool + let isBackupArg = args[2] as! Bool + api.doLoad(key: keyArg, isSecure: isSecureArg, isBackup: isBackupArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doLoadChannel.setMessageHandler(nil) + } + let doDeleteChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.CoreOps.doDelete", binaryMessenger: binaryMessenger) + if let api = api { + doDeleteChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let keyArg = args[0] as! String + let isSecureArg = args[1] as! Bool + let isBackupArg = args[2] as! Bool + api.doDelete(key: keyArg, isSecure: isSecureArg, isBackup: isBackupArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doDeleteChannel.setMessageHandler(nil) + } + let doUseFilenameChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.CoreOps.doUseFilename", binaryMessenger: binaryMessenger) + if let api = api { + doUseFilenameChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let filenameArg = args[0] as! String + api.doUseFilename(filename: filenameArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doUseFilenameChannel.setMessageHandler(nil) + } + let doSaveBatchChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.CoreOps.doSaveBatch", binaryMessenger: binaryMessenger) + if let api = api { + doSaveBatchChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let batchArg = args[0] as! String + api.doSaveBatch(batch: batchArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doSaveBatchChannel.setMessageHandler(nil) + } + let doShareFileChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.CoreOps.doShareFile", binaryMessenger: binaryMessenger) + if let api = api { + doShareFileChannel.setMessageHandler { _, reply in + api.doShareFile() { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doShareFileChannel.setMessageHandler(nil) + } + } +} diff --git a/common/ios/Family.swift b/common/ios/Family.swift new file mode 100644 index 000000000..7e5ea20f7 --- /dev/null +++ b/common/ios/Family.swift @@ -0,0 +1,69 @@ +// Autogenerated from Pigeon (v12.0.1), do not edit directly. +// See also: https://pub.dev/packages/pigeon + +import Foundation +#if os(iOS) +import Flutter +#elseif os(macOS) +import FlutterMacOS +#else +#error("Unsupported platform.") +#endif + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + +private func wrapResult(_ result: Any?) -> [Any?] { + return [result] +} + +private func wrapError(_ error: Any) -> [Any?] { + if let flutterError = error as? FlutterError { + return [ + flutterError.code, + flutterError.message, + flutterError.details + ] + } + return [ + "\(error)", + "\(type(of: error))", + "Stacktrace: \(Thread.callStackSymbols)" + ] +} + +private func nilOrValue(_ value: Any?) -> T? { + if value is NSNull { return nil } + return value as! T? +} + +/// Generated protocol from Pigeon that represents a handler of messages from Flutter. +protocol FamilyOps { + func doShareUrl(url: String, completion: @escaping (Result) -> Void) +} + +/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. +class FamilyOpsSetup { + /// The codec used by FamilyOps. + /// Sets up an instance of `FamilyOps` to handle messages through the `binaryMessenger`. + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: FamilyOps?) { + let doShareUrlChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.FamilyOps.doShareUrl", binaryMessenger: binaryMessenger) + if let api = api { + doShareUrlChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let urlArg = args[0] as! String + api.doShareUrl(url: urlArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doShareUrlChannel.setMessageHandler(nil) + } + } +} diff --git a/common/ios/Payment.swift b/common/ios/Payment.swift new file mode 100644 index 000000000..7084d1a4d --- /dev/null +++ b/common/ios/Payment.swift @@ -0,0 +1,301 @@ +// Autogenerated from Pigeon (v12.0.1), do not edit directly. +// See also: https://pub.dev/packages/pigeon + +import Foundation +#if os(iOS) +import Flutter +#elseif os(macOS) +import FlutterMacOS +#else +#error("Unsupported platform.") +#endif + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + +private func wrapResult(_ result: Any?) -> [Any?] { + return [result] +} + +private func wrapError(_ error: Any) -> [Any?] { + if let flutterError = error as? FlutterError { + return [ + flutterError.code, + flutterError.message, + flutterError.details + ] + } + return [ + "\(error)", + "\(type(of: error))", + "Stacktrace: \(Thread.callStackSymbols)" + ] +} + +private func nilOrValue(_ value: Any?) -> T? { + if value is NSNull { return nil } + return value as! T? +} + +enum PaymentStatus: Int { + case unknown = 0 + case fetching = 1 + case ready = 2 + case purchasing = 3 + case restoring = 4 + case fatal = 5 +} + +/// Generated class from Pigeon that represents data sent in messages. +struct Product { + var id: String + var title: String + var description: String + var price: String + var pricePerMonth: String + var periodMonths: Int64 + var type: String + var trial: Int64? = nil + var owned: Bool + + static func fromList(_ list: [Any?]) -> Product? { + let id = list[0] as! String + let title = list[1] as! String + let description = list[2] as! String + let price = list[3] as! String + let pricePerMonth = list[4] as! String + let periodMonths = list[5] is Int64 ? list[5] as! Int64 : Int64(list[5] as! Int32) + let type = list[6] as! String + let trial: Int64? = isNullish(list[7]) ? nil : (list[7] is Int64? ? list[7] as! Int64? : Int64(list[7] as! Int32)) + let owned = list[8] as! Bool + + return Product( + id: id, + title: title, + description: description, + price: price, + pricePerMonth: pricePerMonth, + periodMonths: periodMonths, + type: type, + trial: trial, + owned: owned + ) + } + func toList() -> [Any?] { + return [ + id, + title, + description, + price, + pricePerMonth, + periodMonths, + type, + trial, + owned, + ] + } +} + +private class PaymentOpsCodecReader: FlutterStandardReader { + override func readValue(ofType type: UInt8) -> Any? { + switch type { + case 128: + return Product.fromList(self.readValue() as! [Any?]) + default: + return super.readValue(ofType: type) + } + } +} + +private class PaymentOpsCodecWriter: FlutterStandardWriter { + override func writeValue(_ value: Any) { + if let value = value as? Product { + super.writeByte(128) + super.writeValue(value.toList()) + } else { + super.writeValue(value) + } + } +} + +private class PaymentOpsCodecReaderWriter: FlutterStandardReaderWriter { + override func reader(with data: Data) -> FlutterStandardReader { + return PaymentOpsCodecReader(data: data) + } + + override func writer(with data: NSMutableData) -> FlutterStandardWriter { + return PaymentOpsCodecWriter(data: data) + } +} + +class PaymentOpsCodec: FlutterStandardMessageCodec { + static let shared = PaymentOpsCodec(readerWriter: PaymentOpsCodecReaderWriter()) +} + +/// Generated protocol from Pigeon that represents a handler of messages from Flutter. +protocol PaymentOps { + func doArePaymentsAvailable(completion: @escaping (Result) -> Void) + func doFetchProducts(completion: @escaping (Result<[Product], Error>) -> Void) + func doPurchaseWithReceipts(productId: String, completion: @escaping (Result<[String], Error>) -> Void) + func doRestoreWithReceipts(completion: @escaping (Result<[String], Error>) -> Void) + func doChangeProductWithReceipt(productId: String, completion: @escaping (Result) -> Void) + func doFinishOngoingTransaction(completion: @escaping (Result) -> Void) + func doPaymentStatusChanged(status: PaymentStatus, completion: @escaping (Result) -> Void) + func doProductsChanged(products: [Product], completion: @escaping (Result) -> Void) + func doAccountTypeChanged(accountType: String, completion: @escaping (Result) -> Void) +} + +/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. +class PaymentOpsSetup { + /// The codec used by PaymentOps. + static var codec: FlutterStandardMessageCodec { PaymentOpsCodec.shared } + /// Sets up an instance of `PaymentOps` to handle messages through the `binaryMessenger`. + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: PaymentOps?) { + let doArePaymentsAvailableChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PaymentOps.doArePaymentsAvailable", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doArePaymentsAvailableChannel.setMessageHandler { _, reply in + api.doArePaymentsAvailable() { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doArePaymentsAvailableChannel.setMessageHandler(nil) + } + let doFetchProductsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PaymentOps.doFetchProducts", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doFetchProductsChannel.setMessageHandler { _, reply in + api.doFetchProducts() { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doFetchProductsChannel.setMessageHandler(nil) + } + let doPurchaseWithReceiptsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PaymentOps.doPurchaseWithReceipts", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doPurchaseWithReceiptsChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let productIdArg = args[0] as! String + api.doPurchaseWithReceipts(productId: productIdArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doPurchaseWithReceiptsChannel.setMessageHandler(nil) + } + let doRestoreWithReceiptsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PaymentOps.doRestoreWithReceipts", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doRestoreWithReceiptsChannel.setMessageHandler { _, reply in + api.doRestoreWithReceipts() { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doRestoreWithReceiptsChannel.setMessageHandler(nil) + } + let doChangeProductWithReceiptChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PaymentOps.doChangeProductWithReceipt", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doChangeProductWithReceiptChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let productIdArg = args[0] as! String + api.doChangeProductWithReceipt(productId: productIdArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doChangeProductWithReceiptChannel.setMessageHandler(nil) + } + let doFinishOngoingTransactionChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PaymentOps.doFinishOngoingTransaction", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doFinishOngoingTransactionChannel.setMessageHandler { _, reply in + api.doFinishOngoingTransaction() { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doFinishOngoingTransactionChannel.setMessageHandler(nil) + } + let doPaymentStatusChangedChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PaymentOps.doPaymentStatusChanged", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doPaymentStatusChangedChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let statusArg = PaymentStatus(rawValue: args[0] as! Int)! + api.doPaymentStatusChanged(status: statusArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doPaymentStatusChangedChannel.setMessageHandler(nil) + } + let doProductsChangedChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PaymentOps.doProductsChanged", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doProductsChangedChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let productsArg = args[0] as! [Product] + api.doProductsChanged(products: productsArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doProductsChangedChannel.setMessageHandler(nil) + } + let doAccountTypeChangedChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PaymentOps.doAccountTypeChanged", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doAccountTypeChangedChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let accountTypeArg = args[0] as! String + api.doAccountTypeChanged(accountType: accountTypeArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doAccountTypeChangedChannel.setMessageHandler(nil) + } + } +} diff --git a/common/ios/Perm.swift b/common/ios/Perm.swift new file mode 100644 index 000000000..22e9dbc71 --- /dev/null +++ b/common/ios/Perm.swift @@ -0,0 +1,200 @@ +// Autogenerated from Pigeon (v12.0.1), do not edit directly. +// See also: https://pub.dev/packages/pigeon + +import Foundation +#if os(iOS) +import Flutter +#elseif os(macOS) +import FlutterMacOS +#else +#error("Unsupported platform.") +#endif + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + +private func wrapResult(_ result: Any?) -> [Any?] { + return [result] +} + +private func wrapError(_ error: Any) -> [Any?] { + if let flutterError = error as? FlutterError { + return [ + flutterError.code, + flutterError.message, + flutterError.details + ] + } + return [ + "\(error)", + "\(type(of: error))", + "Stacktrace: \(Thread.callStackSymbols)" + ] +} + +private func nilOrValue(_ value: Any?) -> T? { + if value is NSNull { return nil } + return value as! T? +} + +/// Generated protocol from Pigeon that represents a handler of messages from Flutter. +protocol PermOps { + func getPrivateDnsSetting(completion: @escaping (Result) -> Void) + func doSetPrivateDnsEnabled(tag: String, alias: String, completion: @escaping (Result) -> Void) + func doSetDns(tag: String, completion: @escaping (Result) -> Void) + func doNotificationEnabled(completion: @escaping (Result) -> Void) + func doVpnEnabled(completion: @escaping (Result) -> Void) + func doOpenSettings(completion: @escaping (Result) -> Void) + func doAskNotificationPerms(completion: @escaping (Result) -> Void) + func doAskVpnPerms(completion: @escaping (Result) -> Void) + func doAuthenticate(completion: @escaping (Result) -> Void) +} + +/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. +class PermOpsSetup { + /// The codec used by PermOps. + /// Sets up an instance of `PermOps` to handle messages through the `binaryMessenger`. + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: PermOps?) { + let getPrivateDnsSettingChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PermOps.getPrivateDnsSetting", binaryMessenger: binaryMessenger) + if let api = api { + getPrivateDnsSettingChannel.setMessageHandler { _, reply in + api.getPrivateDnsSetting() { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + getPrivateDnsSettingChannel.setMessageHandler(nil) + } + let doSetPrivateDnsEnabledChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PermOps.doSetPrivateDnsEnabled", binaryMessenger: binaryMessenger) + if let api = api { + doSetPrivateDnsEnabledChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let tagArg = args[0] as! String + let aliasArg = args[1] as! String + api.doSetPrivateDnsEnabled(tag: tagArg, alias: aliasArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doSetPrivateDnsEnabledChannel.setMessageHandler(nil) + } + let doSetDnsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PermOps.doSetDns", binaryMessenger: binaryMessenger) + if let api = api { + doSetDnsChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let tagArg = args[0] as! String + api.doSetDns(tag: tagArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doSetDnsChannel.setMessageHandler(nil) + } + let doNotificationEnabledChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PermOps.doNotificationEnabled", binaryMessenger: binaryMessenger) + if let api = api { + doNotificationEnabledChannel.setMessageHandler { _, reply in + api.doNotificationEnabled() { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doNotificationEnabledChannel.setMessageHandler(nil) + } + let doVpnEnabledChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PermOps.doVpnEnabled", binaryMessenger: binaryMessenger) + if let api = api { + doVpnEnabledChannel.setMessageHandler { _, reply in + api.doVpnEnabled() { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doVpnEnabledChannel.setMessageHandler(nil) + } + let doOpenSettingsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PermOps.doOpenSettings", binaryMessenger: binaryMessenger) + if let api = api { + doOpenSettingsChannel.setMessageHandler { _, reply in + api.doOpenSettings() { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doOpenSettingsChannel.setMessageHandler(nil) + } + let doAskNotificationPermsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PermOps.doAskNotificationPerms", binaryMessenger: binaryMessenger) + if let api = api { + doAskNotificationPermsChannel.setMessageHandler { _, reply in + api.doAskNotificationPerms() { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doAskNotificationPermsChannel.setMessageHandler(nil) + } + let doAskVpnPermsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PermOps.doAskVpnPerms", binaryMessenger: binaryMessenger) + if let api = api { + doAskVpnPermsChannel.setMessageHandler { _, reply in + api.doAskVpnPerms() { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doAskVpnPermsChannel.setMessageHandler(nil) + } + let doAuthenticateChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PermOps.doAuthenticate", binaryMessenger: binaryMessenger) + if let api = api { + doAuthenticateChannel.setMessageHandler { _, reply in + api.doAuthenticate() { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doAuthenticateChannel.setMessageHandler(nil) + } + } +} diff --git a/common/ios/Plus.swift b/common/ios/Plus.swift new file mode 100644 index 000000000..1142ba7cd --- /dev/null +++ b/common/ios/Plus.swift @@ -0,0 +1,426 @@ +// Autogenerated from Pigeon (v12.0.1), do not edit directly. +// See also: https://pub.dev/packages/pigeon + +import Foundation +#if os(iOS) +import Flutter +#elseif os(macOS) +import FlutterMacOS +#else +#error("Unsupported platform.") +#endif + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + +private func wrapResult(_ result: Any?) -> [Any?] { + return [result] +} + +private func wrapError(_ error: Any) -> [Any?] { + if let flutterError = error as? FlutterError { + return [ + flutterError.code, + flutterError.message, + flutterError.details + ] + } + return [ + "\(error)", + "\(type(of: error))", + "Stacktrace: \(Thread.callStackSymbols)" + ] +} + +private func nilOrValue(_ value: Any?) -> T? { + if value is NSNull { return nil } + return value as! T? +} + +/// Generated class from Pigeon that represents data sent in messages. +struct OpsGateway { + var publicKey: String + var region: String + var location: String + var resourceUsagePercent: Int64 + var ipv4: String + var ipv6: String + var port: Int64 + var country: String? = nil + + static func fromList(_ list: [Any?]) -> OpsGateway? { + let publicKey = list[0] as! String + let region = list[1] as! String + let location = list[2] as! String + let resourceUsagePercent = list[3] is Int64 ? list[3] as! Int64 : Int64(list[3] as! Int32) + let ipv4 = list[4] as! String + let ipv6 = list[5] as! String + let port = list[6] is Int64 ? list[6] as! Int64 : Int64(list[6] as! Int32) + let country: String? = nilOrValue(list[7]) + + return OpsGateway( + publicKey: publicKey, + region: region, + location: location, + resourceUsagePercent: resourceUsagePercent, + ipv4: ipv4, + ipv6: ipv6, + port: port, + country: country + ) + } + func toList() -> [Any?] { + return [ + publicKey, + region, + location, + resourceUsagePercent, + ipv4, + ipv6, + port, + country, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct OpsKeypair { + var publicKey: String + var privateKey: String + + static func fromList(_ list: [Any?]) -> OpsKeypair? { + let publicKey = list[0] as! String + let privateKey = list[1] as! String + + return OpsKeypair( + publicKey: publicKey, + privateKey: privateKey + ) + } + func toList() -> [Any?] { + return [ + publicKey, + privateKey, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct OpsLease { + var accountId: String + var publicKey: String + var gatewayId: String + var expires: String + var alias: String? = nil + var vip4: String + var vip6: String + + static func fromList(_ list: [Any?]) -> OpsLease? { + let accountId = list[0] as! String + let publicKey = list[1] as! String + let gatewayId = list[2] as! String + let expires = list[3] as! String + let alias: String? = nilOrValue(list[4]) + let vip4 = list[5] as! String + let vip6 = list[6] as! String + + return OpsLease( + accountId: accountId, + publicKey: publicKey, + gatewayId: gatewayId, + expires: expires, + alias: alias, + vip4: vip4, + vip6: vip6 + ) + } + func toList() -> [Any?] { + return [ + accountId, + publicKey, + gatewayId, + expires, + alias, + vip4, + vip6, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct OpsVpnConfig { + var devicePrivateKey: String + var deviceTag: String + var gatewayPublicKey: String + var gatewayNiceName: String + var gatewayIpv4: String + var gatewayIpv6: String + var gatewayPort: String + var leaseVip4: String + var leaseVip6: String + + static func fromList(_ list: [Any?]) -> OpsVpnConfig? { + let devicePrivateKey = list[0] as! String + let deviceTag = list[1] as! String + let gatewayPublicKey = list[2] as! String + let gatewayNiceName = list[3] as! String + let gatewayIpv4 = list[4] as! String + let gatewayIpv6 = list[5] as! String + let gatewayPort = list[6] as! String + let leaseVip4 = list[7] as! String + let leaseVip6 = list[8] as! String + + return OpsVpnConfig( + devicePrivateKey: devicePrivateKey, + deviceTag: deviceTag, + gatewayPublicKey: gatewayPublicKey, + gatewayNiceName: gatewayNiceName, + gatewayIpv4: gatewayIpv4, + gatewayIpv6: gatewayIpv6, + gatewayPort: gatewayPort, + leaseVip4: leaseVip4, + leaseVip6: leaseVip6 + ) + } + func toList() -> [Any?] { + return [ + devicePrivateKey, + deviceTag, + gatewayPublicKey, + gatewayNiceName, + gatewayIpv4, + gatewayIpv6, + gatewayPort, + leaseVip4, + leaseVip6, + ] + } +} + +private class PlusOpsCodecReader: FlutterStandardReader { + override func readValue(ofType type: UInt8) -> Any? { + switch type { + case 128: + return OpsGateway.fromList(self.readValue() as! [Any?]) + case 129: + return OpsKeypair.fromList(self.readValue() as! [Any?]) + case 130: + return OpsLease.fromList(self.readValue() as! [Any?]) + case 131: + return OpsLease.fromList(self.readValue() as! [Any?]) + case 132: + return OpsVpnConfig.fromList(self.readValue() as! [Any?]) + default: + return super.readValue(ofType: type) + } + } +} + +private class PlusOpsCodecWriter: FlutterStandardWriter { + override func writeValue(_ value: Any) { + if let value = value as? OpsGateway { + super.writeByte(128) + super.writeValue(value.toList()) + } else if let value = value as? OpsKeypair { + super.writeByte(129) + super.writeValue(value.toList()) + } else if let value = value as? OpsLease { + super.writeByte(130) + super.writeValue(value.toList()) + } else if let value = value as? OpsLease { + super.writeByte(131) + super.writeValue(value.toList()) + } else if let value = value as? OpsVpnConfig { + super.writeByte(132) + super.writeValue(value.toList()) + } else { + super.writeValue(value) + } + } +} + +private class PlusOpsCodecReaderWriter: FlutterStandardReaderWriter { + override func reader(with data: Data) -> FlutterStandardReader { + return PlusOpsCodecReader(data: data) + } + + override func writer(with data: NSMutableData) -> FlutterStandardWriter { + return PlusOpsCodecWriter(data: data) + } +} + +class PlusOpsCodec: FlutterStandardMessageCodec { + static let shared = PlusOpsCodec(readerWriter: PlusOpsCodecReaderWriter()) +} + +/// Generated protocol from Pigeon that represents a handler of messages from Flutter. +protocol PlusOps { + func doGenerateKeypair(completion: @escaping (Result) -> Void) + func doGatewaysChanged(gateways: [OpsGateway], completion: @escaping (Result) -> Void) + func doSelectedGatewayChanged(publicKey: String?, completion: @escaping (Result) -> Void) + func doLeasesChanged(leases: [OpsLease], completion: @escaping (Result) -> Void) + func doCurrentLeaseChanged(lease: OpsLease?, completion: @escaping (Result) -> Void) + func doSetVpnConfig(config: OpsVpnConfig, completion: @escaping (Result) -> Void) + func doSetVpnActive(active: Bool, completion: @escaping (Result) -> Void) + func doPlusEnabledChanged(plusEnabled: Bool, completion: @escaping (Result) -> Void) +} + +/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. +class PlusOpsSetup { + /// The codec used by PlusOps. + static var codec: FlutterStandardMessageCodec { PlusOpsCodec.shared } + /// Sets up an instance of `PlusOps` to handle messages through the `binaryMessenger`. + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: PlusOps?) { + let doGenerateKeypairChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PlusOps.doGenerateKeypair", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doGenerateKeypairChannel.setMessageHandler { _, reply in + api.doGenerateKeypair() { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doGenerateKeypairChannel.setMessageHandler(nil) + } + let doGatewaysChangedChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PlusOps.doGatewaysChanged", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doGatewaysChangedChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let gatewaysArg = args[0] as! [OpsGateway] + api.doGatewaysChanged(gateways: gatewaysArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doGatewaysChangedChannel.setMessageHandler(nil) + } + let doSelectedGatewayChangedChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PlusOps.doSelectedGatewayChanged", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doSelectedGatewayChangedChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let publicKeyArg: String? = nilOrValue(args[0]) + api.doSelectedGatewayChanged(publicKey: publicKeyArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doSelectedGatewayChangedChannel.setMessageHandler(nil) + } + let doLeasesChangedChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PlusOps.doLeasesChanged", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doLeasesChangedChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let leasesArg = args[0] as! [OpsLease] + api.doLeasesChanged(leases: leasesArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doLeasesChangedChannel.setMessageHandler(nil) + } + let doCurrentLeaseChangedChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PlusOps.doCurrentLeaseChanged", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doCurrentLeaseChangedChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let leaseArg: OpsLease? = nilOrValue(args[0]) + api.doCurrentLeaseChanged(lease: leaseArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doCurrentLeaseChangedChannel.setMessageHandler(nil) + } + let doSetVpnConfigChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PlusOps.doSetVpnConfig", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doSetVpnConfigChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let configArg = args[0] as! OpsVpnConfig + api.doSetVpnConfig(config: configArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doSetVpnConfigChannel.setMessageHandler(nil) + } + let doSetVpnActiveChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PlusOps.doSetVpnActive", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doSetVpnActiveChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let activeArg = args[0] as! Bool + api.doSetVpnActive(active: activeArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doSetVpnActiveChannel.setMessageHandler(nil) + } + let doPlusEnabledChangedChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PlusOps.doPlusEnabledChanged", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + doPlusEnabledChangedChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let plusEnabledArg = args[0] as! Bool + api.doPlusEnabledChanged(plusEnabled: plusEnabledArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doPlusEnabledChangedChannel.setMessageHandler(nil) + } + } +} +/// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift. +protocol PlusVpnEventsProtocol { + func onVpnStatus(status statusArg: String, completion: @escaping (Result) -> Void) +} +class PlusVpnEvents: PlusVpnEventsProtocol { + private let binaryMessenger: FlutterBinaryMessenger + init(binaryMessenger: FlutterBinaryMessenger){ + self.binaryMessenger = binaryMessenger + } + func onVpnStatus(status statusArg: String, completion: @escaping (Result) -> Void) { + let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.PlusVpnEvents.onVpnStatus", binaryMessenger: binaryMessenger) + channel.sendMessage([statusArg] as [Any?]) { _ in + completion(.success(Void())) + } + } +} diff --git a/common/ios/Stage.swift b/common/ios/Stage.swift new file mode 100644 index 000000000..31839f470 --- /dev/null +++ b/common/ios/Stage.swift @@ -0,0 +1,153 @@ +// Autogenerated from Pigeon (v12.0.1), do not edit directly. +// See also: https://pub.dev/packages/pigeon + +import Foundation +#if os(iOS) +import Flutter +#elseif os(macOS) +import FlutterMacOS +#else +#error("Unsupported platform.") +#endif + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + +private func wrapResult(_ result: Any?) -> [Any?] { + return [result] +} + +private func wrapError(_ error: Any) -> [Any?] { + if let flutterError = error as? FlutterError { + return [ + flutterError.code, + flutterError.message, + flutterError.details + ] + } + return [ + "\(error)", + "\(type(of: error))", + "Stacktrace: \(Thread.callStackSymbols)" + ] +} + +private func nilOrValue(_ value: Any?) -> T? { + if value is NSNull { return nil } + return value as! T? +} + +enum StageModal: Int { + case help = 0 + case perms = 1 + case onboardingFamily = 2 + case onboardingAccountDecided = 3 + case payment = 4 + case plusLocationSelect = 5 + case debug = 6 + case debugSharing = 7 + case adsCounterShare = 8 + case custom = 9 + case fault = 10 + case faultLocked = 11 + case faultLockInvalid = 12 + case faultLinkAlready = 13 + case accountChange = 14 + case accountLink = 15 + case accountInitFailed = 16 + case accountRestoreFailed = 17 + case accountRestoreIdOk = 18 + case accountRestoreIdFailed = 19 + case accountExpired = 20 + case accountInvalid = 21 + case plusTooManyLeases = 22 + case plusVpnFailure = 23 + case paymentUnavailable = 24 + case paymentTempUnavailable = 25 + case paymentFailed = 26 + case deviceAlias = 27 + case lock = 28 + case rate = 29 + case crash = 30 +} + +/// Generated protocol from Pigeon that represents a handler of messages from Flutter. +protocol StageOps { + func doShowModal(modal: StageModal, completion: @escaping (Result) -> Void) + func doDismissModal(completion: @escaping (Result) -> Void) + func doOpenLink(url: String, completion: @escaping (Result) -> Void) + func doHomeReached(completion: @escaping (Result) -> Void) +} + +/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. +class StageOpsSetup { + /// The codec used by StageOps. + /// Sets up an instance of `StageOps` to handle messages through the `binaryMessenger`. + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: StageOps?) { + let doShowModalChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.StageOps.doShowModal", binaryMessenger: binaryMessenger) + if let api = api { + doShowModalChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let modalArg = StageModal(rawValue: args[0] as! Int)! + api.doShowModal(modal: modalArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doShowModalChannel.setMessageHandler(nil) + } + let doDismissModalChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.StageOps.doDismissModal", binaryMessenger: binaryMessenger) + if let api = api { + doDismissModalChannel.setMessageHandler { _, reply in + api.doDismissModal() { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doDismissModalChannel.setMessageHandler(nil) + } + let doOpenLinkChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.StageOps.doOpenLink", binaryMessenger: binaryMessenger) + if let api = api { + doOpenLinkChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let urlArg = args[0] as! String + api.doOpenLink(url: urlArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doOpenLinkChannel.setMessageHandler(nil) + } + let doHomeReachedChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.common.StageOps.doHomeReached", binaryMessenger: binaryMessenger) + if let api = api { + doHomeReachedChannel.setMessageHandler { _, reply in + api.doHomeReached() { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + doHomeReachedChannel.setMessageHandler(nil) + } + } +} diff --git a/common/libgen/schema/App.dart b/common/libgen/App.dart similarity index 100% rename from common/libgen/schema/App.dart rename to common/libgen/App.dart diff --git a/common/libgen/schema/Command.dart b/common/libgen/Command.dart similarity index 100% rename from common/libgen/schema/Command.dart rename to common/libgen/Command.dart diff --git a/common/libgen/schema/Common.dart b/common/libgen/Common.dart similarity index 100% rename from common/libgen/schema/Common.dart rename to common/libgen/Common.dart diff --git a/common/libgen/schema/Core.dart b/common/libgen/Core.dart similarity index 100% rename from common/libgen/schema/Core.dart rename to common/libgen/Core.dart diff --git a/common/libgen/schema/Family.dart b/common/libgen/Family.dart similarity index 100% rename from common/libgen/schema/Family.dart rename to common/libgen/Family.dart diff --git a/common/libgen/schema/Payment.dart b/common/libgen/Payment.dart similarity index 100% rename from common/libgen/schema/Payment.dart rename to common/libgen/Payment.dart diff --git a/common/libgen/schema/Perm.dart b/common/libgen/Perm.dart similarity index 100% rename from common/libgen/schema/Perm.dart rename to common/libgen/Perm.dart diff --git a/common/libgen/schema/Plus.dart b/common/libgen/Plus.dart similarity index 100% rename from common/libgen/schema/Plus.dart rename to common/libgen/Plus.dart diff --git a/common/libgen/schema/Stage.dart b/common/libgen/Stage.dart similarity index 100% rename from common/libgen/schema/Stage.dart rename to common/libgen/Stage.dart diff --git a/common/build.for.ios.sh b/common/scripts/build.for.ios.sh similarity index 100% rename from common/build.for.ios.sh rename to common/scripts/build.for.ios.sh diff --git a/common/scripts/pigeon.py b/common/scripts/pigeon.py new file mode 100755 index 000000000..903eeec74 --- /dev/null +++ b/common/scripts/pigeon.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python3 +import os +import glob +import shutil +import subprocess +import re +import argparse + +def run_pigeon(file, output_base, generate_android, base_cmd): + """ + Runs the pigeon command for the given schema file. + Generates: + - Dart output always (goes to lib/platform...). + - Either Android or iOS native files based on generate_android. + """ + base = os.path.basename(file) + name, _ = os.path.splitext(base) + name_lower = name.lower() + + # Insert a slash before every uppercase letter and convert to lowercase. + # This mimics: sed 's/\([A-Z]\)/\/\1/g' | tr '[:upper:]' '[:lower:]' + dart_path = re.sub(r'([A-Z])', r'/\1', name).lower() + print(f"Computed dart path: {dart_path}") + + # Split the base command (e.g., "fvm flutter pub" or "dart") into parts. + base_cmd_list = base_cmd.split() + # Build the common part of the pigeon command. + command = base_cmd_list + [ + "run", "pigeon", + "--input", file, + "--dart_out", f"lib/platform{dart_path}/channel.pg.dart" + ] + + # Append native-specific output based on the flag. + if generate_android: + # Generate Android files. + native_dir = os.path.join(output_base, "android") + command.extend([ + "--kotlin_out", os.path.join(native_dir, f"{name}.kt"), + "--kotlin_package", f"channel.{name_lower}" + ]) + else: + # Generate iOS files. + native_dir = os.path.join(output_base, "ios") + command.extend([ + "--swift_out", os.path.join(native_dir, f"{name}.swift") + ]) + + print(f"Running command: {' '.join(command)}") + subprocess.run(command, check=True) + +def main(): + parser = argparse.ArgumentParser( + description="Sync and generate files using pigeon and build_runner." + ) + parser.add_argument( + "--output", "-o", + type=str, + default="./build", + help="Base output path for generated native files (iOS/Android). Default: ./build" + ) + parser.add_argument( + "--android", + action="store_true", + help="Generate Android files. If not specified, iOS files are generated." + ) + parser.add_argument( + "--cmd", + type=str, + default="dart", + help="Base command to use for running pigeon. E.g., 'fvm flutter pub' or 'dart' (default)." + ) + args = parser.parse_args() + + output_base = args.output + + print("Syncing generated files...") + print("Running pigeon...") + + # Determine the native output directory based on the platform. + native_platform = "android" if args.android else "ios" + native_dir = os.path.join(output_base, native_platform) + + # Remove the native output directory if it exists. + if os.path.exists(native_dir): + shutil.rmtree(native_dir) + os.makedirs(native_dir, exist_ok=True) + + # Process each Dart file in libgen/ + schema_files = glob.glob("libgen/*.dart") + if not schema_files: + print("No schema files found in libgen/") + for file in schema_files: + run_pigeon(file, output_base, args.android, args.cmd) + + print("Done") + +if __name__ == "__main__": + main() diff --git a/common/translate b/common/translate deleted file mode 160000 index 5f4d03345..000000000 --- a/common/translate +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5f4d0334541348c42a0bbb705cd21ddda70388f7 diff --git a/common/libgen/static/Url.swift b/ios/libgen-static/Url.swift similarity index 100% rename from common/libgen/static/Url.swift rename to ios/libgen-static/Url.swift diff --git a/common/sync-generated-files.sh b/scripts/sync-generated-files.sh similarity index 100% rename from common/sync-generated-files.sh rename to scripts/sync-generated-files.sh diff --git a/common/sync-translations.sh b/scripts/sync-translations.sh similarity index 100% rename from common/sync-translations.sh rename to scripts/sync-translations.sh diff --git a/translate b/translate new file mode 160000 index 000000000..5087cb008 --- /dev/null +++ b/translate @@ -0,0 +1 @@ +Subproject commit 5087cb008e701a1b5cfdd74536b551a99aeeb953