refactor(core,gui): make all needed changes to send and receive files on linux and android
This commit is contained in:
parent
351b7b9323
commit
0416ab6dab
12 changed files with 108 additions and 193 deletions
|
|
@ -1,7 +1,11 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class Constants {
|
||||
static const backColor = Color(0xFF32363E);
|
||||
static const highlightColor = Color(0xFF98C379);
|
||||
static const textColor = Color(0xFFABB2BF);
|
||||
static const backColor = Color(0xFF303446);
|
||||
static const highlightColor = Color(0xFF8caaee);
|
||||
static const textColor = Color(0xFFc6d0f5);
|
||||
// static const backColor = Color(0xFF32363E);
|
||||
// static const highlightColor = Color(0xFF98C379);
|
||||
// static const highlightColor = Color(0xFFa6d189);
|
||||
// static const textColor = Color(0xFFABB2BF);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import 'package:bitsdojo_window/bitsdojo_window.dart';
|
|||
import 'package:flutter_test_gui/pages/settings_screen.dart';
|
||||
import 'package:flutter_test_gui/pages/send_screen.dart';
|
||||
import 'package:flutter_test_gui/pages/receive_screen.dart';
|
||||
import 'package:flutter_test_gui/consts/consts.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
await RustLib.init();
|
||||
|
|
@ -23,9 +24,9 @@ Future<void> main() async {
|
|||
}
|
||||
}
|
||||
|
||||
const backColor = Color(0xFF32363E);
|
||||
const highlightColor = Color(0xFF98C379);
|
||||
const textColor = Color(0xFFABB2BF);
|
||||
// const backColor = Color(0xFF32363E);
|
||||
// const highlightColor = Color(0xFF98C379);
|
||||
// const textColor = Color(0xFFABB2BF);
|
||||
|
||||
class MyApp extends StatefulWidget {
|
||||
const MyApp({super.key});
|
||||
|
|
@ -73,13 +74,13 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
return MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
home: Scaffold(
|
||||
backgroundColor: backColor,
|
||||
backgroundColor: Constants.backColor,
|
||||
appBar: AppBar(
|
||||
backgroundColor: const Color(0xFF282C34),
|
||||
backgroundColor: const Color(0xFF292c3c), //0xFF282C34),
|
||||
centerTitle: true,
|
||||
title: Text(
|
||||
widget.title,
|
||||
style: const TextStyle(color: textColor),
|
||||
style: const TextStyle(color: Constants.textColor),
|
||||
),
|
||||
actions: [
|
||||
PopupMenuButton<String>(
|
||||
|
|
@ -102,7 +103,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
),
|
||||
body: _screens[_selectedIndex],
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
backgroundColor: const Color(0xFF282C34),
|
||||
backgroundColor: const Color(0xFF292c3c), //0xFF282C34),
|
||||
items: const <BottomNavigationBarItem>[
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.send),
|
||||
|
|
@ -114,8 +115,8 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
),
|
||||
],
|
||||
currentIndex: _selectedIndex,
|
||||
selectedItemColor: highlightColor,
|
||||
unselectedItemColor: textColor,
|
||||
selectedItemColor: Constants.highlightColor,
|
||||
unselectedItemColor: Constants.textColor,
|
||||
onTap: _onItemTapped,
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test_gui/main.dart';
|
||||
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||
|
|
@ -31,7 +32,8 @@ class ReceiveScreenState extends State<ReceiveScreen> {
|
|||
if (barcode.raw == null) {
|
||||
debugPrint('Failed to scan qr code');
|
||||
} else {
|
||||
final String code = barcode.raw.toString();
|
||||
final String code = barcode.barcodes.first.displayValue.toString();
|
||||
print(code);
|
||||
setState(() {
|
||||
inputValue = code;
|
||||
_showScanner = false;
|
||||
|
|
@ -69,12 +71,20 @@ class ReceiveScreenState extends State<ReceiveScreen> {
|
|||
|
||||
Future<void> _startTransfer(String appOrigin) async {
|
||||
final input = inputValue.trim();
|
||||
String filePath = '';
|
||||
if (input.isNotEmpty) {
|
||||
String? selectDirectory = await FilePicker.platform.getDirectoryPath();
|
||||
if (selectDirectory == null) {
|
||||
print("User doesnt choose a directory");
|
||||
} else {
|
||||
print("user choose: $selectDirectory");
|
||||
filePath = selectDirectory;
|
||||
}
|
||||
if (Platform.isAndroid) {
|
||||
if (await _requestPermission(Permission.manageExternalStorage)) {
|
||||
try {
|
||||
final outcome =
|
||||
await startRustReceiver(transfername: input, relay: appOrigin);
|
||||
final outcome = await startRustReceiver(
|
||||
filepath: filePath, transfername: input, relay: appOrigin);
|
||||
print('Ergebnis von Rust: $outcome');
|
||||
} catch (e) {
|
||||
print('Fehler beim Starten des Receivers: $e');
|
||||
|
|
@ -93,8 +103,8 @@ class ReceiveScreenState extends State<ReceiveScreen> {
|
|||
}
|
||||
} else {
|
||||
try {
|
||||
final outcome =
|
||||
await startRustReceiver(transfername: input, relay: appOrigin);
|
||||
final outcome = await startRustReceiver(
|
||||
filepath: filePath, transfername: input, relay: appOrigin);
|
||||
print('Ergebnis von Rust: $outcome');
|
||||
} catch (e) {
|
||||
print('Fehler beim Starten des Receivers: $e');
|
||||
|
|
@ -112,7 +122,7 @@ class ReceiveScreenState extends State<ReceiveScreen> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: backColor,
|
||||
backgroundColor: Constants.backColor,
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ class TransferScreenState extends State<TransferScreen> {
|
|||
// } else {}
|
||||
// } else {
|
||||
try {
|
||||
final outcome =
|
||||
await startRustReceiver(transfername: input, relay: appOrigin);
|
||||
print('Ergebnis von Rust: $outcome');
|
||||
// final outcome =
|
||||
// await startRustReceiver(transfername: input, relay: appOrigin);
|
||||
// print('Ergebnis von Rust: $outcome');
|
||||
} catch (e) {
|
||||
print('Fehler beim Starten des Receivers: $e');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,12 @@ Future<void> startRustSender(
|
|||
.startRustSender(name: name, relay: relay, files: files, hint: hint);
|
||||
|
||||
Future<String> startRustReceiver(
|
||||
{required String relay, required String transfername, dynamic hint}) =>
|
||||
{required String filepath,
|
||||
required String relay,
|
||||
required String transfername,
|
||||
dynamic hint}) =>
|
||||
RustLib.instance.api.startRustReceiver(
|
||||
relay: relay, transfername: transfername, hint: hint);
|
||||
filepath: filepath,
|
||||
relay: relay,
|
||||
transfername: transfername,
|
||||
hint: hint);
|
||||
|
|
|
|||
|
|
@ -72,7 +72,10 @@ abstract class RustLibApi extends BaseApi {
|
|||
Future<void> initApp({dynamic hint});
|
||||
|
||||
Future<String> startRustReceiver(
|
||||
{required String relay, required String transfername, dynamic hint});
|
||||
{required String filepath,
|
||||
required String relay,
|
||||
required String transfername,
|
||||
dynamic hint});
|
||||
|
||||
Future<void> startRustSender(
|
||||
{required String name,
|
||||
|
|
@ -138,10 +141,14 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
|||
|
||||
@override
|
||||
Future<String> startRustReceiver(
|
||||
{required String relay, required String transfername, dynamic hint}) {
|
||||
{required String filepath,
|
||||
required String relay,
|
||||
required String transfername,
|
||||
dynamic hint}) {
|
||||
return handler.executeNormal(NormalTask(
|
||||
callFfi: (port_) {
|
||||
final serializer = SseSerializer(generalizedFrbRustBinding);
|
||||
sse_encode_String(filepath, serializer);
|
||||
sse_encode_String(relay, serializer);
|
||||
sse_encode_String(transfername, serializer);
|
||||
pdeCallFfi(generalizedFrbRustBinding, serializer,
|
||||
|
|
@ -152,7 +159,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
|||
decodeErrorData: sse_decode_AnyhowException,
|
||||
),
|
||||
constMeta: kStartRustReceiverConstMeta,
|
||||
argValues: [relay, transfername],
|
||||
argValues: [filepath, relay, transfername],
|
||||
apiImpl: this,
|
||||
hint: hint,
|
||||
));
|
||||
|
|
@ -160,7 +167,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
|||
|
||||
TaskConstMeta get kStartRustReceiverConstMeta => const TaskConstMeta(
|
||||
debugName: "start_rust_receiver",
|
||||
argNames: ["relay", "transfername"],
|
||||
argNames: ["filepath", "relay", "transfername"],
|
||||
);
|
||||
|
||||
@override
|
||||
|
|
|
|||
|
|
@ -1,32 +1,12 @@
|
|||
name: flutter_test_gui
|
||||
description: "A new Flutter project."
|
||||
# The following line prevents the package from being accidentally published to
|
||||
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
||||
publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
||||
publish_to: "none"
|
||||
|
||||
# The following defines the version and build number for your application.
|
||||
# A version number is three numbers separated by dots, like 1.2.43
|
||||
# followed by an optional build number separated by a +.
|
||||
# Both the version and the builder number may be overridden in flutter
|
||||
# build by specifying --build-name and --build-number, respectively.
|
||||
# In Android, build-name is used as versionName while build-number used as versionCode.
|
||||
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
|
||||
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
|
||||
# Read more about iOS versioning at
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
# In Windows, build-name is used as the major, minor, and patch parts
|
||||
# of the product and file versions while build-number is used as the build suffix.
|
||||
version: 1.0.0+1
|
||||
|
||||
environment:
|
||||
sdk: ">=3.3.4 <4.0.0"
|
||||
|
||||
# Dependencies specify other packages that your package needs in order to work.
|
||||
# To automatically upgrade your package dependencies to the latest versions
|
||||
# consider running `flutter pub upgrade --major-versions`. Alternatively,
|
||||
# dependencies can be manually updated by changing the version numbers below to
|
||||
# the latest version available on pub.dev. To see which dependencies have newer
|
||||
# versions available, run `flutter pub outdated`.
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
|
@ -39,66 +19,19 @@ dependencies:
|
|||
desktop_drop: ^0.4.4
|
||||
shared_preferences: ^2.2.3
|
||||
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^1.0.6
|
||||
rust_lib_flutter_test_gui:
|
||||
path: rust_builder
|
||||
flutter_rust_bridge: 2.0.0-dev.33
|
||||
# dio: ^5.4.3+1
|
||||
# path_provider: ^2.1.3
|
||||
permission_handler: ^11.3.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
# The "flutter_lints" package below contains a set of recommended lints to
|
||||
# encourage good coding practices. The lint set provided by the package is
|
||||
# activated in the `analysis_options.yaml` file located at the root of your
|
||||
# package. See that file for information about deactivating specific lint
|
||||
# rules and activating additional ones.
|
||||
flutter_lints: ^3.0.0
|
||||
integration_test:
|
||||
sdk: flutter
|
||||
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://dart.dev/tools/pub/pubspec
|
||||
|
||||
# The following section is specific to Flutter packages.
|
||||
flutter:
|
||||
# The following line ensures that the Material Icons font is
|
||||
# included with your application, so that you can use the icons in
|
||||
# the material Icons class.
|
||||
uses-material-design: true
|
||||
|
||||
# To add assets to your application, add an assets section, like this:
|
||||
# assets:
|
||||
# - images/a_dot_burr.jpeg
|
||||
# - images/a_dot_ham.jpeg
|
||||
|
||||
# An image asset can refer to one or more resolution-specific "variants", see
|
||||
# https://flutter.dev/assets-and-images/#resolution-aware
|
||||
|
||||
# For details regarding adding assets from package dependencies, see
|
||||
# https://flutter.dev/assets-and-images/#from-packages
|
||||
|
||||
# To add custom fonts to your application, add a fonts section here,
|
||||
# in this "flutter" section. Each entry in this list should have a
|
||||
# "family" key with the font family name, and a "fonts" key with a
|
||||
# list giving the asset and other descriptors for the font. For
|
||||
# example:
|
||||
# fonts:
|
||||
# - family: Schyler
|
||||
# fonts:
|
||||
# - asset: fonts/Schyler-Regular.ttf
|
||||
# - asset: fonts/Schyler-Italic.ttf
|
||||
# style: italic
|
||||
# - family: Trajan Pro
|
||||
# fonts:
|
||||
# - asset: fonts/TrajanPro.ttf
|
||||
# - asset: fonts/TrajanPro_Bold.ttf
|
||||
# weight: 700
|
||||
#
|
||||
# For details regarding fonts from package dependencies,
|
||||
# see https://flutter.dev/custom-fonts/#from-packages
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue