winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

ActivePackageView.cpp (2395B)


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