1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 21:38:38 +00:00

Plugins - Added help pages

This commit is contained in:
Robert 2023-04-14 11:55:53 +02:00
parent b59e898dd3
commit 949106e470
12 changed files with 134 additions and 43 deletions

View File

@ -188,6 +188,9 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
}
}
[JsonProperty]
internal List<PluginInfoHelpPage> HelpPages { get; set; } = new();
/// <summary>
/// Gets a boolean indicating whether this plugin is compatible with the current operating system and API version
/// </summary>

View File

@ -0,0 +1,26 @@
using Newtonsoft.Json;
namespace Artemis.Core;
/// <summary>
/// Represents basic info about a plugin and contains a reference to the instance of said plugin
/// </summary>
internal class PluginInfoHelpPage
{
[JsonConstructor]
public PluginInfoHelpPage(string title, string markdownFile, string id)
{
Title = title;
MarkdownFile = markdownFile;
Id = id;
}
[JsonProperty(Required = Required.Always)]
public string Title { get; }
[JsonProperty(Required = Required.Always)]
public string MarkdownFile { get; }
[JsonProperty(Required = Required.Always)]
public string Id { get; }
}

View File

@ -350,6 +350,9 @@ internal class PluginManagementService : IPluginManagementService
// Load the entity and fall back on creating a new one
Plugin plugin = new(pluginInfo, directory, _pluginRepository.GetPluginByGuid(pluginInfo.Guid));
foreach (PluginInfoHelpPage pluginInfoHelpPage in pluginInfo.HelpPages)
plugin.HelpPages.Add(new MarkdownPluginHelpPage(plugin, pluginInfoHelpPage.Title, pluginInfoHelpPage.Id, pluginInfoHelpPage.MarkdownFile));
OnPluginLoading(new PluginEventArgs(plugin));
// Locate the main assembly entry

View File

@ -3,25 +3,13 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:avalonia="clr-namespace:Markdown.Avalonia;assembly=Markdown.Avalonia"
xmlns:plugins="clr-namespace:Artemis.UI.Screens.Plugins"
xmlns:ctxt="clr-namespace:ColorTextBlock.Avalonia;assembly=ColorTextBlock.Avalonia"
xmlns:help="clr-namespace:Artemis.UI.Screens.Plugins.Help"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Artemis.UI.Screens.Plugins.Help.MarkdownPluginHelpPageView"
x:DataType="help:MarkdownPluginHelpPageViewModel">
<avalonia:MarkdownScrollViewer Markdown="{CompiledBinding MarkdownText}" MarkdownStyleName="FluentAvalonia">
<avalonia:MarkdownScrollViewer.Styles>
<Style Selector="ctxt|CHyperlink">
<Setter Property="Foreground" Value="{DynamicResource SystemAccentColorLight3}" />
</Style>
<Style Selector="ctxt|CHyperlink:pointerover">
<Setter Property="Foreground" Value="{DynamicResource SystemAccentColorLight1}" />
</Style>
<Style Selector="Grid.List">
<Style.Setters>
<Setter Property="Margin" Value="20,0,0,0"/>
</Style.Setters>
</Style>
<StyleInclude Source="/Styles/Markdown.axaml"/>
</avalonia:MarkdownScrollViewer.Styles>
</avalonia:MarkdownScrollViewer>
</UserControl>

View File

