Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
EwuUwe committed Feb 13, 2024
1 parent bf61c01 commit a3bc258
Show file tree
Hide file tree
Showing 12 changed files with 1,444 additions and 28 deletions.
34 changes: 34 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM ghcr.io/cirruslabs/flutter:latest

ENV ANDROID_NDK_VERSION 24.0.8215888
ENV PATH="/root/.cargo/bin:$PATH"


RUN yes | sdkmanager "ndk;$ANDROID_NDK_VERSION"

RUN echo "INPUT(-lunwind)" > /opt/android-sdk-linux/ndk/$ANDROID_NDK_VERSION/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.1/lib/linux/aarch64/libgcc.a
RUN echo "INPUT(-lunwind)" > /opt/android-sdk-linux/ndk/$ANDROID_NDK_VERSION/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.1/lib/linux/arm/libgcc.a
RUN echo "INPUT(-lunwind)" > /opt/android-sdk-linux/ndk/$ANDROID_NDK_VERSION/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.1/lib/linux/i386/libgcc.a
RUN echo "INPUT(-lunwind)" > /opt/android-sdk-linux/ndk/$ANDROID_NDK_VERSION/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.1/lib/linux/x86_64/libgcc.a

RUN apt update && apt install -y \
build-essential \
clang \
llvm \
curl \
git \
libssl-dev \
libgtk-3-dev \
ninja-build \
cmake

RUN curl https://sh.rustup.rs -sSf | sh -s -- -y \
&& . "$HOME/.cargo/env" \
&& rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android \
&& echo "export ANDROID_NDK_HOME=/opt/android-sdk-linux/ndk/$ANDROID_NDK_VERSION" >> $HOME/.bashrc \
&& cargo install cargo-ndk

RUN cargo install flutter_rust_bridge_codegen \
&& cargo install cargo-expand

WORKDIR /root/wormhole
33 changes: 17 additions & 16 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,24 @@
rustToolchain
flutter
androidSdk
gnumake
jdk11
libstdcxx5
libzra
libzip
zlib
libllvm
libclang
llvm
musl
libcxx
glibc
glibc_multi
pkg-config
libclang
gnome.zenity
];
#GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${androidSdk}/libexec/android-sdk/build-tools/${buildToolsVersion}/aapt2";
};

formatter = pkgs.alejandra;

packages = {
default = pkgs.flutter.buildFlutterApplication {
pname = "firmware-updater";
version = "0-unstable-2023-04-30";

# To build for the Web, use the targetFlutterPlatform argument.
targetFlutterPlatform = "linux";

src = ./.;

pubspecLock = pkgs.lib.importJSON ./pubspec.lock.json;
};
};
});
}
71 changes: 64 additions & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,79 @@

import 'dart:io';

import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:iyox_wormhole/pages/BasePage.dart';
import 'package:flutter_displaymode/flutter_displaymode.dart';
import 'package:iyox_wormhole/pages/Router.dart';
import 'package:flutter/services.dart';
import 'package:logger/logger.dart';

