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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
List<Widget> colorSection = [];
|
List<Widget> colorSection = [];
|
||||||
|
List<Widget> logSection = [];
|
||||||
|
|
||||||
|
// System Color Configs
|
||||||
colorSection.add(ConfigItem(
|
colorSection.add(ConfigItem(
|
||||||
label: Text('Use system colors'),
|
label: Text('Use system colors'),
|
||||||
labelWidth: 200,
|
labelWidth: 200,
|
||||||
|
@ -63,10 +65,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||||
)),
|
)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
// Log Configs
|
||||||
List<Widget> items = [];
|
logSection.add(ConfigItem(
|
||||||
items.add(ConfigSection(children: colorSection));
|
|
||||||
items.add(ConfigItem(
|
|
||||||
label: Text('Wrap log output'),
|
label: Text('Wrap log output'),
|
||||||
labelWidth: 200,
|
labelWidth: 200,
|
||||||
content: Align(
|
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: [
|
items.add(ConfigSection(children: [
|
||||||
ConfigPageItem(
|
ConfigPageItem(
|
||||||
label: Text('About'),
|
label: Text('About'),
|
||||||
|
|
|
@ -103,8 +103,11 @@ class _SiteLogsScreenState extends State<SiteLogsScreen> {
|
||||||
loadLogs() async {
|
loadLogs() async {
|
||||||
var file = File(widget.site.logFile);
|
var file = File(widget.site.logFile);
|
||||||
try {
|
try {
|
||||||
final v = await file.readAsString();
|
String v = await file.readAsString();
|
||||||
|
|
||||||
|
if (settings.logLocalTZ) {
|
||||||
|
v = convertToLocalTZ(v);
|
||||||
|
}
|
||||||
setState(() {
|
setState(() {
|
||||||
logs = v;
|
logs = v;
|
||||||
});
|
});
|
||||||
|
@ -126,4 +129,12 @@ class _SiteLogsScreenState extends State<SiteLogsScreen> {
|
||||||
return BoxConstraints(minWidth: MediaQuery.of(context).size.width);
|
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);
|
_set('logWrap', enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool get logLocalTZ {
|
||||||
|
return _getBool('logLocalTZ', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
set logLocalTZ(bool enabled) {
|
||||||
|
_set('logLocalTZ', enabled);
|
||||||
|
}
|
||||||
|
|
||||||
String _getString(String key, String defaultValue) {
|
String _getString(String key, String defaultValue) {
|
||||||
final val = _settings[key];
|
final val = _settings[key];
|
||||||
if (val is String) {
|
if (val is String) {
|
||||||
|
|
Loading…
Reference in New Issue