This commit is contained in:
agra
2026-01-16 14:11:34 +02:00
commit 2b39c6e17f
155 changed files with 5966 additions and 0 deletions

40
lib/hardware.dart Normal file
View File

@@ -0,0 +1,40 @@
import 'dart:ffi';
import 'dart:io';
import 'hardware_bindings_generated.dart';
const String _libName = 'hardware';
/// The dynamic library in which the symbols for [HardwareBindings] can be found.
final DynamicLibrary _dylib = () {
if (Platform.isMacOS || Platform.isIOS) {
return DynamicLibrary.open('$_libName.framework/$_libName');
}
if (Platform.isAndroid || Platform.isLinux) {
return DynamicLibrary.open('lib$_libName.so');
}
if (Platform.isWindows) {
return DynamicLibrary.open('$_libName.dll');
}
throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}');
}();
/// The bindings to the native functions in [_dylib].
final HardwareBindings _bindings = HardwareBindings(_dylib);
/// Hardware screen information.
class HardwareScreen {
/// Returns the device screen corner radius in logical pixels.
/// Returns null on platforms where the value is not available.
double? get borderRadius {
final result = _bindings.get_screen_border_radius();
if (result.hasValue == 0) return null;
return result.value;
}
}
/// Main Hardware API for accessing device hardware information.
abstract class Hardware {
static final HardwareScreen screen = HardwareScreen();
}

View File

@@ -0,0 +1,51 @@
// ignore_for_file: always_specify_types
// ignore_for_file: camel_case_types
// ignore_for_file: non_constant_identifier_names
// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
// ignore_for_file: type=lint
import 'dart:ffi' as ffi;
/// Bindings for `src/hardware.h`.
///
/// Regenerate bindings with `dart run ffigen --config ffigen.yaml`.
///
class HardwareBindings {
/// Holds the symbol lookup function.
final ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
_lookup;
/// The symbols are looked up in [dynamicLibrary].
HardwareBindings(ffi.DynamicLibrary dynamicLibrary)
: _lookup = dynamicLibrary.lookup;
/// The symbols are looked up with [lookup].
HardwareBindings.fromLookup(
ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName) lookup,
) : _lookup = lookup;
/// Returns the screen border radius in logical pixels.
/// If hasValue is 0, the value is not available on this platform.
DoubleOption get_screen_border_radius() {
return _get_screen_border_radius();
}
late final _get_screen_border_radiusPtr =
_lookup<ffi.NativeFunction<DoubleOption Function()>>(
'get_screen_border_radius',
);
late final _get_screen_border_radius = _get_screen_border_radiusPtr
.asFunction<DoubleOption Function()>();
}
/// Option type for nullable double values
final class DoubleOption extends ffi.Struct {
@ffi.Double()
external double value;
/// 1 = has value, 0 = null
@ffi.Int()
external int hasValue;
}