void main() {
void main() async {
await initApp();
runApp(const WormholeApp());
}

Future<void> initApp() async {
WidgetsFlutterBinding.ensureInitialized();

if (kReleaseMode && Platform.isAndroid) {
try {
await FlutterDisplayMode.setHighRefreshRate();
debugPrint("Enabled high refresh mode");
} catch (e) {
debugPrint("Error setting high refresh rate: $e");
}
}

var log = Logger();

FlutterError.onError = (details) {
FlutterError.presentError(details);
log.f(
'FlutterError - Catch all error: ${details.toString()} - ${details.exception} - ${details.library} - ${details.context} - ${details.stack}',
error: details,
stackTrace: details.stack,
);
};

PlatformDispatcher.instance.onError = (error, stack) {
log.f('PlatformDispatcher - Catch all error: $error', error: error, stackTrace: stack);
debugPrint("PlatformDispatcher - Catch all error: $error $stack");
return true;
};
}

class NavigationService {
static GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
}

class WormholeApp extends StatelessWidget {
class WormholeApp extends StatefulWidget {
const WormholeApp({super.key});

@override
WormholeAppState createState() => WormholeAppState();
}

class WormholeAppState extends State<WormholeApp> {

Future<void> initApp() async {
// Draw the app from edge to edge
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);

// Sets the navigation bar color
SystemUiOverlayStyle overlayStyle = const SystemUiOverlayStyle(
systemNavigationBarColor: Colors.transparent,
);
SystemChrome.setSystemUIOverlayStyle(overlayStyle);
}

@override
initState() {
super.initState();
initApp().then((_) => debugPrint("App Init Completed"));
}

@override
Widget build(BuildContext context) {
return DynamicColorBuilder(builder: (lightColorScheme, darkColorScheme) {
Expand All @@ -31,10 +91,7 @@ class WormholeApp extends StatelessWidget {
colorScheme: darkColorScheme,
),
themeMode: ThemeMode.dark,
home: GestureDetector(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
child: const BasePage(),
),
home: const BasePage(),
);
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/ReceivePage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:gap/gap.dart';
import 'package:iyox_wormhole/gen/ffi.dart';
import 'package:iyox_wormhole/pages/QrCodeScannerPage.dart';
import 'package:iyox_wormhole/pages/SendPage.dart';
import 'package:iyox_wormhole/type_helpers.dart';
import 'package:iyox_wormhole/utils/type_helpers.dart';
import 'package:iyox_wormhole/utils/paths.dart';

class ReceivePage extends StatefulWidget {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/pages/SendPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:gap/gap.dart';
import 'package:iyox_wormhole/type_helpers.dart';
import 'package:iyox_wormhole/utils/type_helpers.dart';
import 'package:iyox_wormhole/gen/ffi.dart';

import 'SendingPage.dart';
Expand Down
3 changes: 1 addition & 2 deletions lib/pages/SendingPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:gap/gap.dart';
import 'package:iyox_wormhole/type_helpers.dart';
import 'package:iyox_wormhole/utils/type_helpers.dart';
import 'package:qr_flutter/qr_flutter.dart';

import '../gen/ffi.dart';
Expand Down Expand Up @@ -77,7 +77,6 @@ class _SendingPageState extends State<SendingPage> {
appBar: AppBar(),
body: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
debugPrint(constraints.maxWidth.toString());
if (constraints.maxWidth > 600) {
return _buildWideContainer();
} else {
Expand Down
25 changes: 25 additions & 0 deletions lib/utils/responsive_layout.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:flutter/material.dart';

class ResponsiveLayout extends StatelessWidget {
const ResponsiveLayout({
super.key,
required this.mobileLayout,
required this.desktopLayout,
});

final Widget mobileLayout;
final Widget desktopLayout;

@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
if (constraints.maxWidth < 700) {
return mobileLayout;
} else {
return desktopLayout;
}
},
);
}
}
2 changes: 1 addition & 1 deletion lib/type_helpers.dart → lib/utils/type_helpers.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../gen/bridge_definitions.dart';
import '../../gen/bridge_definitions.dart';

extension GetValue<T> on TUpdate {
T getValue() {
Expand Down
16 changes: 16 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_displaymode:
dependency: "direct main"
description:
name: flutter_displaymode
sha256: "42c5e9abd13d28ed74f701b60529d7f8416947e58256e6659c5550db719c57ef"
url: "https://pub.dev"
source: hosted
version: "0.6.0"
flutter_launcher_icons:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -584,6 +592,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.1"
logger:
dependency: "direct main"
description:
name: logger
sha256: "6bbb9d6f7056729537a4309bda2e74e18e5d9f14302489cc1e93f33b3fe32cac"
url: "https://pub.dev"
source: hosted
version: "2.0.2+1"
logging:
dependency: transitive
description:
Expand Down
Loading

0 comments on commit a3bc258

Please sign in to comment.