Initial project import
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
enum ApkInstallStatus { launched, permissionRequested, unsupported }
|
||||
|
||||
class ApkInspection {
|
||||
final bool valid;
|
||||
final String? message;
|
||||
|
||||
const ApkInspection({required this.valid, this.message});
|
||||
}
|
||||
|
||||
class UpdateInstaller {
|
||||
UpdateInstaller._();
|
||||
|
||||
static const _channel = MethodChannel('com.nx.miaoji/update');
|
||||
|
||||
static Future<ApkInspection> inspect({
|
||||
required String path,
|
||||
required int expectedBuild,
|
||||
}) async {
|
||||
final result = await _channel.invokeMapMethod<String, dynamic>(
|
||||
'inspectApk',
|
||||
{'path': path, 'expectedBuild': expectedBuild},
|
||||
);
|
||||
return ApkInspection(
|
||||
valid: result?['valid'] == true,
|
||||
message: result?['message']?.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
static Future<ApkInstallStatus> install({
|
||||
required String path,
|
||||
required int expectedBuild,
|
||||
}) async {
|
||||
final result = await _channel.invokeMapMethod<String, dynamic>(
|
||||
'installApk',
|
||||
{'path': path, 'expectedBuild': expectedBuild},
|
||||
);
|
||||
return switch (result?['status']) {
|
||||
'launched' => ApkInstallStatus.launched,
|
||||
'permission_requested' => ApkInstallStatus.permissionRequested,
|
||||
_ => ApkInstallStatus.unsupported,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user