Skip to content

Commit

Permalink
Add DriverClient to Dart bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Dampfwalze committed Aug 14, 2024
1 parent 428a03e commit e774c94
Show file tree
Hide file tree
Showing 17 changed files with 6,389 additions and 139 deletions.
23 changes: 21 additions & 2 deletions rust/bindings/dart/lib/errors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,29 @@ export 'src/generated/api/client.dart'
show
ConnectionError,
ConnectionError_Failed,
PersistError,
PersistError_Open,
PersistError_Serialize,
PersistError_Set,
ReceiveError,
RequestError,
RequestError_Send,
RequestError_Receive,
RequestError_Send,
RequestError_Timeout,
ReceiveError,
SendError,
SendError_PipeBroken;

export 'src/generated/api/driver_client.dart'
show
AddModeError,
AddModeError_ModeExists,
AddModeError_MonitorNotFound,
AddModeError_RefreshRateExists,
DuplicateError,
DuplicateError_Monitor,
DuplicateError_Mode,
DuplicateError_RefreshRate,
InitError,
InitError_Connect,
InitError_RequestState,
MonitorNotFoundError;
34 changes: 33 additions & 1 deletion rust/bindings/dart/lib/src/generated/api/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
import 'package:freezed_annotation/freezed_annotation.dart' hide protected;
part 'client.freezed.dart';

// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `from`, `from`, `from`, `from`
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `from`, `from`, `from`, `from`, `from`

// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<Client>>
abstract class Client implements RustOpaqueInterface {
Expand All @@ -23,6 +23,13 @@ abstract class Client implements RustOpaqueInterface {
/// Send new state to the driver.
Future<void> notify({required List<Monitor> monitors});

/// Write `monitors` to the registry for current user.
///
/// Next time the driver is started, it will load this state from the
/// registry. This might be after a reboot or a driver restart.
static Future<void> persist({required List<Monitor> monitors}) =>
RustLib.instance.api.crateApiClientClientPersist(monitors: monitors);

/// Receive continuous events from the driver.
///
/// Only new events after calling this method are received.
Expand Down Expand Up @@ -58,6 +65,31 @@ sealed class ConnectionError with _$ConnectionError implements FrbException {
};
}

@freezed
sealed class PersistError with _$PersistError implements FrbException {
const PersistError._();

const factory PersistError.open({
required String message,
}) = PersistError_Open;
const factory PersistError.set_({
required String message,
}) = PersistError_Set;
const factory PersistError.serialize({
required String message,
}) = PersistError_Serialize;

@override
String toString() => switch (this) {
PersistError_Open(:final message) =>
'Failed to open registry key: $message',
PersistError_Set(:final message) =>
'Failed to set registry key: $message',
PersistError_Serialize(:final message) =>
'Failed to serialize data: $message',
};
}

class ReceiveError implements FrbException {
final String message;

Expand Down
Loading

0 comments on commit e774c94

Please sign in to comment.