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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue