mirror of
https://github.com/DefinedNet/mobile_nebula.git
synced 2025-01-30 17:07:02 +00:00
ad45cc1d78
TODO: - [x] Address Android, which this probably breaks. Previously the back button was taking up all the room in the title bar, this fixes it so that we can see titles again. It also truncates site names so they stay to one line. |Before|After| |---|---| |![image](https://github.com/user-attachments/assets/3e07a50d-fb40-40da-87f8-4d623019b26d)|![Simulator 2025-01-23 16 32 34](https://github.com/user-attachments/assets/ea668973-e67d-4fc5-8731-578e5f3fdd27)| |Before|After| |---|---| |![image](https://github.com/user-attachments/assets/d95e1a9d-f431-42aa-a9f2-357b20c37abb)|![Simulator 2025-01-23 16 11 15](https://github.com/user-attachments/assets/ff3f664b-1983-4514-a492-cf585153e294)| |Before|After| |---|---| |![image](https://github.com/user-attachments/assets/0ea3aa0d-340a-44db-8a0a-e0c8032c2450)|![image](https://github.com/user-attachments/assets/fb7e26c5-5c67-4dd7-808c-d471ca1e913e)| |Before|After| |---|---| |![image](https://github.com/user-attachments/assets/bffec7e3-561d-4a43-ab8a-3bd1cc95003c)|![Simulator 2025-01-23 16 13 23](https://github.com/user-attachments/assets/288c1f7f-4d79-4b59-b693-0cbcdd2024db)| A few other "After" screenshots: |Logs|DN enrollment| |---|---| |![Simulator 2025-01-23 16 30 48](https://github.com/user-attachments/assets/4698939e-c4ad-4929-bd0b-1b72fc21c439)|![image](https://github.com/user-attachments/assets/4c738c41-af3c-4465-9907-76fce34ecdd9)|
133 lines
3.9 KiB
Dart
133 lines
3.9 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
|
import 'package:mobile_nebula/components/SimplePage.dart';
|
|
import 'package:mobile_nebula/models/Site.dart';
|
|
import 'package:mobile_nebula/services/settings.dart';
|
|
import 'package:mobile_nebula/services/share.dart';
|
|
import 'package:mobile_nebula/services/utils.dart';
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
|
|
import '../components/SiteTitle.dart';
|
|
|
|
class SiteLogsScreen extends StatefulWidget {
|
|
const SiteLogsScreen({Key? key, required this.site}) : super(key: key);
|
|
|
|
final Site site;
|
|
|
|
@override
|
|
_SiteLogsScreenState createState() => _SiteLogsScreenState();
|
|
}
|
|
|
|
class _SiteLogsScreenState extends State<SiteLogsScreen> {
|
|
String logs = '';
|
|
ScrollController controller = ScrollController();
|
|
RefreshController refreshController = RefreshController(initialRefresh: false);
|
|
|
|
var settings = Settings();
|
|
@override
|
|
void initState() {
|
|
loadLogs();
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final title = SiteTitle(site: widget.site);
|
|
|
|
return SimplePage(
|
|
title: title,
|
|
scrollable: SimpleScrollable.both,
|
|
scrollController: controller,
|
|
onRefresh: () async {
|
|
await loadLogs();
|
|
refreshController.refreshCompleted();
|
|
},
|
|
onLoading: () async {
|
|
await loadLogs();
|
|
refreshController.loadComplete();
|
|
},
|
|
refreshController: refreshController,
|
|
child: Container(
|
|
padding: EdgeInsets.all(5),
|
|
constraints: logBoxConstraints(context),
|
|
child: SelectableText(logs.trim(), style: TextStyle(fontFamily: 'RobotoMono', fontSize: 14))),
|
|
bottomBar: _buildBottomBar(),
|
|
);
|
|
}
|
|
|
|
Widget _buildBottomBar() {
|
|
var borderSide = BorderSide(
|
|
color: CupertinoColors.separator,
|
|
style: BorderStyle.solid,
|
|
width: 0.0,
|
|
);
|
|
|
|
var padding = Platform.isAndroid ? EdgeInsets.fromLTRB(0, 20, 0, 30) : EdgeInsets.all(10);
|
|
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
border: Border(top: borderSide),
|
|
),
|
|
child: Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
|
|
Expanded(child: Builder(builder: (BuildContext context) {
|
|
return PlatformIconButton(
|
|
padding: padding,
|
|
icon: Icon(context.platformIcons.share, size: 30),
|
|
onPressed: () {
|
|
Share.shareFile(context,
|
|
title: '${widget.site.name} logs',
|
|
filePath: widget.site.logFile,
|
|
filename: '${widget.site.name}.log');
|
|
},
|
|
);
|
|
})),
|
|
Expanded(
|
|
child: PlatformIconButton(
|
|
padding: padding,
|
|
icon: Icon(context.platformIcons.downArrow, size: 30),
|
|
onPressed: () async {
|
|
controller.animateTo(controller.position.maxScrollExtent,
|
|
duration: const Duration(milliseconds: 500), curve: Curves.linearToEaseOut);
|
|
},
|
|
)),
|
|
]));
|
|
}
|
|
|
|
loadLogs() async {
|
|
var file = File(widget.site.logFile);
|
|
try {
|
|
final v = await file.readAsString();
|
|
|
|
setState(() {
|
|
logs = v;
|
|
});
|
|
} on FileSystemException {
|
|
Utils.popError(context, 'Error while reading logs', 'No log file was present');
|
|
} catch (err) {
|
|
Utils.popError(context, 'Error while reading logs', err.toString());
|
|
}
|
|
}
|
|
|
|
deleteLogs() async {
|
|
var file = File(widget.site.logFile);
|
|
await file.writeAsBytes([]);
|
|
await loadLogs();
|
|
}
|
|
|
|
logBoxConstraints(BuildContext context) {
|
|
if (settings.logWrap) {
|
|
return BoxConstraints(maxWidth: MediaQuery.of(context).size.width);
|
|
} else {
|
|
return BoxConstraints(minWidth: MediaQuery.of(context).size.width);
|
|
}
|
|
}
|
|
}
|