public void Handle(AppSettingsMessage message) { var settings = message.Settings; if (message.Action == SettingsAction.Loading) { DisablePopup = settings.TryGetValue(nameof(DisablePopup), out var disablePopupToken) && disablePopupToken.Value <bool>(); if (!DisablePopup) { Execute.PostToUIThread(async() => { var result = await DialogHelper.ShowAsync(new InformationMessageDialogViewModel(showCheckbox: true), "RootDialog").ConfigureAwait(true); if (result is not bool disablePopup) { return; } DisablePopup = disablePopup; }); } } else if (message.Action == SettingsAction.Saving) { settings[nameof(DisablePopup)] = DisablePopup; } }
public void Handle(AppSettingsMessage message) { if (message.Action == SettingsAction.Saving) { if (!message.Settings.EnsureContainsObjects("MediaSource") || !message.Settings.TryGetObject(out var settings, "MediaSource")) { return; } settings[nameof(ContentVisible)] = ContentVisible; settings[nameof(ScanDelay)] = ScanDelay; settings[nameof(ScanInterval)] = ScanInterval; if (ActiveItem != null) { settings[nameof(ActiveItem)] = ActiveItem.Name; } } else if (message.Action == SettingsAction.Loading) { if (!message.Settings.TryGetObject(out var settings, "MediaSource")) { return; } if (settings.TryGetValue <bool>(nameof(ContentVisible), out var contentVisible)) { ContentVisible = contentVisible; } if (settings.TryGetValue <int>(nameof(ScanDelay), out var scanDelay)) { ScanDelay = scanDelay; } if (settings.TryGetValue <int>(nameof(ScanInterval), out var scanInterval)) { ScanInterval = scanInterval; } if (settings.TryGetValue <string>(nameof(ActiveItem), out var selectedItem)) { ChangeActiveItem(Items.FirstOrDefault(x => string.Equals(x.Name, selectedItem)) ?? Items[0], closePrevious: false); } } }
public void Handle(AppSettingsMessage message) { if (message.Action == SettingsAction.Saving) { if (!message.Settings.EnsureContainsObjects("OutputTarget") || !message.Settings.TryGetObject(out var settings, "OutputTarget")) { return; } settings[nameof(ContentVisible)] = ContentVisible; settings[nameof(ScanDelay)] = ScanDelay; settings[nameof(ScanInterval)] = ScanInterval; if (ActiveItem != null) { settings[nameof(ActiveItem)] = ActiveItem.Identifier; } settings[nameof(Items)] = JArray.FromObject(Items.Select(x => { var o = new JObject() { ["$index"] = x.InstanceIndex }; o.AddTypeProperty(x.GetType()); x.HandleSettings(o, message.Action); return(o); })); } else if (message.Action == SettingsAction.Loading) { if (!message.Settings.TryGetObject(out var settings, "OutputTarget")) { return; } if (settings.TryGetValue <bool>(nameof(ContentVisible), out var contentVisible)) { ContentVisible = contentVisible; } if (settings.TryGetValue <int>(nameof(ScanDelay), out var scanDelay)) { ScanDelay = scanDelay; } if (settings.TryGetValue <int>(nameof(ScanInterval), out var scanInterval)) { ScanInterval = scanInterval; } if (settings.TryGetValue(nameof(Items), out var itemsToken) && itemsToken is JArray items) { foreach (var item in items.OfType <JObject>()) { var type = item.GetTypeProperty(); var index = item["$index"].ToObject <int>(); item.Remove("$type"); var usedIndices = Items.Where(x => x.GetType() == type) .Select(x => x.InstanceIndex) .ToList(); if (usedIndices.Contains(index)) { Logger.Warn("Index {0} is already used for type {1}", index, type); continue; } var instance = _outputTargetFactory.CreateOutputTarget(type, index); if (instance == null) { continue; } instance.HandleSettings(item, message.Action); AddItem(instance); } } if (settings.TryGetValue <string>(nameof(ActiveItem), out var selectedItem)) { ChangeActiveItem(Items.FirstOrDefault(x => string.Equals(x.Identifier, selectedItem)) ?? Items.FirstOrDefault(), closePrevious: false); } } }