Skip to content

Commit

Permalink
perf: 惰性加载检查更新 UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Blinue committed Nov 17, 2023
1 parent 266633d commit 47785a2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/Magpie.App/AboutPage.idl
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ namespace Magpie.App {
AboutPage();

AboutViewModel ViewModel { get; };

// https://github.com/microsoft/microsoft-ui-xaml/issues/7579
void UnloadObject(Windows.UI.Xaml.DependencyObject object);
}
}
14 changes: 8 additions & 6 deletions src/Magpie.App/AboutPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,24 @@
<Grid>
<TextBlock x:Uid="About_Version_CheckForUpdates"
Visibility="{x:Bind ViewModel.IsCheckingForUpdates, Mode=OneWay, Converter={StaticResource NegativeVisibilityConverter}}" />
<StackPanel Orientation="Horizontal"
<StackPanel x:Name="CheckingForUpdates"
x:Load="{x:Bind ViewModel.IsCheckingForUpdates, Mode=OneWay}"
Orientation="Horizontal"
Spacing="8">
<muxc:ProgressRing Width="16"
Height="16"
VerticalAlignment="Center"
Foreground="White"
IsActive="True"
Visibility="{x:Bind ViewModel.IsCheckingForUpdates, Mode=OneWay}" />
IsActive="True" />
<TextBlock x:Uid="About_Version_CheckingForUpdates"
VerticalAlignment="Center"
Visibility="{x:Bind ViewModel.IsCheckingForUpdates, Mode=OneWay}" />
VerticalAlignment="Center" />
</StackPanel>
</Grid>
</Button>
</StackPanel>
<StackPanel ChildrenTransitions="{StaticResource SettingsCardsAnimations}"
<StackPanel x:Name="UpdateInfos"
x:Load="{x:Bind ViewModel.IsAnyUpdateStatus, Mode=OneWay}"
ChildrenTransitions="{StaticResource SettingsCardsAnimations}"
Orientation="Vertical">
<muxc:InfoBar x:Uid="About_Version_CheckForUpdatesFailed"
Margin="0,10,0,0"
Expand Down
8 changes: 6 additions & 2 deletions src/Magpie.App/AboutViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,16 @@ void AboutViewModel::IsAutoCheckForUpdates(bool value) noexcept {
_propertyChangedEvent(*this, PropertyChangedEventArgs(L"IsAutoCheckForUpdates"));
}

bool AboutViewModel::IsAnyUpdateStatus() const noexcept {
return UpdateService::Get().Status() > UpdateStatus::Checking;
}

bool AboutViewModel::IsCheckingForUpdates() const noexcept {
return UpdateService::Get().Status() == UpdateStatus::Checking;
}

bool AboutViewModel::IsErrorWhileChecking() const noexcept {
UpdateService& service = UpdateService::Get();
return service.Status() == UpdateStatus::ErrorWhileChecking;
return UpdateService::Get().Status() == UpdateStatus::ErrorWhileChecking;
}

void AboutViewModel::IsErrorWhileChecking(bool value) noexcept {
Expand Down Expand Up @@ -257,6 +260,7 @@ void AboutViewModel::Retry() {
void AboutViewModel::_UpdateService_StatusChanged(UpdateStatus status) {
_propertyChangedEvent(*this, PropertyChangedEventArgs(L"IsCheckingForUpdates"));
_propertyChangedEvent(*this, PropertyChangedEventArgs(L"IsCheckForUpdatesButtonEnabled"));
_propertyChangedEvent(*this, PropertyChangedEventArgs(L"IsAnyUpdateStatus"));
_propertyChangedEvent(*this, PropertyChangedEventArgs(L"IsErrorWhileChecking"));
_propertyChangedEvent(*this, PropertyChangedEventArgs(L"IsNoUpdate"));
_propertyChangedEvent(*this, PropertyChangedEventArgs(L"IsAvailable"));
Expand Down
2 changes: 2 additions & 0 deletions src/Magpie.App/AboutViewModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ struct AboutViewModel : AboutViewModelT<AboutViewModel> {
bool IsAutoCheckForUpdates() const noexcept;
void IsAutoCheckForUpdates(bool value) noexcept;

bool IsAnyUpdateStatus() const noexcept;

bool IsCheckingForUpdates() const noexcept;

bool IsErrorWhileChecking() const noexcept;
Expand Down
2 changes: 2 additions & 0 deletions src/Magpie.App/AboutViewModel.idl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace Magpie.App {
Boolean IsAutoCheckForUpdates;
Boolean IsCheckForPreviewUpdates;

Boolean IsAnyUpdateStatus { get; };

Boolean IsErrorWhileChecking;
Boolean IsNoUpdate;
Boolean IsAvailable { get; };
Expand Down

0 comments on commit 47785a2

Please sign in to comment.