@ -1,9 +1,10 @@
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
namespace Artemis.UI.Screens.Plugins.Help;
public partial class MarkdownPluginHelpPageView : UserControl
public partial class MarkdownPluginHelpPageView : ReactiveUserControl<MarkdownPluginHelpPageViewModel>
{
public MarkdownPluginHelpPageView()
{

View File

@ -1,3 +1,4 @@
using System;
using System.IO;
using System.Reactive.Disposables;
using System.Threading.Tasks;
@ -9,13 +10,23 @@ namespace Artemis.UI.Screens.Plugins.Help;
public class MarkdownPluginHelpPageViewModel : ActivatableViewModelBase, IPluginHelpPage
{
private string? _markdownText;
private readonly MarkdownPluginHelpPage _helpPage;
private string? _markdownText;
public MarkdownPluginHelpPageViewModel(MarkdownPluginHelpPage helpPage)
{
_helpPage = helpPage;
this.WhenActivated(d => Load().DisposeWith(d));
this.WhenActivated(d =>
{
FileSystemWatcher watcher = new();
watcher.Path = Path.GetDirectoryName(_helpPage.MarkdownFile) ?? throw new InvalidOperationException($"Path \"{_helpPage.MarkdownFile}\" does not contain a directory");
watcher.Filter = Path.GetFileName(_helpPage.MarkdownFile);
watcher.EnableRaisingEvents = true;
watcher.Changed += WatcherOnChanged;
watcher.DisposeWith(d);
LoadMarkdown().DisposeWith(d);
});
}
public string? MarkdownText
@ -24,6 +35,25 @@ public class MarkdownPluginHelpPageViewModel : ActivatableViewModelBase, IPlugin
set => RaiseAndSetIfChanged(ref _markdownText, value);
}
private async void WatcherOnChanged(object sender, FileSystemEventArgs e)
{
await LoadMarkdown();
}
private async Task LoadMarkdown()
{
try
{
await using FileStream stream = new(_helpPage.MarkdownFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using StreamReader reader = new(stream);
MarkdownText = await reader.ReadToEndAsync();
}
catch (Exception e)
{
MarkdownText = e.Message;
}
}
/// <inheritdoc />
public Plugin Plugin => _helpPage.Plugin;
@ -32,9 +62,4 @@ public class MarkdownPluginHelpPageViewModel : ActivatableViewModelBase, IPlugin
/// <inheritdoc />
public string Id => _helpPage.Id;
private async Task Load()
{
MarkdownText ??= await File.ReadAllTextAsync(_helpPage.MarkdownFile);
}
}

View File

@ -10,7 +10,7 @@
x:DataType="help:PluginHelpWindowViewModel"
Icon="/Assets/Images/Logo/application.ico"
Title="{CompiledBinding DisplayName}"
Width="800"
Width="1200"
Height="800"
WindowStartupLocation="CenterOwner">
@ -18,7 +18,7 @@
<ListBox Items="{CompiledBinding HelpPages}" SelectedItem="{CompiledBinding SelectedHelpPage}" Grid.Column="0" Margin="10">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="core:IPluginHelpPage">
<TextBlock Text="{CompiledBinding Title}"/>
<TextBlock Text="{CompiledBinding Title}" VerticalAlignment="Center" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
@ -28,4 +28,4 @@
<StackPanel Grid.Column="0" Grid.ColumnSpan="2" Classes="notification-container" Name="NotificationContainer" VerticalAlignment="Bottom" HorizontalAlignment="Right" />
</Grid>
</Window>
</Window>

View File

@ -1,10 +1,11 @@
using Artemis.UI.Shared;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace Artemis.UI.Screens.Plugins.Help;
public partial class PluginHelpWindowView : Window
public partial class PluginHelpWindowView : ReactiveAppWindow<PluginHelpWindowViewModel>
{
public PluginHelpWindowView()
{

View File

@ -95,7 +95,7 @@
IsVisible="{CompiledBinding HasHelpPages}"
Command="{CompiledBinding OpenHelp}"
ToolTip.Tip="View help pages">
<avalonia:MaterialIcon Kind="Help" />
<avalonia:MaterialIcon Kind="HelpCircle" />
</controls:HyperlinkButton>
<controls:HyperlinkButton Classes="icon-button icon-button-large"
IsVisible="{CompiledBinding Plugin.Info.Website, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"

View File

@ -230,9 +230,6 @@ public class PluginViewModel : ActivatableViewModelBase
private void ExecuteOpenHelp()
{
if (Plugin.ConfigurationDialog == null)
return;
if (_helpWindow != null)
{
_helpWindow.WindowState = WindowState.Normal;

View File

@ -4,9 +4,6 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:updating="clr-namespace:Artemis.UI.Screens.Settings.Updating"
xmlns:avalonia="clr-namespace:Markdown.Avalonia;assembly=Markdown.Avalonia"
xmlns:mdc="clr-namespace:Markdown.Avalonia.Controls;assembly=Markdown.Avalonia"
xmlns:mde="clr-namespace:Markdown.Avalonia.Extensions;assembly=Markdown.Avalonia"
xmlns:ctxt="clr-namespace:ColorTextBlock.Avalonia;assembly=ColorTextBlock.Avalonia"
xmlns:avalonia1="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared"
mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="1400"
@ -158,17 +155,7 @@
<avalonia:MarkdownScrollViewer Grid.Row="2" Markdown="{CompiledBinding Changelog}" MarkdownStyleName="FluentAvalonia">
<avalonia:MarkdownScrollViewer.Styles>
<Style Selector="ctxt|CHyperlink">
<Setter Property="Foreground" Value="{DynamicResource SystemAccentColorLight3}" />
</Style>
<Style Selector="ctxt|CHyperlink:pointerover">
<Setter Property="Foreground" Value="{DynamicResource SystemAccentColorLight1}" />
</Style>
<Style Selector="Grid.List">
<Style.Setters>
<Setter Property="Margin" Value="20,0,0,0"/>
</Style.Setters>
</Style>
<StyleInclude Source="/Styles/Markdown.axaml"/>
</avalonia:MarkdownScrollViewer.Styles>
</avalonia:MarkdownScrollViewer>
</Grid>

View File

@ -0,0 +1,60 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:avalonia="clr-namespace:Markdown.Avalonia;assembly=Markdown.Avalonia"
xmlns:ctxt="clr-namespace:ColorTextBlock.Avalonia;assembly=ColorTextBlock.Avalonia">
<Style Selector="ctxt|CHyperlink">
<Setter Property="Foreground" Value="{DynamicResource SystemAccentColorLight3}" />
</Style>
<Style Selector="ctxt|CHyperlink:pointerover">
<Setter Property="Foreground" Value="{DynamicResource SystemAccentColorLight1}" />
</Style>
<Style Selector="Grid.List">
<Style.Setters>
<Setter Property="Margin" Value="10,0,0,0" />
</Style.Setters>
</Style>
<Style Selector="ctxt|CTextBlock">
<Style.Setters>
<Setter Property="FontSize" Value="14" />
<Setter Property="Margin" Value="0,5" />
</Style.Setters>
</Style>
<Style Selector="TextBlock">
<Style.Setters>
<Setter Property="FontSize" Value="14" />
</Style.Setters>
</Style>
<Style Selector="ctxt|CTextBlock.Heading1">
<Style.Setters>
<Setter Property="FontSize" Value="28" />
<Setter Property="FontWeight" Value="SemiBold" />
<Setter Property="Margin" Value="0,15,0,5" />
</Style.Setters>
</Style>
<Style Selector="ctxt|CTextBlock.Heading2">
<Style.Setters>
<Setter Property="FontSize" Value="22" />
<Setter Property="FontWeight" Value="SemiBold" />
<Setter Property="Margin" Value="0,15,0,5" />
</Style.Setters>
</Style>
<Style Selector="ctxt|CTextBlock.Heading3">
<Style.Setters>
<Setter Property="FontSize" Value="18" />
<Setter Property="FontWeight" Value="SemiBold" />
<Setter Property="Margin" Value="0,10,0,5" />
</Style.Setters>
</Style>
<Style Selector="ctxt|CTextBlock.Heading4">
<Style.Setters>
<Setter Property="FontSize" Value="14" />
<Setter Property="FontWeight" Value="SemiBold" />
<Setter Property="Margin" Value="0,10,0,5" />
</Style.Setters>
</Style>
</Styles>