potential electrum fixes + mweb logs display only last 10000 characters

This commit is contained in:
Matthew Fosse 2024-10-24 09:08:39 -07:00
parent 7874675edd
commit 87cca2db54
3 changed files with 35 additions and 0 deletions

View file

@ -132,6 +132,7 @@ class ElectrumClient {
if (host == socket?.address.host || socket == null) {
_setConnectionStatus(ConnectionStatus.disconnected);
socket?.destroy();
socket = null;
}
} catch (e) {
print("onDone: $e");

View file

@ -26,6 +26,29 @@ class MwebLogsPage extends BasePage {
return Stack(
fit: StackFit.expand,
children: [
Expanded(
child: FutureBuilder<String>(
future: mwebSettingsViewModelBase.getAbbreviatedLogs(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(child: CircularProgressIndicator());
} else if (snapshot.hasError || !snapshot.hasData || snapshot.data!.isEmpty) {
return Center(child: Text('No logs found'));
} else {
return SingleChildScrollView(
child: Padding(
padding: EdgeInsets.all(16.0),
child: Text(
snapshot.data!,
style: TextStyle(fontFamily: 'Monospace'),
),
),
);
}
},
),
),
Positioned(
child: Observer(
builder: (_) => LoadingPrimaryButton(

View file

@ -46,6 +46,17 @@ abstract class MwebSettingsViewModelBase with Store {
await logsFile.copy(filePath);
}
Future<String> getAbbreviatedLogs() async {
final appSupportPath = (await getApplicationSupportDirectory()).path;
final logsFile = File("$appSupportPath/logs/debug.log");
if (!logsFile.existsSync()) {
return "";
}
final logs = logsFile.readAsStringSync();
// return last 10000 characters:
return logs.substring(logs.length > 10000 ? logs.length - 10000 : 0);
}
Future<void> removeLogsLocally(String filePath) async {
final logsFile = File(filePath);
if (logsFile.existsSync()) {