private void Initialize() { var updateChapter = Task.Run(async() => { DataSource.Initialize(Environment.GetCommandLineArgs()); var updated = await DataSource.SetChapter(DataSource.Path); // Self-initialize WindowTitle = $"{DataSource.Title} - Minimal CS Manga Reader"; if (updated) { // Refresh from source instead of ViewModel since it's not initialized yet _activeIndex = DataSource.ChapterList.Count > 0 && Config.OpenChapterOnLoadChoice == Enums.OpenChapterOnLoad.Last ? DataSource.ChapterList.Count - 1 : 0; ActiveIndex = _activeIndex; } }); ThemeEditor.ModifyTheme(Config.Theme); ThemeEditor.ChangePrimaryColor(Config.AccentColor); ImageMargin = $"0,0,0,{ImageMarginSetter}"; ZoomScale = _zoomScaleSetter == 100 ? 1 : Math.Round(_zoomScaleSetter / 99.999999999999, 3); ActiveBackgroundView = Config.Background; IsScrollBarVisible = Config.IsScrollBarVisible; _scrollIncrement = Config.ScrollIncrement; ScrollIncrement = _scrollIncrement.ToString(); _imageMarginSetter = Config.ImageMargin; ActiveBackgroundView = Config.Background; updateChapter.Wait(); }
public SettingViewModel(Action <SettingViewModel, bool> closeCallback, IUserConfig config) { Config = config ?? Locator.Current.GetService <IUserConfig>(); ContextIntegrated = RegistryContextManager.IsContextRegistry(); _initialContextIntegrated = ContextIntegrated; FitImagesToScreen = Config.FitImagesToScreen; IsScrollBarVisible = Config.IsScrollBarVisible; OpenChapterOnLoad = Config.OpenChapterOnLoadChoice; SelectedBackground = Config.Background; SelectedTheme = Config.Theme; try { SelectedInterpolationMode = Config.InterpolationMode; SelectedSmoothingMode = Config.SmoothingMode; SelectedPixelOffsetMode = Config.PixelOffsetMode; } catch (Exception) { SelectedInterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default; SelectedSmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default; SelectedPixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Default; Config.InterpolationMode = SelectedInterpolationMode; Config.SmoothingMode = SelectedSmoothingMode; Config.PixelOffsetMode = SelectedPixelOffsetMode; Config.Save(); } _closeCallback = closeCallback; Save = ReactiveCommand.Create(() => { SaveSettings(); _closeCallback(this, false); }); SaveAndRefresh = ReactiveCommand.Create(() => { SaveSettings(); _closeCallback(this, true); }); Close = ReactiveCommand.Create(() => { _closeCallback(this, false); if (SelectedTheme != Config.Theme) { // Restore theme ThemeEditor.ModifyTheme(Config.Theme); } ThemeEditor.ChangePrimaryColor(Config.AccentColor); }); SetAccentColor = ReactiveCommand.Create(() => { InitialAccentColor = SelectedColor; ThemeEditor.ChangePrimaryColor(SelectedColor); IsPopupOpen = false; }); CancelAccentColor = ReactiveCommand.Create(() => { SelectedColor = Config.AccentColor; IsPopupOpen = false; }); ResetAccentColor = ReactiveCommand.Create(() => { InitialAccentColor = Color.FromArgb(255, 154, 103, 234); SelectedColor = InitialAccentColor; ThemeEditor.ChangePrimaryColor(InitialAccentColor); IsPopupOpen = false; }); this.WhenValueChanged(x => x.SelectedTheme).Subscribe(x => { ThemeEditor.ModifyTheme(x); }); this.WhenAnyValue(x => x.SelectedColor).Subscribe(x => { SelectedBrush = new SolidColorBrush(SelectedColor); }); }