2024-04-21 00:20:52 +01:00
|
|
|
import 'package:grpc/grpc.dart';
|
2024-04-21 19:58:45 +01:00
|
|
|
import 'package:path_provider/path_provider.dart';
|
2024-04-21 00:20:52 +01:00
|
|
|
import 'cw_mweb_platform_interface.dart';
|
|
|
|
import 'mwebd.pbgrpc.dart';
|
|
|
|
|
|
|
|
class CwMweb {
|
2024-04-21 19:58:45 +01:00
|
|
|
static Future<RpcClient> stub() async {
|
|
|
|
final appDir = await getApplicationSupportDirectory();
|
2024-07-17 09:27:31 -07:00
|
|
|
int port = await CwMwebPlatform.instance.start(appDir.path) ?? 0;
|
|
|
|
return RpcClient(
|
|
|
|
ClientChannel('127.0.0.1',
|
|
|
|
port: port,
|
|
|
|
options: const ChannelOptions(
|
|
|
|
credentials: ChannelCredentials.insecure(),
|
|
|
|
keepAlive: ClientKeepAliveOptions(permitWithoutCalls: true),
|
2024-07-19 09:15:28 -07:00
|
|
|
)),
|
2024-07-17 09:27:31 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<void> stop() async {
|
|
|
|
await CwMwebPlatform.instance.start("stop");
|
2024-04-21 00:20:52 +01:00
|
|
|
}
|
|
|
|
}
|