diff --git a/app/Wissance.Zerial/Wissance.Zerial.Desktop/Managers/DeviceConfigurationManager.cs b/app/Wissance.Zerial/Wissance.Zerial.Desktop/Managers/DeviceConfigurationManager.cs index f6877f2..b03b84f 100644 --- a/app/Wissance.Zerial/Wissance.Zerial.Desktop/Managers/DeviceConfigurationManager.cs +++ b/app/Wissance.Zerial/Wissance.Zerial.Desktop/Managers/DeviceConfigurationManager.cs @@ -13,9 +13,9 @@ namespace Wissance.Zerial.Desktop.Managers { public class DeviceConfigurationManager { - public DeviceConfigurationManager(string configFile) + public DeviceConfigurationManager(string env, string configFile) { - try + if (env != Program.SnapEnvironmentKey) { bool result = PrepareDevConfigDirectory(configFile); if (!result) @@ -29,10 +29,6 @@ public DeviceConfigurationManager(string configFile) } } } - catch (Exception e) - { - // SNAP ASSHOLE!!! - } } public ObservableCollection Load() diff --git a/app/Wissance.Zerial/Wissance.Zerial.Desktop/Program.cs b/app/Wissance.Zerial/Wissance.Zerial.Desktop/Program.cs index c41e02e..f95a488 100644 --- a/app/Wissance.Zerial/Wissance.Zerial.Desktop/Program.cs +++ b/app/Wissance.Zerial/Wissance.Zerial.Desktop/Program.cs @@ -1,6 +1,7 @@ using Avalonia; using Avalonia.ReactiveUI; using System; +using System.Linq; namespace Wissance.Zerial.Desktop; @@ -10,8 +11,21 @@ class Program // SynchronizationContext-reliant code before AppMain is called: things aren't initialized // yet and stuff might break. [STAThread] - public static void Main(string[] args) => BuildAvaloniaApp() - .StartWithClassicDesktopLifetime(args); + public static void Main(string[] args) + { + string env = args.FirstOrDefault(a => a.Contains(EnvironmentKey)); + Environment = OtherEnvironmentKey; + if (env != null) + { + string[] parts = env.Split("="); + if (parts.Length == 2) + { + Environment = parts[1].ToLower() == SnapEnvironmentKey ? SnapEnvironmentKey : OtherEnvironmentKey; + } + } + + BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); + } // Avalonia configuration, don't remove; also used by visual designer. public static AppBuilder BuildAvaloniaApp() @@ -20,4 +34,10 @@ public static AppBuilder BuildAvaloniaApp() .WithInterFont() .LogToTrace() .UseReactiveUI(); + + public static string Environment { get; set; } + + public const string SnapEnvironmentKey = "snap"; + public const string OtherEnvironmentKey = "other"; + private const string EnvironmentKey = "environment"; } \ No newline at end of file diff --git a/app/Wissance.Zerial/Wissance.Zerial.Desktop/ViewModels/MainWindowViewModel.cs b/app/Wissance.Zerial/Wissance.Zerial.Desktop/ViewModels/MainWindowViewModel.cs index 5a8fb5b..750f109 100644 --- a/app/Wissance.Zerial/Wissance.Zerial.Desktop/ViewModels/MainWindowViewModel.cs +++ b/app/Wissance.Zerial/Wissance.Zerial.Desktop/ViewModels/MainWindowViewModel.cs @@ -36,7 +36,7 @@ public MainWindowViewModel() SelectedPortNumber = Ports.Any() ? Ports.First() : null; _deviceManager = new MultiDeviceRs232Manager(OnSerialDeviceDataReceived, new LoggerFactory()); _serialDevices = new List(); - _configurationManager = new DeviceConfigurationManager("devices.json"); + _configurationManager = new DeviceConfigurationManager(Program.Environment, "devices.json"); DevicesConfigs = _configurationManager.Load(); // these init depends on loaded configuration foreach (SerialPortShortInfoModel config in DevicesConfigs) diff --git a/snapcraft.yaml b/snapcraft.yaml index fd18f0b..d1f569a 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -34,4 +34,4 @@ apps: plugs: - desktop - desktop-legacy - command: ./Wissance.Zerial.Desktop + command: ./Wissance.Zerial.Desktop --environment=snap