Advertisement
mekasu0124

Untitled

Feb 24th, 2024
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.60 KB | None | 0 0
  1. using Diary.Services;
  2. using System;
  3. using System.Diagnostics;
  4. using ReactiveUI;
  5. using System.Reactive;
  6. using Diary.Models;
  7.  
  8. namespace Diary.ViewModels;
  9.  
  10. public class UpdateAvailableViewModel : ViewModelBase
  11. {
  12.     private string _title = "";
  13.     private string _information = "";
  14.     private string _subInformation = "";
  15.     private string _background = "";
  16.     private string _foreground = "";
  17.     private string _border = "";
  18.     private string _fontSize = "";
  19.     private string _fontFamily = "";
  20.     private string _fontStyle = "";
  21.     private string _textAlign = "";
  22.     private User _user;
  23.     private StyleModel _userStyles;
  24.  
  25.     public UpdateAvailableViewModel()
  26.     {
  27.         _user = new();
  28.         SetupUi();
  29.     }
  30.  
  31.     public UpdateAvailableViewModel(GithubService.VersionData version, User user)
  32.     {
  33.         string latestVersion = version.LatestVersion.ToString();
  34.         string releaseDate = version.ReleaseDate.ToString();
  35.  
  36.         Title = "A New Update Is Available";
  37.         Information = $"""
  38.                       Version: {latestVersion}
  39.                       Release Date: {releaseDate}
  40.                       Author: mekasu0124
  41.                       """;
  42.         SubInformation = "Would You Like To Update?";
  43.  
  44.         StartUpdate = ReactiveCommand.Create(LaunchUpdate);
  45.         GoHome = ReactiveCommand.Create(() => { });
  46.  
  47.         SetupUi();
  48.     }
  49.  
  50.     public void SetupUi()
  51.     {
  52.         _userStyles = User.UserSettings.StylesModel;
  53.  
  54.         Background = _userStyles.BackgroundColor;
  55.         Foreground = _userStyles.FontColor;
  56.         Border = _userStyles.BorderColor;
  57.         FontSize = _userStyles.FontSize;
  58.         FontFamily = _userStyles.FontName;
  59.         FontStyle = _userStyles.FontStyle;
  60.         TextAlign = _userStyles.TextAlign;
  61.  
  62.     }
  63.  
  64.     public static void LaunchUpdate()
  65.     {
  66.         Process pWin = new();
  67.         pWin.StartInfo.FileName = "Updater.exe";
  68.         pWin.Start();
  69.  
  70.         Environment.Exit(0);
  71.     }
  72.  
  73.     public ReactiveCommand<Unit, Unit> StartUpdate { get; }
  74.     public ReactiveCommand<Unit, Unit> GoHome { get; }
  75.  
  76.     #region Getters/Setters
  77.     public string Title
  78.     {
  79.         get => _title;
  80.         set => this.RaiseAndSetIfChanged(ref _title, value);
  81.     }
  82.     public string Information
  83.     {
  84.         get => _information;
  85.         set => this.RaiseAndSetIfChanged(ref _information, value);
  86.     }
  87.     public string SubInformation
  88.     {
  89.         get => _subInformation;
  90.         set => this.RaiseAndSetIfChanged(ref _subInformation, value);
  91.     }
  92.     public string Background
  93.     {
  94.         get => _background;
  95.         set => this.RaiseAndSetIfChanged(ref _background, value);
  96.     }
  97.     public string Foreground
  98.     {
  99.         get => _foreground;
  100.         set => this.RaiseAndSetIfChanged(ref _foreground, value);
  101.     }
  102.     public string Border
  103.     {
  104.         get => _border;
  105.         set => this.RaiseAndSetIfChanged(ref _border, value);
  106.     }
  107.     public string FontSize
  108.     {
  109.         get => _fontSize;
  110.         set => this.RaiseAndSetIfChanged(ref _fontSize, value);
  111.     }
  112.     public string FontFamily
  113.     {
  114.         get => _fontFamily;
  115.         set => this.RaiseAndSetIfChanged(ref _fontFamily, value);
  116.     }
  117.     public string FontStyle
  118.     {
  119.         get => _fontStyle;
  120.         set => this.RaiseAndSetIfChanged(ref _fontStyle, value);
  121.     }
  122.     public string TextAlign
  123.     {
  124.         get => _textAlign;
  125.         set => this.RaiseAndSetIfChanged(ref _textAlign, value);
  126.     }
  127.     public User User
  128.     {
  129.         get => _user;
  130.         set => this.RaiseAndSetIfChanged(ref _user, value);
  131.     }
  132.     #endregion
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement