Add logLocalTZ to app settings
Allow users to configure their log timezone for all sites. Advances #2 Closes #8
This commit is contained in:
parent
e844e2c195
commit
4ea602eeef
|
@ -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'),
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue