mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Plugins - Added help pages
This commit is contained in:
parent
b59e898dd3
commit
949106e470
@ -188,6 +188,9 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[JsonProperty]
|
||||||
|
internal List<PluginInfoHelpPage> HelpPages { get; set; } = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a boolean indicating whether this plugin is compatible with the current operating system and API version
|
/// Gets a boolean indicating whether this plugin is compatible with the current operating system and API version
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
26
src/Artemis.Core/Plugins/PluginInfoHelpPage.cs
Normal file
26
src/Artemis.Core/Plugins/PluginInfoHelpPage.cs
Normal 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; }
|
||||||
|
}
|
||||||
@ -350,6 +350,9 @@ internal class PluginManagementService : IPluginManagementService
|
|||||||
|
|
||||||
// Load the entity and fall back on creating a new one
|
// Load the entity and fall back on creating a new one
|
||||||
Plugin plugin = new(pluginInfo, directory, _pluginRepository.GetPluginByGuid(pluginInfo.Guid));
|
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));
|
OnPluginLoading(new PluginEventArgs(plugin));
|
||||||
|
|
||||||
// Locate the main assembly entry
|
// Locate the main assembly entry
|
||||||
|
|||||||
@ -3,25 +3,13 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:avalonia="clr-namespace:Markdown.Avalonia;assembly=Markdown.Avalonia"
|
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"
|
xmlns:help="clr-namespace:Artemis.UI.Screens.Plugins.Help"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="Artemis.UI.Screens.Plugins.Help.MarkdownPluginHelpPageView"
|
x:Class="Artemis.UI.Screens.Plugins.Help.MarkdownPluginHelpPageView"
|
||||||
x:DataType="help:MarkdownPluginHelpPageViewModel">
|
x:DataType="help:MarkdownPluginHelpPageViewModel">
|
||||||
<avalonia:MarkdownScrollViewer Markdown="{CompiledBinding MarkdownText}" MarkdownStyleName="FluentAvalonia">
|
<avalonia:MarkdownScrollViewer Markdown="{CompiledBinding MarkdownText}" MarkdownStyleName="FluentAvalonia">
|
||||||
<avalonia:MarkdownScrollViewer.Styles>
|
<avalonia:MarkdownScrollViewer.Styles>
|
||||||
<Style Selector="ctxt|CHyperlink">
|
<StyleInclude Source="/Styles/Markdown.axaml"/>
|
||||||
<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>
|
|
||||||
</avalonia:MarkdownScrollViewer.Styles>
|
</avalonia:MarkdownScrollViewer.Styles>
|
||||||
</avalonia:MarkdownScrollViewer>
|
</avalonia:MarkdownScrollViewer>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Avalonia.ReactiveUI;
|
||||||
|
|
||||||
namespace Artemis.UI.Screens.Plugins.Help;
|
namespace Artemis.UI.Screens.Plugins.Help;
|
||||||
|
|
||||||
public partial class MarkdownPluginHelpPageView : UserControl
|
public partial class MarkdownPluginHelpPageView : ReactiveUserControl<MarkdownPluginHelpPageViewModel>
|
||||||
{
|
{
|
||||||
public MarkdownPluginHelpPageView()
|
public MarkdownPluginHelpPageView()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reactive.Disposables;
|
using System.Reactive.Disposables;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -9,13 +10,23 @@ namespace Artemis.UI.Screens.Plugins.Help;
|
|||||||
|
|
||||||
public class MarkdownPluginHelpPageViewModel : ActivatableViewModelBase, IPluginHelpPage
|
public class MarkdownPluginHelpPageViewModel : ActivatableViewModelBase, IPluginHelpPage
|
||||||
{
|
{
|
||||||
private string? _markdownText;
|
|
||||||
private readonly MarkdownPluginHelpPage _helpPage;
|
private readonly MarkdownPluginHelpPage _helpPage;
|
||||||
|
private string? _markdownText;
|
||||||
|
|
||||||
public MarkdownPluginHelpPageViewModel(MarkdownPluginHelpPage helpPage)
|
public MarkdownPluginHelpPageViewModel(MarkdownPluginHelpPage helpPage)
|
||||||
{
|
{
|
||||||
_helpPage = 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
|
public string? MarkdownText
|
||||||
@ -24,6 +35,25 @@ public class MarkdownPluginHelpPageViewModel : ActivatableViewModelBase, IPlugin
|
|||||||
set => RaiseAndSetIfChanged(ref _markdownText, value);
|
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 />
|
/// <inheritdoc />
|
||||||
public Plugin Plugin => _helpPage.Plugin;
|
public Plugin Plugin => _helpPage.Plugin;
|
||||||
|
|
||||||
@ -32,9 +62,4 @@ public class MarkdownPluginHelpPageViewModel : ActivatableViewModelBase, IPlugin
|
|||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Id => _helpPage.Id;
|
public string Id => _helpPage.Id;
|
||||||
|
|
||||||
private async Task Load()
|
|
||||||
{
|
|
||||||
MarkdownText ??= await File.ReadAllTextAsync(_helpPage.MarkdownFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -10,7 +10,7 @@
|
|||||||
x:DataType="help:PluginHelpWindowViewModel"
|
x:DataType="help:PluginHelpWindowViewModel"
|
||||||
Icon="/Assets/Images/Logo/application.ico"
|
Icon="/Assets/Images/Logo/application.ico"
|
||||||
Title="{CompiledBinding DisplayName}"
|
Title="{CompiledBinding DisplayName}"
|
||||||
Width="800"
|
Width="1200"
|
||||||
Height="800"
|
Height="800"
|
||||||
WindowStartupLocation="CenterOwner">
|
WindowStartupLocation="CenterOwner">
|
||||||
|
|
||||||
@ -18,7 +18,7 @@
|
|||||||
<ListBox Items="{CompiledBinding HelpPages}" SelectedItem="{CompiledBinding SelectedHelpPage}" Grid.Column="0" Margin="10">
|
<ListBox Items="{CompiledBinding HelpPages}" SelectedItem="{CompiledBinding SelectedHelpPage}" Grid.Column="0" Margin="10">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate x:DataType="core:IPluginHelpPage">
|
<DataTemplate x:DataType="core:IPluginHelpPage">
|
||||||
<TextBlock Text="{CompiledBinding Title}"/>
|
<TextBlock Text="{CompiledBinding Title}" VerticalAlignment="Center" />
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ListBox.ItemTemplate>
|
</ListBox.ItemTemplate>
|
||||||
</ListBox>
|
</ListBox>
|
||||||
@ -28,4 +28,4 @@
|
|||||||
|
|
||||||
<StackPanel Grid.Column="0" Grid.ColumnSpan="2" Classes="notification-container" Name="NotificationContainer" VerticalAlignment="Bottom" HorizontalAlignment="Right" />
|
<StackPanel Grid.Column="0" Grid.ColumnSpan="2" Classes="notification-container" Name="NotificationContainer" VerticalAlignment="Bottom" HorizontalAlignment="Right" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
@ -1,10 +1,11 @@
|
|||||||
|
using Artemis.UI.Shared;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
|
|
||||||
namespace Artemis.UI.Screens.Plugins.Help;
|
namespace Artemis.UI.Screens.Plugins.Help;
|
||||||
|
|
||||||
public partial class PluginHelpWindowView : Window
|
public partial class PluginHelpWindowView : ReactiveAppWindow<PluginHelpWindowViewModel>
|
||||||
{
|
{
|
||||||
public PluginHelpWindowView()
|
public PluginHelpWindowView()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -95,7 +95,7 @@
|
|||||||
IsVisible="{CompiledBinding HasHelpPages}"
|
IsVisible="{CompiledBinding HasHelpPages}"
|
||||||
Command="{CompiledBinding OpenHelp}"
|
Command="{CompiledBinding OpenHelp}"
|
||||||
ToolTip.Tip="View help pages">
|
ToolTip.Tip="View help pages">
|
||||||
<avalonia:MaterialIcon Kind="Help" />
|
<avalonia:MaterialIcon Kind="HelpCircle" />
|
||||||
</controls:HyperlinkButton>
|
</controls:HyperlinkButton>
|
||||||
<controls:HyperlinkButton Classes="icon-button icon-button-large"
|
<controls:HyperlinkButton Classes="icon-button icon-button-large"
|
||||||
IsVisible="{CompiledBinding Plugin.Info.Website, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
|
IsVisible="{CompiledBinding Plugin.Info.Website, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
|
||||||
|
|||||||
@ -230,9 +230,6 @@ public class PluginViewModel : ActivatableViewModelBase
|
|||||||
|
|
||||||
private void ExecuteOpenHelp()
|
private void ExecuteOpenHelp()
|
||||||
{
|
{
|
||||||
if (Plugin.ConfigurationDialog == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_helpWindow != null)
|
if (_helpWindow != null)
|
||||||
{
|
{
|
||||||
_helpWindow.WindowState = WindowState.Normal;
|
_helpWindow.WindowState = WindowState.Normal;
|
||||||
|
|||||||
@ -4,9 +4,6 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:updating="clr-namespace:Artemis.UI.Screens.Settings.Updating"
|
xmlns:updating="clr-namespace:Artemis.UI.Screens.Settings.Updating"
|
||||||
xmlns:avalonia="clr-namespace:Markdown.Avalonia;assembly=Markdown.Avalonia"
|
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:avalonia1="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||||
xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared"
|
xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared"
|
||||||
mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="1400"
|
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 Grid.Row="2" Markdown="{CompiledBinding Changelog}" MarkdownStyleName="FluentAvalonia">
|
||||||
<avalonia:MarkdownScrollViewer.Styles>
|
<avalonia:MarkdownScrollViewer.Styles>
|
||||||
<Style Selector="ctxt|CHyperlink">
|
<StyleInclude Source="/Styles/Markdown.axaml"/>
|
||||||
<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>
|
|
||||||
</avalonia:MarkdownScrollViewer.Styles>
|
</avalonia:MarkdownScrollViewer.Styles>
|
||||||
</avalonia:MarkdownScrollViewer>
|
</avalonia:MarkdownScrollViewer>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
60
src/Artemis.UI/Styles/Markdown.axaml
Normal file
60
src/Artemis.UI/Styles/Markdown.axaml
Normal 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>
|
||||||
Loading…
x
Reference in New Issue
Block a user