Skip to content

Commit e774c94

Browse files
committed
Add DriverClient to Dart bindings
1 parent 428a03e commit e774c94

File tree

17 files changed

+6389
-139
lines changed

17 files changed

+6389
-139
lines changed

rust/bindings/dart/lib/errors.dart

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,29 @@ export 'src/generated/api/client.dart'
22
show
33
ConnectionError,
44
ConnectionError_Failed,
5+
PersistError,
6+
PersistError_Open,
7+
PersistError_Serialize,
8+
PersistError_Set,
9+
ReceiveError,
510
RequestError,
6-
RequestError_Send,
711
RequestError_Receive,
12+
RequestError_Send,
813
RequestError_Timeout,
9-
ReceiveError,
1014
SendError,
1115
SendError_PipeBroken;
16+
17+
export 'src/generated/api/driver_client.dart'
18+
show
19+
AddModeError,
20+
AddModeError_ModeExists,
21+
AddModeError_MonitorNotFound,
22+
AddModeError_RefreshRateExists,
23+
DuplicateError,
24+
DuplicateError_Monitor,
25+
DuplicateError_Mode,
26+
DuplicateError_RefreshRate,
27+
InitError,
28+
InitError_Connect,
29+
InitError_RequestState,
30+
MonitorNotFoundError;

rust/bindings/dart/lib/src/generated/api/client.dart

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
99
import 'package:freezed_annotation/freezed_annotation.dart' hide protected;
1010
part 'client.freezed.dart';
1111

12-
// 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`
12+
// 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`
1313

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

26+
/// Write `monitors` to the registry for current user.
27+
///
28+
/// Next time the driver is started, it will load this state from the
29+
/// registry. This might be after a reboot or a driver restart.
30+
static Future<void> persist({required List<Monitor> monitors}) =>
31+
RustLib.instance.api.crateApiClientClientPersist(monitors: monitors);
32+
2633
/// Receive continuous events from the driver.
2734
///
2835
/// Only new events after calling this method are received.
@@ -58,6 +65,31 @@ sealed class ConnectionError with _$ConnectionError implements FrbException {
5865
};
5966
}
6067

68+
@freezed
69+
sealed class PersistError with _$PersistError implements FrbException {
70+
const PersistError._();
71+
72+
const factory PersistError.open({
73+
required String message,
74+
}) = PersistError_Open;
75+
const factory PersistError.set_({
76+
required String message,
77+
}) = PersistError_Set;
78+
const factory PersistError.serialize({
79+
required String message,
80+
}) = PersistError_Serialize;
81+
82+
@override
83+
String toString() => switch (this) {
84+
PersistError_Open(:final message) =>
85+
'Failed to open registry key: $message',
86+
PersistError_Set(:final message) =>
87+
'Failed to set registry key: $message',
88+
PersistError_Serialize(:final message) =>
89+
'Failed to serialize data: $message',
90+
};
91+
}
92+
6193
class ReceiveError implements FrbException {
6294
final String message;
6395

0 commit comments

Comments
 (0)