Skip to content

Commit

Permalink
✨feature: reformat mission stream
Browse files Browse the repository at this point in the history
  • Loading branch information
tom8zds committed Jul 7, 2024
1 parent 549fe3a commit 24ad684
Show file tree
Hide file tree
Showing 39 changed files with 1,311 additions and 1,941 deletions.
14 changes: 11 additions & 3 deletions lib/common/device_info_utils.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'dart:io';
import 'dart:math';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:localsend_rs/core/store/config_store.dart';
import 'package:slang/builder/model/enums.dart';
import 'package:uuid/uuid.dart';

Expand Down Expand Up @@ -42,17 +44,23 @@ Future<List<String>> getInterface() async {
return addressList;
}

int randomPort() {
return 10000 + Random().nextInt(65535 - 10000);
}

Future<NodeDevice> newDevice() async {
final deviceInfo = await getDeviceInfo();
final addressList = await getInterface();
final alias =
"${deviceInfo.deviceModel ?? "unknown"}#${addressList[0].split(".")[3]}";
return NodeDevice(
alias: "test",
alias: alias,
version: "2.0",
deviceModel: deviceInfo.deviceModel ?? "unknown",
deviceType: deviceInfo.deviceType.name,
fingerprint: const Uuid().v4(),
fingerprint: ConfigStore().deviceId(),
address: addressList[0],
port: 9999,
port: randomPort(),
protocol: "http",
download: true,
announcement: true,
Expand Down
15 changes: 15 additions & 0 deletions lib/core/listeners/mission_listener.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:localsend_rs/core/rust/bridge.dart';

import '../rust/actor/mission.dart';

class MissionListener {
static MissionListener? _instance;
MissionListener._();

static MissionListener instance() {
_instance ??= MissionListener._();
return _instance!;
}

Stream<MissionInfo?> stream = listenMission();
}
15 changes: 0 additions & 15 deletions lib/core/listeners/pending_mission_listener.dart

This file was deleted.

2 changes: 1 addition & 1 deletion lib/core/providers/core_provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions lib/core/providers/mission_provider.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import 'package:localsend_rs/core/rust/actor/mission/pending.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../listeners/pending_mission_listener.dart';
import '../rust/actor/model.dart';
import '../listeners/mission_listener.dart';
import '../rust/actor/mission.dart';

part 'mission_provider.g.dart';

@riverpod
class PendingMission extends _$PendingMission {
class CoreMission extends _$CoreMission {
@override
PendingMissionDto build() {
final subPendingMission = PendingMissionListener.instance().stream.listen(
MissionInfo? build() {
final subMission = MissionListener.instance().stream.listen(
(event) {
state = event;
},
);
ref.onDispose(() {
subPendingMission.cancel();
subMission.cancel();
});
return const PendingMissionDto(state: MissionState.idle);
return null;
}
}
21 changes: 10 additions & 11 deletions lib/core/providers/mission_provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/core/rust/actor/core.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is automatically generated, so please do not edit it.
// Generated by `flutter_rust_bridge`@ 2.0.0.
// Generated by `flutter_rust_bridge`@ 2.1.0.

// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import

Expand Down
73 changes: 73 additions & 0 deletions lib/core/rust/actor/mission.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// This file is automatically generated, so please do not edit it.
// Generated by `flutter_rust_bridge`@ 2.1.0.

// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import

import '../api/model.dart';
import '../frb_generated.dart';
import 'model.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
import 'package:freezed_annotation/freezed_annotation.dart' hide protected;
part 'mission.freezed.dart';

@freezed
sealed class FileState with _$FileState {
const FileState._();

const factory FileState.pending() = FileState_Pending;
const factory FileState.transfer() = FileState_Transfer;
const factory FileState.finish() = FileState_Finish;
const factory FileState.skip() = FileState_Skip;
const factory FileState.fail({
required String msg,
}) = FileState_Fail;
}

class MissionFileInfo {
final FileInfo info;
final FileState state;

const MissionFileInfo({
required this.info,
required this.state,
});

@override
int get hashCode => info.hashCode ^ state.hashCode;

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is MissionFileInfo &&
runtimeType == other.runtimeType &&
info == other.info &&
state == other.state;
}

class MissionInfo {
final String id;
final NodeDevice sender;
final List<MissionFileInfo> files;
final MissionState state;

const MissionInfo({
required this.id,
required this.sender,
required this.files,
required this.state,
});

@override
int get hashCode =>
id.hashCode ^ sender.hashCode ^ files.hashCode ^ state.hashCode;

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is MissionInfo &&
runtimeType == other.runtimeType &&
id == other.id &&
sender == other.sender &&
files == other.files &&
state == other.state;
}
Loading

0 comments on commit 24ad684

Please sign in to comment.