Skip to content

Commit

Permalink
Move invocation code to service.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
lbirkert committed Aug 22, 2024
1 parent 1d469ed commit 1e7f122
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 143 deletions.
191 changes: 79 additions & 112 deletions qb-mobile/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,125 +1,92 @@
// The original content is temporarily commented out to allow generating a self-contained demo - feel free to uncomment later.

// import 'package:flutter/material.dart';
// import 'package:qb_mobile/service.dart';
//
// void main() async {
// WidgetsFlutterBinding.ensureInitialized();
// print("kekw");
// await initializeService();
//
// runApp(const QuixByteApp());
// }
//
// class QuixByteApp extends StatelessWidget {
// const QuixByteApp({super.key});
//
// // This widget is the root of your application.
// @override
// Widget build(BuildContext context) {
// return MaterialApp(
// title: 'QuixByte Mobile',
// theme: ThemeData(
// // This is the theme of your application.
// //
// // TRY THIS: Try running your application with "flutter run". You'll see
// // the application has a purple toolbar. Then, without quitting the app,
// // try changing the seedColor in the colorScheme below to Colors.green
// // and then invoke "hot reload" (save your changes or press the "hot
// // reload" button in a Flutter-supported IDE, or press "r" if you used
// // the command line to start the app).
// //
// // Notice that the counter didn't reset back to zero; the application
// // state is not lost during the reload. To reset the state, use hot
// // restart instead.
// //
// // This works for code too, not just values: Most code changes can be
// // tested with just a hot reload.
// colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
// useMaterial3: true,
// ),
// home: const QuixByteHomePage(),
// );
// }
// }
//
// class QuixByteHomePage extends StatelessWidget {
// const QuixByteHomePage({super.key});
//
// @override
// Widget build(BuildContext context) {
// // This method is rerun every time setState is called, for instance as done
// // by the _incrementCounter method above.
// //
// // The Flutter framework has been optimized to make rerunning build methods
// // fast, so that you can just rebuild anything that needs updating rather
// // than having to individually change instances of widgets.
// return Scaffold(
// appBar: AppBar(
// // TRY THIS: Try changing the color here to a specific color (to
// // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// // change color while the other colors stay the same.
// backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// // Here we take the value from the MyHomePage object that was created by
// // the App.build method, and use it to set our appbar title.
// title: const Text("QuixByte Mobile"),
// ),
// body: Center(
// // Center is a layout widget. It takes a single child and positions it
// // in the middle of the parent.
// child: Column(
// // Column is also a layout widget. It takes a list of children and
// // arranges them vertically. By default, it sizes itself to fit its
// // children horizontally, and tries to be as tall as its parent.
// //
// // Column has various properties to control how it sizes itself and
// // how it positions its children. Here we use mainAxisAlignment to
// // center the children vertically; the main axis here is the vertical
// // axis because Columns are vertical (the cross axis would be
// // horizontal).
// //
// // TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
// // action in the IDE, or press "p" in the console), to see the
// // wireframe for each widget.
// mainAxisAlignment: MainAxisAlignment.center,
// children: <Widget>[
// FilledButton(onPressed: () {}, child: const Text("Settings")),
// FilledButton(onPressed: () {}, child: const Text("Manage")),
// FilledButton(onPressed: () {}, child: const Text("View Files")),
// ],
// ),
// ),
// );
// }
// }
//

import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'package:qb_mobile/src/rust/api/daemon.dart';
import 'package:qb_mobile/src/rust/frb_generated.dart';
import 'package:qb_mobile/service.dart';

Future<void> main() async {
await RustLib.init();
final dir = await getApplicationDocumentsDirectory();
final daemon = await DaemonWrapper.init(path: '$dir');
print(daemon);
runApp(const MyApp());
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await initializeService();

runApp(const QuixByteApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});
class QuixByteApp extends StatelessWidget {
const QuixByteApp({super.key});

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('flutter_rust_bridge quickstart')),
body: Center(
child: Text(
'Action: Call Rust `greet("Tom")`\nResult:`'),
title: 'QuixByte Mobile',
theme: ThemeData(
// This is the theme of your application.
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a purple toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const QuixByteHomePage(),
);
}
}

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

@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: const Text("QuixByte Mobile"),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
//
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
// action in the IDE, or press "p" in the console), to see the
// wireframe for each widget.
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FilledButton(onPressed: () {}, child: const Text("Settings")),
FilledButton(onPressed: () {}, child: const Text("Manage")),
FilledButton(onPressed: () {}, child: const Text("View Files")),
],
),
),
);
}
}

36 changes: 5 additions & 31 deletions qb-mobile/lib/service.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'dart:io';
import 'dart:ui';
import 'dart:async';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
import 'package:process/process.dart';

import 'package:flutter/material.dart';
import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:qb_mobile/src/rust/api/daemon.dart';
import 'package:qb_mobile/src/rust/frb_generated.dart';

const ProcessManager processManager = LocalProcessManager();

Expand Down Expand Up @@ -49,34 +48,9 @@ Future<bool> onIosBackground(ServiceInstance service) async {

@pragma('vm:entry-point')
void onStart(ServiceInstance service) async {
final dir = await getApplicationSupportDirectory();
final deviceInfo = DeviceInfoPlugin();
print("kekw");
if (Platform.isAndroid) {
final binaryAbis = ["arm64-v8a", "armeabi-v7a", "x86_64"];
final androidInfo = await deviceInfo.androidInfo;
final supportedAbis = androidInfo.supportedAbis;
final abi = binaryAbis.firstWhere((abi) => supportedAbis.contains(abi));
//final file = File('${dir.path}/bin/qb-daemon-$abi');
//if(!await file.exists()) {
//await copyBinary('qb-daemon-$abi', file);
//}

final fileProc = await processManager
.run(['ls', '-la', '/data/app/com.example.qb_mobile.apk']);
print(fileProc.stdout);
print(fileProc.stderr);

final file = File('');
final process = await processManager
.run([file.path, '--no-ipc --std'], runInShell: true);
print(process.stderr);
process.stdout.listen((data) {
print("recv: $data");
});
} else {
throw UnimplementedError("QuixByte does not support this device (yet)!");
}
await RustLib.init();
final dir = await getApplicationDocumentsDirectory();
final daemon = await DaemonWrapper.init(path: dir.path);

service.on("stop").listen((event) {
service.stopSelf();
Expand Down

0 comments on commit 1e7f122

Please sign in to comment.