forked from firka/firka
settings: add log file sharing
This commit is contained in:
@@ -285,6 +285,7 @@ class SettingsStore {
|
||||
l10n.s_stats_for_nerds,
|
||||
false,
|
||||
always),
|
||||
"logs": SettingsLogs(0, always),
|
||||
}),
|
||||
isDeveloper),
|
||||
|
||||
@@ -723,6 +724,29 @@ class SettingsKretenAccountPicker implements SettingsItem {
|
||||
}
|
||||
}
|
||||
|
||||
class SettingsLogs implements SettingsItem {
|
||||
@override
|
||||
Id key;
|
||||
@override
|
||||
FirkaIconType? iconType;
|
||||
@override
|
||||
Object? iconData;
|
||||
@override
|
||||
bool Function() visibilityProvider;
|
||||
@override
|
||||
Future<void> Function() postUpdate = () async {};
|
||||
String title = "";
|
||||
String icon = "";
|
||||
|
||||
SettingsLogs(this.key, this.visibilityProvider);
|
||||
|
||||
@override
|
||||
Future<void> load(IsarCollection<AppSettingsModel> model) async {}
|
||||
|
||||
@override
|
||||
Future<void> save(IsarCollection<AppSettingsModel> model) async {}
|
||||
}
|
||||
|
||||
class SettingsAppIconPicker implements SettingsItem {
|
||||
@override
|
||||
Id key;
|
||||
|
||||
@@ -64,6 +64,7 @@ class DeviceInfo {
|
||||
|
||||
class AppInitialization {
|
||||
final Isar isar;
|
||||
final Directory appDir;
|
||||
final PackageInfo packageInfo;
|
||||
final DeviceInfo devInfo;
|
||||
late KretaClient client;
|
||||
@@ -76,6 +77,7 @@ class AppInitialization {
|
||||
|
||||
AppInitialization({
|
||||
required this.isar,
|
||||
required this.appDir,
|
||||
required this.devInfo,
|
||||
required this.packageInfo,
|
||||
required this.tokens,
|
||||
@@ -229,6 +231,7 @@ Future<AppInitialization> initializeApp() async {
|
||||
|
||||
var init = AppInitialization(
|
||||
isar: isar,
|
||||
appDir: await getApplicationDocumentsDirectory(),
|
||||
devInfo: devInfo,
|
||||
packageInfo: await PackageInfo.fromPlatform(),
|
||||
tokens: tokens,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'dart:collection';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
|
||||
import 'package:firka/helpers/db/models/app_settings_model.dart';
|
||||
@@ -11,6 +12,8 @@ import 'package:firka/ui/widget/firka_icon.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
import '../../../../helpers/firka_bundle.dart';
|
||||
import '../../../../helpers/firka_state.dart';
|
||||
@@ -576,6 +579,76 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
));
|
||||
continue;
|
||||
}
|
||||
if (item is SettingsLogs) {
|
||||
final logFileRegex = RegExp(r'^(\d{4})_(\d{2})_(\d{2})\.log$');
|
||||
|
||||
for (final entity in widget.data.appDir.listSync()) {
|
||||
if (entity is! File) continue;
|
||||
final name = entity.uri.pathSegments.last;
|
||||
final m = logFileRegex.firstMatch(name);
|
||||
if (m == null) continue;
|
||||
|
||||
widgets.add(GestureDetector(
|
||||
child: SizedBox(
|
||||
height: 52,
|
||||
child: FirkaCard(
|
||||
left: [
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.noteTextSolid,
|
||||
color: appStyle.colors.accent,
|
||||
),
|
||||
Text(
|
||||
name,
|
||||
style: appStyle.fonts.B_16R
|
||||
.apply(color: appStyle.colors.textPrimary),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
onTap: () async {
|
||||
try {
|
||||
logger.info("Compressing log file: ${entity.path}");
|
||||
final original = File(entity.path);
|
||||
final originalBytes = await original.readAsBytes();
|
||||
final gzBytes = GZipCodec().encode(originalBytes);
|
||||
final tempDir = await Directory.systemTemp.createTemp('firka');
|
||||
final gzPath =
|
||||
p.join(tempDir.path, '${p.basename(entity.path)}.gz');
|
||||
final gzFile =
|
||||
await File(gzPath).writeAsBytes(gzBytes, flush: true);
|
||||
|
||||
final params = ShareParams(
|
||||
text: name,
|
||||
files: [XFile(gzFile.path, mimeType: 'application/gzip')],
|
||||
);
|
||||
|
||||
await SharePlus.instance.share(params);
|
||||
|
||||
await gzFile.delete();
|
||||
await tempDir.delete();
|
||||
} catch (ex) {
|
||||
if (ex is Error) {
|
||||
logger.shout("Failed to compress log file", ex.toString(),
|
||||
ex.stackTrace);
|
||||
} else {
|
||||
logger.shout("Failed to compress log file", ex.toString());
|
||||
}
|
||||
|
||||
logger.info("Sharing regular log file instead: ${entity.path}");
|
||||
final params = ShareParams(
|
||||
text: name,
|
||||
files: [XFile(entity.path, mimeType: 'text/plain')],
|
||||
);
|
||||
|
||||
await SharePlus.instance.share(params);
|
||||
}
|
||||
},
|
||||
));
|
||||
widgets.add(SizedBox(height: 8));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return widgets;
|
||||
|
||||
@@ -67,6 +67,7 @@ dependencies:
|
||||
smart_scroll: ^1.0.0
|
||||
live_activities: ^2.4.1
|
||||
logging: ^1.3.0
|
||||
share_plus: ^11.1.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user