Skip to content

Commit

Permalink
fix: ffi for web
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Dec 3, 2023
1 parent 6117762 commit e93b801
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/bloc/gebura/gebura_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:tuihub_protos/librarian/sephirah/v1/gebura.pb.dart';
import 'package:tuihub_protos/librarian/v1/common.pb.dart';

import '../../common/bloc_event_status_mixin.dart';
import '../../ffi/native_ffi.dart';
import '../../ffi/ffi.dart';
import '../../model/gebura_model.dart';
import '../../repo/grpc/api_helper.dart';
import '../../repo/local/gebura.dart';
Expand Down Expand Up @@ -189,7 +189,7 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
return;
}
try {
final (start, end, suceess) = await NativeFunc.processRunner(
final (start, end, suceess) = await FFI().processRunner(
'', setting.path, '', dirname(setting.path), 1, 1000);
if (!suceess) {
emit(GeburaRunAppState(state, event.appID, EventStatus.failed,
Expand Down
1 change: 1 addition & 0 deletions lib/ffi/ffi.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'native_ffi.dart' if (dart.library.html) 'web_ffi.dart' show FFI;
12 changes: 12 additions & 0 deletions lib/ffi/ffi_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
abstract class FFIBase {
Future<(int, int, bool)> processRunner(
String name,
String executePath,
String monitorPath,
String workingDir,
int sleepCount,
int sleepMillis,
) {
throw UnimplementedError();
}
}
6 changes: 4 additions & 2 deletions lib/ffi/native_ffi.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:ffi';
import 'dart:io';

import 'ffi_model.dart';
import 'rust_ffi/rust_ffi.dart';

class NativeFFI {
Expand Down Expand Up @@ -28,10 +29,11 @@ class NativeFFI {
}
}

class NativeFunc {
class FFI extends FFIBase {
static final _ffi = RustFfiImpl(NativeFFI.dyLib);

static Future<(int, int, bool)> processRunner(
@override
Future<(int, int, bool)> processRunner(
String name,
String executePath,
String monitorPath,
Expand Down
3 changes: 3 additions & 0 deletions lib/ffi/web_ffi.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'ffi_model.dart';

class FFI extends FFIBase {}

0 comments on commit e93b801

Please sign in to comment.