From f043940152b4657b44d56c2c098d2a0ade38aee1 Mon Sep 17 00:00:00 2001 From: open-trade Date: Mon, 9 Nov 2020 18:25:55 +0800 Subject: [PATCH] set app_dir via ffi --- .../android/app/src/main/AndroidManifest.xml | 3 +- flutter_hbb/lib/main.dart | 16 +++- flutter_hbb/pubspec.lock | 85 +++++++++++++++++++ flutter_hbb/pubspec.yaml | 1 + 4 files changed, 100 insertions(+), 5 deletions(-) diff --git a/flutter_hbb/android/app/src/main/AndroidManifest.xml b/flutter_hbb/android/app/src/main/AndroidManifest.xml index deb519449..c107abd8c 100644 --- a/flutter_hbb/android/app/src/main/AndroidManifest.xml +++ b/flutter_hbb/android/app/src/main/AndroidManifest.xml @@ -43,5 +43,6 @@ - + + diff --git a/flutter_hbb/lib/main.dart b/flutter_hbb/lib/main.dart index f5b49ab62..a3f287ca9 100644 --- a/flutter_hbb/lib/main.dart +++ b/flutter_hbb/lib/main.dart @@ -1,20 +1,28 @@ +import 'package:ffi/ffi.dart'; import 'package:flutter/material.dart'; -import 'dart:io' show Platform; +import 'package:path_provider/path_provider.dart'; +import 'dart:io'; import 'dart:ffi'; +import 'dart:async'; void main() { - final dylib = Platform.isAndroid ? DynamicLibrary.open('librustdesk.so') : DynamicLibrary.process(); - final initialize = dylib.lookupFunction('initialize'); - initialize(); // final connect = dylib.lookupFunction), void Function(Pointer)>('connect'); // connect(Utf8.toUtf8('test')); runApp(MyApp()); } +Future initialzeFFI() async { + final dylib = Platform.isAndroid ? DynamicLibrary.open('librustdesk.so') : DynamicLibrary.process(); + String dir = (await getApplicationDocumentsDirectory()).path; + final initialize = dylib.lookupFunction), void Function(Pointer)>('initialize'); + initialize(Utf8.toUtf8(dir)); +} + class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { + initialzeFFI(); return MaterialApp( title: 'Flutter Demo', theme: ThemeData( diff --git a/flutter_hbb/pubspec.lock b/flutter_hbb/pubspec.lock index 6efd799b4..7cb6b1fb0 100644 --- a/flutter_hbb/pubspec.lock +++ b/flutter_hbb/pubspec.lock @@ -64,6 +64,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.1.3" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "5.2.1" flutter: dependency: "direct main" description: flutter @@ -74,6 +81,13 @@ packages: description: flutter source: sdk version: "0.0.0" + intl: + dependency: transitive + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.16.1" matcher: dependency: transitive description: @@ -95,6 +109,62 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0-nullsafety.1" + path_provider: + dependency: "direct main" + description: + name: path_provider + url: "https://pub.dartlang.org" + source: hosted + version: "1.6.24" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.1+2" + path_provider_macos: + dependency: transitive + description: + name: path_provider_macos + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.4+6" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.4+3" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.1" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" + process: + dependency: transitive + description: + name: process + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.13" sky_engine: dependency: transitive description: flutter @@ -156,5 +226,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0-nullsafety.3" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" + source: hosted + version: "1.7.3" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.2" sdks: dart: ">=2.10.0-110 <2.11.0" + flutter: ">=1.12.13+hotfix.5 <2.0.0" diff --git a/flutter_hbb/pubspec.yaml b/flutter_hbb/pubspec.yaml index c9ceec9f6..921f3fe6d 100644 --- a/flutter_hbb/pubspec.yaml +++ b/flutter_hbb/pubspec.yaml @@ -29,6 +29,7 @@ dependencies: # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.0 ffi: ^0.1.3 + path_provider: ^1.6.24 dev_dependencies: flutter_test: