Skip to content

Commit b02739c

Browse files
fix two of the remaining todos :D
1 parent b69cb42 commit b02739c

File tree

5 files changed

+29
-18
lines changed

5 files changed

+29
-18
lines changed

lib/bloc/process_bloc/process_bloc.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ class ProcessBloc extends Bloc<ProcessEvent, ProcessState> {
200200
);
201201
} else if (event is ProcessError) {
202202
yield state.copyWith(current: state.current, exitCode: event.exitCode);
203+
} else if (event is ResetProcessError) {
204+
yield state.copyWith(current: state.current, exitCode: 0);
203205
} else if (event is ProcessOnNetwork) {
204206
yield* _extractOnNetwork(
205207
event.type, event.location, event.tcppassword, event.tcpdesc);

lib/bloc/process_bloc/process_event.dart

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,41 @@ class ProcessFilesSubmitted extends ProcessEvent {
1313

1414
class ProcessStarted extends ProcessEvent {}
1515

16-
/// ProcessStopped stops all the files from processing after finishing the
17-
/// current one. Maybe use process.kill for this?
16+
/// ProcessStopped stops all the files from processing.
1817
class ProcessStopped extends ProcessEvent {}
1918

19+
/// Removes pending file from state queue
2020
class ProcessFileRemoved extends ProcessEvent {
2121
final XFile file;
2222

2323
const ProcessFileRemoved(this.file);
2424
}
2525

26+
/// Stops ccx on a file using .kill()
2627
class ProcessKill extends ProcessEvent {
2728
final XFile file;
2829

2930
const ProcessKill(this.file);
3031
}
3132

33+
/// Remvoes all files from selected and stops ccx on any running file
3234
class ProcessRemoveAll extends ProcessEvent {}
3335

36+
/// Used in callback when ccx emits logs to stderr
3437
class ProcessFileExtractorOutput extends ProcessEvent {
3538
final String log;
3639

3740
const ProcessFileExtractorOutput(this.log);
3841
}
3942

43+
/// Used in callback when ccx emits video details to stderr
4044
class ProcessFileVideoDetails extends ProcessEvent {
4145
final List<String> videoDetails;
4246

4347
ProcessFileVideoDetails(this.videoDetails);
4448
}
4549

50+
/// Used in callback when ccx emits progress details to stderr
4651
class ProcessFileExtractorProgress extends ProcessEvent {
4752
final String progress;
4853

@@ -55,11 +60,13 @@ class ProcessFileComplete extends ProcessEvent {
5560
const ProcessFileComplete(this.file);
5661
}
5762

63+
// emits a state with exit codes to show in snackbar
5864
class ProcessError extends ProcessEvent {
5965
final int exitCode;
6066
const ProcessError(this.exitCode);
6167
}
6268

69+
// Runs tcp udp stuff in ccx
6370
class ProcessOnNetwork extends ProcessEvent {
6471
final String type;
6572
final String location;
@@ -73,4 +80,8 @@ class ProcessOnNetwork extends ProcessEvent {
7380
required this.tcpdesc});
7481
}
7582

83+
// Gets the ccextractor version using `--version`
7684
class GetCCExtractorVersion extends ProcessEvent {}
85+
86+
// Resets exitcode to 0, ideally should be null but wont emit a new state then
87+
class ResetProcessError extends ProcessEvent {}

lib/main.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ class MyApp extends StatelessWidget {
6666

6767
// Logs events and states during transition
6868
class SimpleBlocObserver extends BlocObserver {
69-
// @override
70-
// void onTransition(Bloc bloc, Transition transition) {
71-
// print(transition);
72-
// super.onTransition(bloc, transition);
73-
// }
69+
@override
70+
void onTransition(Bloc bloc, Transition transition) {
71+
print(transition);
72+
super.onTransition(bloc, transition);
73+
}
7474

7575
@override
7676
void onError(BlocBase bloc, Object error, StackTrace stackTrace) {

lib/repositories/settings_repository.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,16 @@ class SettingsRepository {
3636
throw Exception('Setting key not found');
3737
}
3838
}
39-
// This checks if all the values are of the intended datatype. TODO
40-
if (outputFormats.contains(data['out']) &&
41-
data['outputfilename'] is String &&
42-
data['append'] is bool &&
43-
data['autoprogram'] is bool) {
44-
} else {
45-
throw Exception('Settings value has mismatched datatype');
39+
// This checks if all the values are of the intended datatype, by setting the current data to a settingsModel object
40+
try {
41+
// ignore: unused_local_variable
42+
final _settingsModel = SettingsModel.fromJson(data);
43+
} catch (e) {
44+
throw Exception('Settings value has mismatched datatype. Error $e');
4645
}
4746
return true;
4847
} catch (e) {
49-
print('Rewriting config.json file');
48+
print('Rewriting config.json file. Error $e');
5049
await file.writeAsString(jsonEncode(SettingsModel()));
5150
return false;
5251
}

lib/screens/dashboard/dashboard.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,11 @@ class ClearFilesButton extends StatelessWidget {
5252
@override
5353
Widget build(BuildContext context) {
5454
return BlocConsumer<ProcessBloc, ProcessState>(
55-
listenWhen: (_, __) => true,
5655
listener: (context, processState) {
57-
//TODO: fix only works the first time, bloc wont emit same state
58-
if (CCExtractor.exitCodes[processState.exitCode] != null) {
56+
if (CCExtractor.exitCodes[processState.exitCode] != null && processState.exitCode != 0) {
5957
CustomSnackBarMessage.show(
6058
context, CCExtractor.exitCodes[processState.exitCode]!);
59+
context.read<ProcessBloc>().add(ResetProcessError());
6160
}
6261
},
6362
builder: (context, processState) {

0 commit comments

Comments
 (0)