cake_wallet/cw_mweb/lib/cw_mweb.dart

35 lines
1,016 B
Dart
Raw Normal View History

2024-04-20 23:20:52 +00:00
import 'package:grpc/grpc.dart';
2024-04-21 18:58:45 +00:00
import 'package:path_provider/path_provider.dart';
2024-04-20 23:20:52 +00:00
import 'cw_mweb_platform_interface.dart';
import 'mwebd.pbgrpc.dart';
class CwMweb {
2024-07-25 14:03:40 +00:00
static RpcClient? _rpcClient;
static ClientChannel? _clientChannel;
2024-04-21 18:58:45 +00:00
static Future<RpcClient> stub() async {
final appDir = await getApplicationSupportDirectory();
2024-07-17 16:27:31 +00:00
int port = await CwMwebPlatform.instance.start(appDir.path) ?? 0;
2024-07-25 14:03:40 +00:00
_clientChannel = ClientChannel('127.0.0.1',
port: port,
options: const ChannelOptions(
credentials: ChannelCredentials.insecure(),
keepAlive: ClientKeepAliveOptions(permitWithoutCalls: true),
));
_rpcClient = RpcClient(_clientChannel!);
return _rpcClient!;
2024-07-17 16:27:31 +00:00
}
static Future<void> stop() async {
await CwMwebPlatform.instance.start("stop");
2024-07-25 14:03:40 +00:00
await cleanup();
}
static Future<void> cleanup() async {
await _clientChannel?.terminate();
_rpcClient = null;
_clientChannel = null;
print("rpc has been shut down");
2024-04-20 23:20:52 +00:00
}
}