Skip to content

Commit

Permalink
cleanup responsibilites of common module
Browse files Browse the repository at this point in the history
Improve Makefile and scripts
  • Loading branch information
kar committed Feb 10, 2025
1 parent 734d617 commit 431fde9
Show file tree
Hide file tree
Showing 33 changed files with 2,065 additions and 18 deletions.
Binary file added .BUILDING.md.swp
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "landing-github-pages"]
path = landing-github-pages
url = [email protected]:blokadaorg/landing-github-pages.git
[submodule "translate"]
path = translate
url = [email protected]:blokadaorg/translate.git
File renamed without changes.
File renamed without changes.
File renamed without changes.
75 changes: 75 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion common/.fvmrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"flutter": "3.22.1"
"flutter": "3.24.4"
}
70 changes: 54 additions & 16 deletions common/Makefile
Original file line number Diff line number Diff line change
@@ -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
80 changes: 80 additions & 0 deletions common/ios/App.swift
Original file line number Diff line number Diff line change
@@ -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<T>(_ 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, Error>) -> 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)
}
}
}
131 changes: 131 additions & 0 deletions common/ios/Command.swift
Original file line number Diff line number Diff line change
@@ -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<T>(_ 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, Error>) -> 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, FlutterError>) -> Void)
func onCommandWithParam(command commandArg: String, p1 p1Arg: String, m mArg: Int64, completion: @escaping (Result<Void, FlutterError>) -> Void)
func onCommandWithParams(command commandArg: String, p1 p1Arg: String, p2 p2Arg: String, m mArg: Int64, completion: @escaping (Result<Void, FlutterError>) -> 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, FlutterError>) -> 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, FlutterError>) -> 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, FlutterError>) -> 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()))
}
}
}
Loading

0 comments on commit 431fde9

Please sign in to comment.