mirror of
https://github.com/inventree/inventree-app.git
synced 2026-08-18 17:26:28 +00:00
Add intent wedge scanner, MDM support for Android (#863)
Add Android intent wedge scanner support with auto configuration for supported Zebra and Datalogic devices. Intent wedge scans can be done without pressing the scan button first. Adds the ability for an MDM server to push settings on Android.
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import "dart:io";
|
||||
|
||||
import "package:flutter/foundation.dart";
|
||||
import "package:flutter/services.dart";
|
||||
import "package:inventree/preferences.dart";
|
||||
|
||||
const MethodChannel _channel = MethodChannel("inventree/wedge");
|
||||
|
||||
class WedgeDetectionResult {
|
||||
const WedgeDetectionResult({this.vendor = "none", this.supported = false});
|
||||
|
||||
final String vendor;
|
||||
|
||||
final bool supported;
|
||||
}
|
||||
|
||||
Future<WedgeDetectionResult> detectWedgeScanner() async {
|
||||
if (kIsWeb || !Platform.isAndroid) {
|
||||
return const WedgeDetectionResult();
|
||||
}
|
||||
|
||||
try {
|
||||
final Map<String, dynamic>? result = await _channel
|
||||
.invokeMapMethod<String, dynamic>("detectWedge");
|
||||
|
||||
if (result == null) return const WedgeDetectionResult();
|
||||
|
||||
return WedgeDetectionResult(
|
||||
vendor: (result["vendor"] ?? "none").toString(),
|
||||
supported: result["supported"] == true,
|
||||
);
|
||||
} catch (error) {
|
||||
return const WedgeDetectionResult();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> applyWedgeDetection(WedgeDetectionResult result) async {
|
||||
if (result.supported) {
|
||||
await InvenTreeSettingsManager().setValue(
|
||||
INV_BARCODE_SCAN_TYPE,
|
||||
BARCODE_CONTROLLER_INTENT,
|
||||
);
|
||||
}
|
||||
|
||||
await InvenTreeSettingsManager().setValue(INV_BARCODE_WEDGE_DETECTED, true);
|
||||
}
|
||||
|
||||
Future<void> initWedgeScannerDefault() async {
|
||||
if (await InvenTreeSettingsManager().getBool(
|
||||
INV_BARCODE_WEDGE_DETECTED,
|
||||
false,
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final dynamic existing = await InvenTreeSettingsManager().getValue(
|
||||
INV_BARCODE_SCAN_TYPE,
|
||||
null,
|
||||
);
|
||||
|
||||
if (existing != null) {
|
||||
await InvenTreeSettingsManager().setValue(INV_BARCODE_WEDGE_DETECTED, true);
|
||||
return;
|
||||
}
|
||||
|
||||
await applyWedgeDetection(await detectWedgeScanner());
|
||||
}
|
||||
Reference in New Issue
Block a user