Skip to content

Commit

Permalink
add hard minimum os version restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
zznty committed Oct 7, 2024
1 parent 1c8ace3 commit df6cd73
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 1 deletion.
33 changes: 32 additions & 1 deletion MusicX/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading;
using System;
using System.Threading;
using System.Windows;
using MusicX.Patches;
using MusicX.Services;
Expand Down Expand Up @@ -35,6 +36,9 @@ protected async override void OnStartup(StartupEventArgs e)

SetupAnalytics();

if (ShowUnsupportedOsMessage())
return;

ItemContainerGeneratorIndexHook.Apply();

var window = new StartingWindow(e.Args);
Expand All @@ -43,6 +47,33 @@ protected async override void OnStartup(StartupEventArgs e)
await SingleAppService.Instance.StartArgsListener();
}

private static bool ShowUnsupportedOsMessage()
{
if (OperatingSystem.IsWindowsVersionAtLeast(StaticService.MinimumOsVersion.Major,
StaticService.MinimumOsVersion.Minor,
StaticService.MinimumOsVersion.Build,
StaticService.MinimumOsVersion.Revision))
return false;

if (OperatingSystem.IsWindowsVersionAtLeast(10))
{
var window = new UnsupportedOsVersionWindow();

window.Show();
return true;
}

MessageBox.Show(
$"""
Установите последнюю версию Windows 10 или выше
Минимальная версия: {StaticService.MinimumOsVersion}
У вас установлена версия {StaticService.CurrentOsVersion}
""",
"Неподдерживаемая версия Windows", MessageBoxButton.OK, MessageBoxImage.Error);

return true;
}

private static void SetupAnalytics()
{
var sentryOptions = new SentryNLogOptions
Expand Down
31 changes: 31 additions & 0 deletions MusicX/Controls/WindowsVersionBlock.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<UserControl x:Class="MusicX.Controls.WindowsVersionBlock"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MusicX.Controls"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
mc:Ignorable="d"
Name="Control"
DataContext="{Binding Version, ElementName=Control}"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<Style TargetType="ui:Card" BasedOn="{StaticResource {x:Type ui:Card}}">
<Setter Property="Padding" Value="6" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>
</UserControl.Resources>

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock TextAlignment="Center" FontWeight="SemiBold" FontSize="24">
<ui:Card Content="{Binding Major, FallbackValue=10}" />
<Run>.</Run>
<ui:Card Content="{Binding Minor, FallbackValue=0}" />
<Run>.</Run>
<ui:Card Content="{Binding Build, FallbackValue=19041}" />
<Run>.</Run>
<ui:Card Content="{Binding Revision, FallbackValue=0}" />
</TextBlock>
</StackPanel>
</UserControl>
22 changes: 22 additions & 0 deletions MusicX/Controls/WindowsVersionBlock.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Windows;
using System.Windows.Controls;

namespace MusicX.Controls;

public partial class WindowsVersionBlock : UserControl
{
public static readonly DependencyProperty VersionProperty = DependencyProperty.Register(
nameof(Version), typeof(Version), typeof(WindowsVersionBlock), new PropertyMetadata(default(Version)));

public Version Version
{
get => (Version)GetValue(VersionProperty);
set => SetValue(VersionProperty, value);
}

public WindowsVersionBlock()
{
InitializeComponent();
}
}
3 changes: 3 additions & 0 deletions MusicX/Services/StaticService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public static class StaticService
public static string BuildDate { get; } =
typeof(StaticService).Assembly.GetCustomAttribute<BuildDateTimeAttribute>()?.Date.ToLocalTime()
.ToString("d MMMM yyyy", CultureInfo.GetCultureInfo("ru-RU")) ?? "23 сентября 2023";

public static Version MinimumOsVersion { get; } = new(10, 0, 19041, 0);
public static Version CurrentOsVersion { get; } = Environment.OSVersion.Version;
}

[AttributeUsage(AttributeTargets.Assembly)]
Expand Down
36 changes: 36 additions & 0 deletions MusicX/Views/UnsupportedOsVersionWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Window x:Class="MusicX.Views.UnsupportedOsVersionWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MusicX.Views"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:controls="clr-namespace:MusicX.Controls"
xmlns:services="clr-namespace:MusicX.Services"
mc:Ignorable="d"
Title="Неподдерживаемая версия Windows" Height="450" Width="800">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<ui:TextBlock FontTypography="Title" TextAlignment="Center">Упс! Кажется ваша система слишком устарела</ui:TextBlock>
<ui:TextBlock FontTypography="Subtitle" TextAlignment="Center">Пожалуйста обновите Windows.</ui:TextBlock>
<ui:Card Margin="0 20">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<ui:TextBlock Margin="0 0 0 5" FontTypography="BodyStrong" TextAlignment="Center">Минимальная версия системы</ui:TextBlock>
<controls:WindowsVersionBlock Grid.Row="1" Version="{x:Static services:StaticService.MinimumOsVersion}" />
</Grid>
<ui:Card.Footer>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<ui:TextBlock Margin="0 0 0 5" FontTypography="Body" TextAlignment="Center">У вас сейчас установлена версия</ui:TextBlock>
<controls:WindowsVersionBlock Grid.Row="1" Version="{x:Static services:StaticService.CurrentOsVersion}" />
</Grid>
</ui:Card.Footer>
</ui:Card>
</StackPanel>
</Window>
9 changes: 9 additions & 0 deletions MusicX/Views/UnsupportedOsVersionWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace MusicX.Views;

public partial class UnsupportedOsVersionWindow
{
public UnsupportedOsVersionWindow()
{
InitializeComponent();
}
}

0 comments on commit df6cd73

Please sign in to comment.