- add: nice error view
This commit is contained in:
@@ -28,14 +28,16 @@ public class App : Application
|
||||
{
|
||||
case IClassicDesktopStyleApplicationLifetime desktop:
|
||||
DisableAvaloniaDataAnnotationValidation();
|
||||
desktop.MainWindow = new MessageWindow(out provider);
|
||||
desktop.MainWindow = (Window)(provider = new MessageWindow());
|
||||
break;
|
||||
case ISingleViewApplicationLifetime singleViewPlatform:
|
||||
singleViewPlatform.MainView = new MessageView(out provider);
|
||||
singleViewPlatform.MainView = (Control)(provider = new MessageView());
|
||||
break;
|
||||
}
|
||||
|
||||
provider?.ShowMessage("Launcher is already running.","hey shithead!");
|
||||
provider?.ShowMessage(
|
||||
"Error: An instance of the application is already running. Please close the existing instance before launching a new one.",
|
||||
"Duplicate instance detected.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
BIN
Nebula.Launcher/Assets/error_presentation/Cinka.png
Normal file
BIN
Nebula.Launcher/Assets/error_presentation/Cinka.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 150 KiB |
BIN
Nebula.Launcher/Assets/error_presentation/alex.png
Normal file
BIN
Nebula.Launcher/Assets/error_presentation/alex.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 158 KiB |
@@ -1,11 +1,11 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using System;
|
||||
using Avalonia.Data.Converters;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Platform;
|
||||
|
||||
namespace Nebula.Launcher.Converters;
|
||||
|
||||
public class TypeConverters
|
||||
public static class TypeConverters
|
||||
{
|
||||
public static FuncValueConverter<string, string?> IconConverter { get; } =
|
||||
new(iconKey =>
|
||||
@@ -13,4 +13,11 @@ public class TypeConverters
|
||||
if (iconKey == null) return null;
|
||||
return $"/Assets/svg/{iconKey}.svg";
|
||||
});
|
||||
|
||||
public static FuncValueConverter<string, IImage?> ImageConverter { get; } =
|
||||
new(iconKey =>
|
||||
{
|
||||
if (iconKey == null) return null;
|
||||
return new Avalonia.Media.Imaging.Bitmap(AssetLoader.Open(new Uri($"avares://Nebula.Launcher/Assets/error_presentation/{iconKey}.png")));
|
||||
});
|
||||
}
|
||||
@@ -2,16 +2,9 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:views="clr-namespace:Nebula.Launcher.Views"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
Width="600"
|
||||
Height="400"
|
||||
|
||||
x:Class="Nebula.Launcher.MessageBox.MessageView">
|
||||
<Grid RowDefinitions="50,*" ColumnDefinitions="*">
|
||||
<Border Grid.Column="0" Background="#222222" Padding="10" BorderBrush="#444444" BorderThickness="0,0,0,3">
|
||||
<Label VerticalAlignment="Center" x:Name="Title">Text</Label>
|
||||
</Border>
|
||||
<Panel Margin="5" Grid.Row="1">
|
||||
<Label x:Name="Message">Message</Label>
|
||||
</Panel>
|
||||
</Grid>
|
||||
<views:VisualErrorView x:Name="ErrorView"/>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Nebula.Launcher.ViewModels;
|
||||
|
||||
namespace Nebula.Launcher.MessageBox;
|
||||
|
||||
public partial class MessageView : UserControl, IMessageContainerProvider
|
||||
{
|
||||
public MessageView(out IMessageContainerProvider provider)
|
||||
private readonly VisualErrorViewModel _context;
|
||||
public MessageView()
|
||||
{
|
||||
InitializeComponent();
|
||||
provider = this;
|
||||
_context = new VisualErrorViewModel();
|
||||
ErrorView.Content = _context;
|
||||
}
|
||||
|
||||
public void ShowMessage(string message, string title)
|
||||
{
|
||||
Title.Content = title;
|
||||
Message.Content = message;
|
||||
_context.Title = title;
|
||||
_context.Description = message;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,52 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:messageBox="clr-namespace:Nebula.Launcher.MessageBox"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
SystemDecorations="BorderOnly"
|
||||
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="260"
|
||||
Width="600"
|
||||
Height="400"
|
||||
Height="260"
|
||||
CanResize="False"
|
||||
x:Class="Nebula.Launcher.MessageBox.MessageWindow"
|
||||
Title="MessageWindow">
|
||||
|
||||
<Grid ColumnDefinitions="*" RowDefinitions="30,*">
|
||||
<messageBox:MessageView
|
||||
Grid.Column="0"
|
||||
Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
x:Name="MessageView" />
|
||||
<Border
|
||||
|
||||
BorderThickness="0,0,0,2"
|
||||
CornerRadius="0"
|
||||
Grid.Column="0"
|
||||
Grid.Row="0">
|
||||
<Border.BorderBrush>
|
||||
<LinearGradientBrush EndPoint="100%,50%" StartPoint="0%,50%">
|
||||
<GradientStop Color="#222222" Offset="0.0" />
|
||||
<GradientStop Color="#442222" Offset="1.0" />
|
||||
</LinearGradientBrush>
|
||||
</Border.BorderBrush>
|
||||
<Panel
|
||||
Height="30"
|
||||
PointerPressed="InputElement_OnPointerPressed">
|
||||
<TextBlock
|
||||
FontSize="10"
|
||||
Foreground="White"
|
||||
IsVisible="False"
|
||||
Margin="15,0"
|
||||
Text="Nebula Launcher"
|
||||
VerticalAlignment="Center" />
|
||||
<StackPanel
|
||||
HorizontalAlignment="Right"
|
||||
Margin="5,0,5,0"
|
||||
Orientation="Horizontal"
|
||||
Spacing="8">
|
||||
<Button
|
||||
Click="Close_Click"
|
||||
Content="🗙"
|
||||
Foreground="Azure" />
|
||||
</StackPanel>
|
||||
</Panel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@@ -1,12 +1,28 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
|
||||
namespace Nebula.Launcher.MessageBox;
|
||||
|
||||
public partial class MessageWindow : Window
|
||||
public partial class MessageWindow : Window, IMessageContainerProvider
|
||||
{
|
||||
public MessageWindow(out IMessageContainerProvider provider)
|
||||
public MessageWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
Content = new MessageView(out provider);
|
||||
}
|
||||
|
||||
public void ShowMessage(string message, string title)
|
||||
{
|
||||
MessageView.ShowMessage(message, title);
|
||||
}
|
||||
|
||||
private void Close_Click(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void InputElement_OnPointerPressed(object? sender, PointerPressedEventArgs e)
|
||||
{
|
||||
BeginMoveDrag(e);
|
||||
}
|
||||
}
|
||||
22
Nebula.Launcher/ViewModels/VisualErrorViewModel.cs
Normal file
22
Nebula.Launcher/ViewModels/VisualErrorViewModel.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Nebula.Launcher.Views;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels;
|
||||
|
||||
|
||||
[ViewModelRegister(typeof(VisualErrorView))]
|
||||
public partial class VisualErrorViewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty] private string _imgPath = "cinka";
|
||||
[ObservableProperty] private string _title = "Error";
|
||||
[ObservableProperty] private string _description = "This is an error.";
|
||||
|
||||
protected override void InitialiseInDesignMode()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Initialise()
|
||||
{
|
||||
}
|
||||
}
|
||||
39
Nebula.Launcher/Views/VisualErrorView.axaml
Normal file
39
Nebula.Launcher/Views/VisualErrorView.axaml
Normal file
@@ -0,0 +1,39 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels"
|
||||
xmlns:converters="clr-namespace:Nebula.Launcher.Converters"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:DataType="viewModels:VisualErrorViewModel"
|
||||
x:Class="Nebula.Launcher.Views.VisualErrorView">
|
||||
<Design.DataContext>
|
||||
<viewModels:VisualErrorViewModel />
|
||||
</Design.DataContext>
|
||||
<Grid RowDefinitions="30,*" ColumnDefinitions="200,*">
|
||||
<Border Grid.Row="1" Grid.Column="0"
|
||||
CornerRadius="10,0,0,10"
|
||||
BorderThickness="0,0,2,0"
|
||||
BorderBrush="{StaticResource DefaultForeground}">
|
||||
<Image Source="{Binding ImgPath, Converter={x:Static converters:TypeConverters.ImageConverter}}" Width="200" Height="200"/>
|
||||
</Border>
|
||||
<Border Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" CornerRadius="10,10,0,0">
|
||||
<Border.Background>
|
||||
<LinearGradientBrush EndPoint="100%,50%" StartPoint="10%,20%">
|
||||
<GradientStop Color="#FF6B6B" Offset="0.0" />
|
||||
<GradientStop Color="#FF8E53" Offset="0.3" />
|
||||
<GradientStop Color="#FF5E3A" Offset="0.6" />
|
||||
<GradientStop Color="#FF5e5e" Offset="1.0" />
|
||||
</LinearGradientBrush>
|
||||
</Border.Background>
|
||||
<Label HorizontalAlignment="Center"><TextBlock Text="{Binding Title}"/></Label>
|
||||
</Border>
|
||||
<TextBlock
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
Margin="15"
|
||||
HorizontalAlignment="Center"
|
||||
TextWrapping="Wrap"
|
||||
Text="{Binding Description}"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
11
Nebula.Launcher/Views/VisualErrorView.axaml.cs
Normal file
11
Nebula.Launcher/Views/VisualErrorView.axaml.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace Nebula.Launcher.Views;
|
||||
|
||||
public partial class VisualErrorView : UserControl
|
||||
{
|
||||
public VisualErrorView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user