InstallingPackageView.cpp (2551B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #include "pch.h" 4 #include "InstallingPackageView.h" 5 #include "InstallingPackageView.g.cpp" 6 #include <winrt/Windows.UI.Core.h> 7 8 namespace winrt::AppInstallerCaller::implementation 9 { 10 winrt::Microsoft::Management::Deployment::CatalogPackage InstallingPackageView::Package() 11 { 12 return m_package; 13 } 14 15 void InstallingPackageView::Package(winrt::Microsoft::Management::Deployment::CatalogPackage const& value) 16 { 17 m_package = value;; 18 } 19 20 InstallingPackageView::AsyncOperation_t InstallingPackageView::AsyncOperation() 21 { 22 return m_asyncOperation; 23 } 24 25 winrt::Windows::Foundation::IAsyncAction UpdateUIProgress( 26 winrt::Microsoft::Management::Deployment::InstallProgress progress, 27 winrt::AppInstallerCaller::InstallingPackageView view) 28 { 29 co_await winrt::resume_foreground(view.Dispatcher()); 30 view.Progress(progress.DownloadProgress * 100); 31 } 32 33 void InstallingPackageView::AsyncOperation(InstallingPackageView::AsyncOperation_t const& value) 34 { 35 m_asyncOperation = value; 36 m_asyncOperation.Progress([=]( 37 InstallingPackageView::AsyncOperation_t const& /* sender */, 38 winrt::Microsoft::Management::Deployment::InstallProgress const& progress) 39 { 40 UpdateUIProgress(progress, *this); 41 }); 42 } 43 44 double InstallingPackageView::Progress() 45 { 46 return m_progress; 47 } 48 49 void InstallingPackageView::Progress(double value) 50 { 51 if (m_progress != value) 52 { 53 m_progress = value; 54 m_propertyChanged(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"Progress" }); 55 } 56 } 57 58 hstring InstallingPackageView::StatusText() 59 { 60 return m_text; 61 } 62 63 void InstallingPackageView::StatusText(hstring const& value) 64 { 65 m_text = value; 66 } 67 68 winrt::Windows::UI::Core::CoreDispatcher InstallingPackageView::Dispatcher() 69 { 70 return m_dispatcher; 71 } 72 73 void InstallingPackageView::Dispatcher(winrt::Windows::UI::Core::CoreDispatcher const& value) 74 { 75 m_dispatcher = value; 76 } 77 78 winrt::event_token InstallingPackageView::PropertyChanged(Windows::UI::Xaml::Data::PropertyChangedEventHandler const& handler) 79 { 80 return m_propertyChanged.add(handler); 81 } 82 83 void InstallingPackageView::PropertyChanged(winrt::event_token const& token) 84 { 85 m_propertyChanged.remove(token); 86 } 87 }