Skip to content

Commit 4734719

Browse files
add important logs from stdout and stderr not subs/progress to dashboard
1 parent b02739c commit 4734719

File tree

5 files changed

+39
-19
lines changed

5 files changed

+39
-19
lines changed

lib/bloc/process_bloc/process_bloc.dart

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ class ProcessBloc extends Bloc<ProcessEvent, ProcessState> {
118118
);
119119
yield* _extractNext();
120120
} else if (event is ProcessStopped) {
121-
_extractor.cancelRun();
121+
// stops everything
122+
try {
123+
_extractor.cancelRun();
124+
} on Exception catch (_) {}
122125
yield state.copyWith(
123126
current: null,
124127
queue: state.orignalList,
@@ -127,7 +130,9 @@ class ProcessBloc extends Bloc<ProcessEvent, ProcessState> {
127130
started: false,
128131
);
129132
} else if (event is ProcessKill) {
130-
_extractor.cancelRun();
133+
try {
134+
_extractor.cancelRun();
135+
} on Exception catch (_) {}
131136
yield state.copyWith(
132137
current: state.current,
133138
orignalList: state.orignalList
@@ -136,14 +141,19 @@ class ProcessBloc extends Bloc<ProcessEvent, ProcessState> {
136141
queue: state.queue.where((element) => element != event.file).toList(),
137142
);
138143
} else if (event is ProcessRemoveAll) {
139-
_extractor.cancelRun();
144+
try {
145+
_extractor.cancelRun();
146+
} on Exception catch (_) {}
140147
yield state.copyWith(
141148
current: null,
142149
progress: '0',
143150
processed: [],
144151
queue: [],
145152
orignalList: [],
146153
started: false,
154+
exitCode: null,
155+
log: [],
156+
videoDetails: [],
147157
);
148158
} else if (event is ProcessFileExtractorProgress) {
149159
yield state.copyWith(current: state.current, progress: event.progress);
@@ -159,7 +169,9 @@ class ProcessBloc extends Bloc<ProcessEvent, ProcessState> {
159169
if (state.current == event.file) {
160170
yield state.copyWith(
161171
current: null,
172+
log: state.queue.isNotEmpty ? [] : state.log,
162173
processed: state.processed.followedBy([event.file]).toList(),
174+
exitCode: null,
163175
);
164176
yield* _extractNext();
165177
}
@@ -201,7 +213,7 @@ class ProcessBloc extends Bloc<ProcessEvent, ProcessState> {
201213
} else if (event is ProcessError) {
202214
yield state.copyWith(current: state.current, exitCode: event.exitCode);
203215
} else if (event is ResetProcessError) {
204-
yield state.copyWith(current: state.current, exitCode: 0);
216+
yield state.copyWith(current: state.current, exitCode: null);
205217
} else if (event is ProcessOnNetwork) {
206218
yield* _extractOnNetwork(
207219
event.type, event.location, event.tcppassword, event.tcpdesc);

lib/bloc/process_bloc/process_state.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class ProcessState extends Equatable {
4646
videoDetails: videoDetails ?? this.videoDetails,
4747
version: version ?? this.version,
4848
current: current,
49-
exitCode: exitCode ?? this.exitCode);
49+
exitCode: exitCode);
5050

5151
@override
5252
List<Object?> get props => [

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/ccextractor.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import 'package:file_selector/file_selector.dart';
66
import 'package:ccxgui/models/settings_model.dart';
77
import 'package:ccxgui/repositories/settings_repository.dart';
88

9-
enum NETWORK_TYPE { udp, tcp }
10-
119
class CCExtractor {
1210
late Process process;
1311
final RegExp progressRegx = RegExp(r'###PROGRESS#(\d+)', multiLine: true);
@@ -39,13 +37,16 @@ class CCExtractor {
3937
...paramsList,
4038
],
4139
);
42-
40+
// sometimes stdout and stderr have important logs like how much time
41+
// it took to process the file or some erros not captured by exitcodes,
42+
// so just print them to the logs box
4343
process.stdout.transform(latin1.decoder).listen((update) {
44-
print(update);
44+
// print(update);
45+
listenOutput(update);
4546
});
4647

4748
process.stderr.transform(latin1.decoder).listen((update) {
48-
print(update);
49+
// print(update);
4950
if (progressRegx.hasMatch(update)) {
5051
for (RegExpMatch i in progressRegx.allMatches(update)) {
5152
listenProgress(i[1]!);
@@ -65,6 +66,7 @@ class CCExtractor {
6566
listenVideoDetails(i[1]!.split('#'));
6667
}
6768
}
69+
update.contains('Error') ? listenOutput(update) : print(update);
6870
});
6971
return process.exitCode;
7072
}
@@ -93,11 +95,11 @@ class CCExtractor {
9395
);
9496

9597
process.stdout.transform(latin1.decoder).listen((update) {
96-
print(update);
98+
//print(update);
99+
listenOutput(update);
97100
});
98101

99102
process.stderr.transform(latin1.decoder).listen((update) {
100-
print(update);
101103
if (progressRegx.hasMatch(update)) {
102104
for (RegExpMatch i in progressRegx.allMatches(update)) {
103105
listenProgress(i[1]!);
@@ -117,6 +119,7 @@ class CCExtractor {
117119
listenVideoDetails(i[1]!.split('#'));
118120
}
119121
}
122+
update.contains('Error') ? listenOutput(update) : print(update);
120123
});
121124
return process.exitCode;
122125
}

lib/screens/dashboard/dashboard.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,16 @@ class ClearFilesButton extends StatelessWidget {
5252
@override
5353
Widget build(BuildContext context) {
5454
return BlocConsumer<ProcessBloc, ProcessState>(
55+
listenWhen: (previous, current) =>
56+
previous.exitCode !=
57+
current
58+
.exitCode, // we reset the exit code everytime so listen only when a new version actually comes not from some other state change before reset error code state comes
5559
listener: (context, processState) {
56-
if (CCExtractor.exitCodes[processState.exitCode] != null && processState.exitCode != 0) {
60+
if (CCExtractor.exitCodes[processState.exitCode] != null &&
61+
processState.exitCode != 0) {
5762
CustomSnackBarMessage.show(
5863
context, CCExtractor.exitCodes[processState.exitCode]!);
59-
context.read<ProcessBloc>().add(ResetProcessError());
64+
context.read<ProcessBloc>().add(ResetProcessError());
6065
}
6166
},
6267
builder: (context, processState) {

0 commit comments

Comments
 (0)