markus / MarkusAutoUpdate / src / NetSparkle.UI.Avalonia / UpdateAvailableWindow.xaml.cs @ d8f5045e
이력 | 보기 | 이력해설 | 다운로드 (3.51 KB)
1 | d8f5045e | taeseongkim | using Avalonia; |
---|---|---|---|
2 | using Avalonia.Controls; |
||
3 | using Avalonia.Controls.Html; |
||
4 | using Avalonia.Markup.Xaml; |
||
5 | using Avalonia.Media.Imaging; |
||
6 | using Avalonia.Threading; |
||
7 | using NetSparkleUpdater.Enums; |
||
8 | using NetSparkleUpdater.Events; |
||
9 | using NetSparkleUpdater.Interfaces; |
||
10 | using NetSparkleUpdater.UI.Avalonia.Controls; |
||
11 | using NetSparkleUpdater.UI.Avalonia.Interfaces; |
||
12 | using NetSparkleUpdater.UI.Avalonia.ViewModels; |
||
13 | using System.Linq; |
||
14 | |||
15 | namespace NetSparkleUpdater.UI.Avalonia |
||
16 | { |
||
17 | public class UpdateAvailableWindow : BaseWindow, IUpdateAvailable, IReleaseNotesUpdater, IUserRespondedToUpdateCheck |
||
18 | { |
||
19 | private UpdateAvailableWindowViewModel _dataContext; |
||
20 | private RowDefinition _releaseNotesRow; |
||
21 | |||
22 | private HtmlLabel _htmlLabel; |
||
23 | |||
24 | public UpdateAvailableWindow() : base(true) |
||
25 | { |
||
26 | this.InitializeComponent(); |
||
27 | #if DEBUG |
||
28 | this.AttachDevTools(); |
||
29 | #endif |
||
30 | } |
||
31 | |||
32 | public UpdateAvailableWindow(UpdateAvailableWindowViewModel viewModel, IBitmap iconBitmap) : base(true) |
||
33 | { |
||
34 | this.InitializeComponent(); |
||
35 | var imageControl = this.FindControl<Image>("AppIcon"); |
||
36 | if (imageControl != null) |
||
37 | { |
||
38 | imageControl.Source = iconBitmap; |
||
39 | } |
||
40 | #if DEBUG |
||
41 | this.AttachDevTools(); |
||
42 | #endif |
||
43 | DataContext = _dataContext = viewModel; |
||
44 | _dataContext.ReleaseNotesUpdater = this; |
||
45 | _dataContext.UserRespondedHandler = this; |
||
46 | } |
||
47 | |||
48 | private void InitializeComponent() |
||
49 | { |
||
50 | AvaloniaXamlLoader.Load(this); |
||
51 | var grid = this.FindControl<Grid>("MainGrid"); |
||
52 | _releaseNotesRow = grid.RowDefinitions[2]; |
||
53 | _htmlLabel = this.FindControl<HtmlLabel>("ChangeNotesHTMLLabel"); |
||
54 | _htmlLabel.SetValue(HtmlLabel.AutoSizeHeightOnlyProperty, true); |
||
55 | } |
||
56 | |||
57 | UpdateAvailableResult IUpdateAvailable.Result => _dataContext?.UserResponse ?? UpdateAvailableResult.None; |
||
58 | |||
59 | AppCastItem IUpdateAvailable.CurrentItem => CurrentItem; |
||
60 | |||
61 | public AppCastItem CurrentItem |
||
62 | { |
||
63 | get { return _dataContext?.Updates?.FirstOrDefault(); } |
||
64 | } |
||
65 | |||
66 | public event UserRespondedToUpdate UserResponded; |
||
67 | |||
68 | void IUpdateAvailable.BringToFront() |
||
69 | { |
||
70 | BringToFront(); |
||
71 | } |
||
72 | |||
73 | void IUpdateAvailable.Close() |
||
74 | { |
||
75 | CloseWindow(); |
||
76 | } |
||
77 | |||
78 | void IUpdateAvailable.HideReleaseNotes() |
||
79 | { |
||
80 | if (_dataContext != null) |
||
81 | { |
||
82 | _dataContext.AreReleaseNotesVisible = false; |
||
83 | } |
||
84 | _releaseNotesRow.Height = new GridLength(10); |
||
85 | } |
||
86 | |||
87 | void IUpdateAvailable.HideRemindMeLaterButton() |
||
88 | { |
||
89 | if (_dataContext != null) |
||
90 | { |
||
91 | _dataContext.IsRemindMeLaterVisible = false; |
||
92 | } |
||
93 | } |
||
94 | |||
95 | void IUpdateAvailable.HideSkipButton() |
||
96 | { |
||
97 | if (_dataContext != null) |
||
98 | { |
||
99 | _dataContext.IsSkipVisible = false; |
||
100 | } |
||
101 | } |
||
102 | |||
103 | void IUpdateAvailable.Show(bool isOnMainThread) |
||
104 | { |
||
105 | ShowWindow(isOnMainThread); |
||
106 | } |
||
107 | |||
108 | public void UserRespondedToUpdateCheck(UpdateAvailableResult response) |
||
109 | { |
||
110 | UserResponded?.Invoke(this, new UpdateResponseEventArgs(_dataContext?.UserResponse ?? UpdateAvailableResult.None, CurrentItem)); |
||
111 | } |
||
112 | |||
113 | public void ShowReleaseNotes(string notes) |
||
114 | { |
||
115 | Dispatcher.UIThread.InvokeAsync(() => |
||
116 | { |
||
117 | _htmlLabel.Text = notes; |
||
118 | }); |
||
119 | } |
||
120 | } |
||
121 | } |