Add logLocalTZ to app settings

Allow users to configure their log timezone for all sites.

Advances #2
Closes #8
This commit is contained in:
micha3lbrown 2021-02-05 16:37:11 -05:00
parent e844e2c195
commit 4ea602eeef
No known key found for this signature in database
GPG Key ID: 3F02D82B487AD431
3 changed files with 43 additions and 5 deletions

View File

@ -34,7 +34,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
@override
Widget build(BuildContext context) {
List<Widget> colorSection = [];
List<Widget> logSection = [];
// System Color Configs
colorSection.add(ConfigItem(
label: Text('Use system colors'),
labelWidth: 200,
@ -63,10 +65,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
)),
));
}
List<Widget> items = [];
items.add(ConfigSection(children: colorSection));
items.add(ConfigItem(
// Log Configs
logSection.add(ConfigItem(
label: Text('Wrap log output'),
labelWidth: 200,
content: Align(
@ -81,6 +81,25 @@ class _SettingsScreenState extends State<SettingsScreen> {
},
)),
));
logSection.add(ConfigItem(
label: Text('Use Local Time Zone'),
labelWidth: 200,
content: Align(
alignment: Alignment.centerRight,
child: Switch.adaptive(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
value: settings.logLocalTZ,
onChanged: (value) {
setState(() {
settings.logLocalTZ = value;
});
},
)),
));
List<Widget> items = [];
items.add(ConfigSection(children: colorSection));
items.add(ConfigSection(children: logSection));
items.add(ConfigSection(children: [
ConfigPageItem(
label: Text('About'),

View File

@ -103,8 +103,11 @@ class _SiteLogsScreenState extends State<SiteLogsScreen> {
loadLogs() async {
var file = File(widget.site.logFile);
try {
final v = await file.readAsString();
String v = await file.readAsString();
if (settings.logLocalTZ) {
v = convertToLocalTZ(v);
}
setState(() {
logs = v;
});
@ -126,4 +129,12 @@ class _SiteLogsScreenState extends State<SiteLogsScreen> {
return BoxConstraints(minWidth: MediaQuery.of(context).size.width);
}
}
convertToLocalTZ(String rawLog) {
rawLog = rawLog.replaceAllMapped(RegExp('time="(.*?)"'), (match) {
DateTime userDate = DateTime.parse(match.group(1));
return 'time="${userDate.toLocal().toIso8601String()}"';
});
return rawLog;
}
}

View File

@ -38,6 +38,14 @@ class Settings {
_set('logWrap', enabled);
}
bool get logLocalTZ {
return _getBool('logLocalTZ', false);
}
set logLocalTZ(bool enabled) {
_set('logLocalTZ', enabled);
}
String _getString(String key, String defaultValue) {
final val = _settings[key];
if (val is String) {