Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show log file location on desktop #2111

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 56 additions & 0 deletions mobile/lib/common/more_info.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get_10101/common/color.dart';
import 'package:get_10101/common/snack_bar.dart';

Widget moreInfo(BuildContext context,
{required String title, required String info, bool showCopyButton = false}) {
return Container(
padding: const EdgeInsets.all(15),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style:
const TextStyle(fontSize: 17, fontWeight: FontWeight.w400, color: Colors.black),
),
const SizedBox(
height: 7,
),
showCopyButton
? SizedBox(
width: MediaQuery.of(context).size.width - 100,
child: Text(
info,
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.w300, color: Colors.grey.shade700),
))
: const SizedBox()
],
),
showCopyButton
? GestureDetector(
onTap: () async {
showSnackBar(ScaffoldMessenger.of(context), "Copied $info");
await Clipboard.setData(ClipboardData(text: info));
},
child: Icon(
Icons.copy,
size: 17,
color: tenTenOnePurple.shade800,
),
)
: Text(
info,
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.w300, color: Colors.grey.shade700),
)
],
),
);
}
57 changes: 1 addition & 56 deletions mobile/lib/common/settings/app_info_screen.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get_10101/common/color.dart';
import 'package:get_10101/common/more_info.dart';
import 'package:get_10101/common/settings/open_telegram.dart';
import 'package:get_10101/common/settings/settings_screen.dart';
import 'package:get_10101/common/snack_bar.dart';
import 'package:get_10101/logger/logger.dart';

import 'package:go_router/go_router.dart';

import 'package:package_info_plus/package_info_plus.dart';
import 'package:get_10101/ffi.dart' as rust;
import 'package:url_launcher/url_launcher.dart';
Expand Down Expand Up @@ -230,55 +227,3 @@ class _AppInfoScreenState extends State<AppInfoScreen> {
);
}
}

Widget moreInfo(BuildContext context,
{required String title, required String info, bool showCopyButton = false}) {
return Container(
padding: const EdgeInsets.all(15),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style:
const TextStyle(fontSize: 17, fontWeight: FontWeight.w400, color: Colors.black),
),
const SizedBox(
height: 7,
),
showCopyButton
? SizedBox(
width: MediaQuery.of(context).size.width - 100,
child: Text(
info,
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.w300, color: Colors.grey.shade700),
))
: const SizedBox()
],
),
showCopyButton
? GestureDetector(
onTap: () async {
showSnackBar(ScaffoldMessenger.of(context), "Copied $info");
await Clipboard.setData(ClipboardData(text: info));
},
child: Icon(
Icons.copy,
size: 17,
color: tenTenOnePurple.shade800,
),
)
: Text(
info,
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.w300, color: Colors.grey.shade700),
)
],
),
);
}
96 changes: 59 additions & 37 deletions mobile/lib/common/settings/share_logs_screen.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'dart:convert';
import 'dart:io';

import 'package:flutter/foundation.dart' show defaultTargetPlatform, TargetPlatform;
import 'package:flutter/material.dart';
import 'package:get_10101/common/application/switch.dart';
import 'package:get_10101/common/color.dart';
import 'package:get_10101/common/more_info.dart';
import 'package:get_10101/common/settings/settings_screen.dart';
import 'package:get_10101/logger/hybrid_logger.dart';
import 'package:get_10101/logger/logger.dart';
Expand Down Expand Up @@ -84,44 +86,64 @@ class _ShareLogsScreenState extends State<ShareLogsScreen> {
const SizedBox(
height: 20,
),
GestureDetector(
onTap: () async {
logger.toString();
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
FutureBuilder(
future: HybridOutput.logFilePath(),
builder: (BuildContext context, AsyncSnapshot<File> snapshot) {
switch (defaultTargetPlatform) {
case TargetPlatform.android:
case TargetPlatform.iOS:
return GestureDetector(
onTap: () async {
logger.toString();

var file = await HybridOutput.logFilePath();
var logsAsString = await file.readAsString();
final List<int> bytes = utf8.encode(logsAsString);
final Directory tempDir = await getTemporaryDirectory();
String now = DateFormat('yyyy-MM-dd_HHmmss').format(DateTime.now());
final String filePath = '${tempDir.path}/$now.log';
await File(filePath).writeAsBytes(bytes);
final XFile logFile = XFile(filePath);
Share.shareXFiles([logFile], text: 'Logs from $now');
},
child: Container(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 20),
decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.circular(15)),
child: Row(
children: [
Icon(
Icons.ios_share_outlined,
color: tenTenOnePurple.shade800,
size: 22,
),
const SizedBox(
width: 20,
),
Text(
"Share Logs",
style: TextStyle(
color: tenTenOnePurple.shade800,
fontSize: 16,
fontWeight: FontWeight.w500),
)
],
),
),
var logsAsString = await snapshot.data!.readAsString();
final List<int> bytes = utf8.encode(logsAsString);
final Directory tempDir = await getTemporaryDirectory();
String now =
DateFormat('yyyy-MM-dd_HHmmss').format(DateTime.now());
final String filePath = '${tempDir.path}/$now.log';
await File(filePath).writeAsBytes(bytes);
final XFile logFile = XFile(filePath);
Share.shareXFiles([logFile], text: 'Logs from $now');
},
child: Container(
padding:
const EdgeInsets.symmetric(vertical: 10, horizontal: 20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(15)),
child: Row(
children: [
Icon(
Icons.ios_share_outlined,
color: tenTenOnePurple.shade800,
size: 22,
),
const SizedBox(
width: 20,
),
Text(
"Share Logs",
style: TextStyle(
color: tenTenOnePurple.shade800,
fontSize: 16,
fontWeight: FontWeight.w500),
)
],
),
),
);
default:
return moreInfo(context,
title: "Log file location",
info: snapshot.data!.path,
showCopyButton: true);
}
}),
],
),
const SizedBox(height: 20),
Container(
Expand Down