From f450dc35b171c7028cc53f6c0558cbd53eae9548 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Tue, 25 Aug 2026 17:31:50 +0200 Subject: [PATCH] Weighing: Add option to opt-out of automatic datetime sync at startup --- Elwig/App.xaml.cs | 2 +- Elwig/Helpers/Config.cs | 8 ++++++-- Installer/Files/config.ini | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Elwig/App.xaml.cs b/Elwig/App.xaml.cs index 45f7d80..d723e83 100644 --- a/Elwig/App.xaml.cs +++ b/Elwig/App.xaml.cs @@ -146,7 +146,7 @@ namespace Elwig { foreach (var s in Config.Scales) { try { var scale = Scale.FromConfig(s); - if (scale is ICommandScale cmd) { + if (s.SyncTime && scale is ICommandScale cmd) { try { await cmd.SetDateAndTime(DateTime.Now); } catch { } diff --git a/Elwig/Helpers/Config.cs b/Elwig/Helpers/Config.cs index c0afe05..8341273 100644 --- a/Elwig/Helpers/Config.cs +++ b/Elwig/Helpers/Config.cs @@ -17,10 +17,11 @@ namespace Elwig.Helpers { public string? Filling; public string? Limit; public bool Required; + public bool SyncTime; public string? Log; public string? _Log; - public ScaleConfig(string id, string? type, string? model, string? cnx, string? empty, string? filling, string? limit, bool? required, string? log) { + public ScaleConfig(string id, string? type, string? model, string? cnx, string? empty, string? filling, string? limit, bool? required, bool? syncTime, string? log) { Id = id; Type = type; Model = model; @@ -29,6 +30,7 @@ namespace Elwig.Helpers { Filling = filling; Limit = limit; Required = required ?? true; + SyncTime = syncTime ?? true; _Log = log; Log = log != null ? Path.Combine(App.DataPath, log) : null; } @@ -37,11 +39,12 @@ namespace Elwig.Helpers { public class Config { private static readonly string[] TrueValues = ["1", "true", "yes", "on"]; + private static readonly string[] FalseValues = ["0", "false", "no", "off"]; private readonly string FileName; public bool Debug; - public string DatabaseFile = App.DataPath + "database.sqlite3"; + public string DatabaseFile = Path.Combine(App.DataPath, "database.sqlite3"); public string? DatabaseLog = null; public string? Branch = null; public WeighingMode? WeighingMode; @@ -105,6 +108,7 @@ namespace Elwig.Helpers { s, config[$"scale.{s}:type"], config[$"scale.{s}:model"], config[$"scale.{s}:connection"], config[$"scale.{s}:empty"], config[$"scale.{s}:filling"], config[$"scale.{s}:limit"], config[$"scale.{s}:required"] != null ? TrueValues.Contains(config[$"scale.{s}:required"]?.ToLower()) : null, + config[$"scale.{s}:synctime"] != null ? !FalseValues.Contains(config[$"scale.{s}:synctime"]?.ToLower()) : null, config[$"scale.{s}:log"] )); } diff --git a/Installer/Files/config.ini b/Installer/Files/config.ini index 6db0edf..7fc584c 100644 --- a/Installer/Files/config.ini +++ b/Installer/Files/config.ini @@ -38,6 +38,8 @@ auto = true ;limit = 3500 ; Enables scale logging ;log = waage.log +; Opt-out of auto time synchronization at startup +;synctime = false ;[scale.B] ;type = Avery-Async