Skip to content

Commit

Permalink
[Stub] Plugins library manager page
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Mar 12, 2023
1 parent ce79935 commit 3dd98ba
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 14 deletions.
9 changes: 7 additions & 2 deletions Amethyst/Amethyst.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
Explorer "Package and Publish" context menu entry to be enabled for this project even if
the Windows App SDK Nuget package has not yet been restored.
-->
<PropertyGroup
Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
</PropertyGroup>
<ItemGroup>
Expand All @@ -78,6 +77,7 @@
<None Remove="Pages\Devices.xaml" />
<None Remove="Pages\General.xaml" />
<None Remove="Pages\Info.xaml" />
<None Remove="Pages\Plugins.xaml" />
<None Remove="Pages\Settings.xaml" />
</ItemGroup>
<ItemGroup>
Expand All @@ -92,6 +92,11 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Page Update="Pages\Plugins.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Page Update="Controls\JointSettingsExpander.xaml">
<Generator>MSBuild:Compile</Generator>
Expand Down
1 change: 1 addition & 0 deletions Amethyst/Assets/Strings/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@
"/SharedStrings/Buttons/Help/Header": "Help",
"/SharedStrings/Buttons/Help/Licenses": "Open-Source Licenses",
"/SharedStrings/Buttons/Info": "Info",
"/SharedStrings/Buttons/Plugins": "Plugins",
"/SharedStrings/Buttons/Settings": "Settings",
"/SharedStrings/Buttons/Updates/Header": "Updates",
"/SharedStrings/Buttons/Updates/Install": "Install now",
Expand Down
28 changes: 25 additions & 3 deletions Amethyst/Classes/Shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public static ManualResetEvent
ReloadGeneralPageEvent,
ReloadSettingsPageEvent,
ReloadDevicesPageEvent,
ReloadInfoPageEvent;
ReloadInfoPageEvent,
ReloadPluginsPageEvent;

public static readonly Semaphore
SemSignalStartMain = new(0, 1);
Expand All @@ -41,6 +42,7 @@ public static void RequestInterfaceReload(bool all = true)
ReloadSettingsPageEvent?.Set();
ReloadDevicesPageEvent?.Set();
ReloadInfoPageEvent?.Set();
ReloadPluginsPageEvent?.Set();

Main.DispatcherQueue?.TryEnqueue(() =>
{
Expand Down Expand Up @@ -130,6 +132,15 @@ public static void NavigateToPage(string navItemTag,
NavigationItems.NavViewInfoButtonIcon.Foreground = NeutralBrush;
NavigationItems.NavViewInfoButtonIcon.Glyph = "\uE946";
break;
case "Amethyst.Pages.Plugins":
NavigationItems.NavViewPluginsButtonIcon.Translation = new Vector3(0, -8, 0);
NavigationItems.NavViewPluginsButtonLabel.Opacity = 1.0;

NavigationItems.NavViewPluginsButtonIcon.Foreground = NeutralBrush;

NavigationItems.NavViewPluginsButtonIcon.Glyph = "\uF158";
NavigationItems.NavViewPluginsButtonIcon.FontSize = 20;
break;
}

// Switch the next navview item to the active state
Expand Down Expand Up @@ -166,6 +177,15 @@ public static void NavigateToPage(string navItemTag,
NavigationItems.NavViewInfoButtonLabel.Opacity = 0.0;
NavigationItems.NavViewInfoButtonIcon.Translation = Vector3.Zero;
break;
case "Amethyst.Pages.Plugins":
NavigationItems.NavViewPluginsButtonLabel.Opacity = 0.0;
NavigationItems.NavViewPluginsButtonIcon.Translation = Vector3.Zero;

NavigationItems.NavViewPluginsButtonIcon.Foreground = AttentionBrush;

NavigationItems.NavViewPluginsButtonIcon.Glyph = "\uEBD2";
NavigationItems.NavViewPluginsButtonIcon.Translation = Vector3.Zero;
break;
}

Interfacing.CurrentPageTag = navItemTag; // Cache the current page tag
Expand All @@ -180,13 +200,15 @@ public static FontIcon
NavViewGeneralButtonIcon,
NavViewSettingsButtonIcon,
NavViewDevicesButtonIcon,
NavViewInfoButtonIcon;
NavViewInfoButtonIcon,
NavViewPluginsButtonIcon;

public static TextBlock
NavViewGeneralButtonLabel,
NavViewSettingsButtonLabel,
NavViewDevicesButtonLabel,
NavViewInfoButtonLabel;
NavViewInfoButtonLabel,
NavViewPluginsButtonLabel;
}
}

Expand Down
17 changes: 9 additions & 8 deletions Amethyst/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -302,21 +302,22 @@
</Viewbox>
</Grid>
</NavigationViewItem>
</muxc:NavigationView.MenuItems>

<NavigationViewItem FontSize="10" FontWeight="Medium" Visibility="Collapsed"
Tag="console" x:Name="ConsoleItem" Height="63"
BackgroundSizing="OuterBorderEdge">
<muxc:NavigationView.FooterMenuItems>
<NavigationViewItem FontSize="10" FontWeight="Medium"
Tag="plugins" x:Name="PluginsItem" Height="63" BackgroundSizing="OuterBorderEdge">
<Grid Margin="8,0,0,0" HorizontalAlignment="Center" Padding="-10">
<FontIcon Glyph="&#xEB51;" Foreground="{ThemeResource SystemFillColorNeutralBrush}"
x:Name="NavViewOkashiButtonIcon" FontSize="22" Translation="0,-8,0">
<FontIcon Glyph="&#xE946;" Foreground="{ThemeResource SystemFillColorNeutralBrush}"
x:Name="NavViewPluginsButtonIcon" FontSize="22" Translation="0,-8,0">
<FontIcon.TranslationTransition>
<Vector3Transition />
</FontIcon.TranslationTransition>
</FontIcon>

<Viewbox Margin="0,27,0,0" Stretch="Uniform" StretchDirection="DownOnly">
<TextBlock Text="お菓子❢" HorizontalAlignment="Center"
x:Name="NavViewOkashiButtonLabel"
<TextBlock HorizontalAlignment="Center" x:Name="NavViewPluginsButtonLabel"
Text="{x:Bind util:Translator.Get.String('/SharedStrings/Buttons/Plugins'), Mode=OneWay}"
Foreground="{ThemeResource SystemFillColorNeutralBrush}">
<TextBlock.OpacityTransition>
<ScalarTransition />
Expand All @@ -325,7 +326,7 @@
</Viewbox>
</Grid>
</NavigationViewItem>
</muxc:NavigationView.MenuItems>
</muxc:NavigationView.FooterMenuItems>

<muxc:NavigationView.PaneFooter>
<StackPanel Orientation="Vertical">
Expand Down
26 changes: 25 additions & 1 deletion Amethyst/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ public MainWindow()
Shared.Main.NavigationItems.NavViewSettingsButtonIcon = NavViewSettingsButtonIcon;
Shared.Main.NavigationItems.NavViewDevicesButtonIcon = NavViewDevicesButtonIcon;
Shared.Main.NavigationItems.NavViewInfoButtonIcon = NavViewInfoButtonIcon;
Shared.Main.NavigationItems.NavViewPluginsButtonIcon = NavViewPluginsButtonIcon;

Shared.Main.NavigationItems.NavViewGeneralButtonLabel = NavViewGeneralButtonLabel;
Shared.Main.NavigationItems.NavViewSettingsButtonLabel = NavViewSettingsButtonLabel;
Shared.Main.NavigationItems.NavViewDevicesButtonLabel = NavViewDevicesButtonLabel;
Shared.Main.NavigationItems.NavViewInfoButtonLabel = NavViewInfoButtonLabel;
Shared.Main.NavigationItems.NavViewPluginsButtonLabel = NavViewPluginsButtonLabel;

// Set up
Title = "Amethyst";
Expand Down Expand Up @@ -172,7 +174,8 @@ public MainWindow()
("general", typeof(General)),
("settings", typeof(Settings)),
("devices", typeof(Devices)),
("info", typeof(Info))
("info", typeof(Info)),
("plugins", typeof(Pages.Plugins))
};

Logger.Info($"Setting up shared events for '{GetType().FullName}'...");
Expand Down Expand Up @@ -1151,6 +1154,27 @@ private void ReloadNavigationIcons()
Shared.Main.NavigationItems.NavViewInfoButtonIcon.Glyph = "\uE946";
}

if (Interfacing.CurrentPageClass == "Amethyst.Pages.Plugins")
{
Shared.Main.NavigationItems.NavViewPluginsButtonLabel.Opacity = 0.0;
Shared.Main.NavigationItems.NavViewPluginsButtonIcon.Translation = Vector3.Zero;

Shared.Main.NavigationItems.NavViewPluginsButtonIcon.Foreground = Shared.Main.AttentionBrush;

Shared.Main.NavigationItems.NavViewPluginsButtonIcon.Glyph = "\uEBD2";
Shared.Main.NavigationItems.NavViewPluginsButtonIcon.FontSize = 23;
}
else
{
Shared.Main.NavigationItems.NavViewPluginsButtonIcon.Translation = new Vector3(0, -8, 0);
Shared.Main.NavigationItems.NavViewPluginsButtonLabel.Opacity = 1.0;

Shared.Main.NavigationItems.NavViewPluginsButtonIcon.Foreground = Shared.Main.NeutralBrush;

Shared.Main.NavigationItems.NavViewPluginsButtonIcon.Glyph = "\uF158";
Shared.Main.NavigationItems.NavViewPluginsButtonIcon.FontSize = 20;
}

HelpIcon.Foreground = Shared.Main.NeutralBrush;
}

Expand Down
43 changes: 43 additions & 0 deletions Amethyst/Pages/Plugins.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!-- Copyright (c) Microsoft Corporation and Contributors. -->
<!-- Licensed under the MIT License. -->

<Page
x:Class="Amethyst.Pages.Plugins"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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:mvvm="using:Amethyst.MVVM"
xmlns:controls="using:Amethyst.Controls"
xmlns:util="using:Amethyst.Utils"
xmlns:classes="using:Amethyst.Classes"
Loaded="Page_Loaded" NavigationCacheMode="Required"
mc:Ignorable="d" Background="Transparent">

<Grid Background="Transparent">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="450" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="15*" />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>

<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="0">
</Grid>

<ScrollViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="2"
x:Name="DevicesMainContentScrollViewer"
VerticalScrollBarVisibility="Visible" Padding="20,-20" Margin="-20,20,-20,20">

<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
x:Name="DevicesMainContentGridOuter" Margin="0,0,0,15">

<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
x:Name="DevicesMainContentGridInner">
</Grid>
</Grid>
</ScrollViewer>
</Grid>
</Grid>
</Page>
81 changes: 81 additions & 0 deletions Amethyst/Pages/Plugins.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading;
using Amethyst.Utils;
using System.Threading.Tasks;
using Amethyst.Classes;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace Amethyst.Pages;

/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class Plugins : Page, INotifyPropertyChanged
{
private bool _pluginsPageLoadedOnce;

public Plugins()
{
InitializeComponent();

Logger.Info($"Constructing page: '{GetType().FullName}'...");
// TODO TeachingTips

Logger.Info("Registering a detached binary semaphore " +
$"reload handler for '{GetType().FullName}'...");

Task.Run(() =>
{
Shared.Events.ReloadPluginsPageEvent =
new ManualResetEvent(false);
while (true)
{
// Wait for a reload signal (blocking)
Shared.Events.ReloadPluginsPageEvent.WaitOne();
// Reload & restart the waiting loop
if (_pluginsPageLoadedOnce && Interfacing.CurrentPageTag == "plugins")
Shared.Main.DispatcherQueue.TryEnqueue(Page_LoadedHandler);
// Reset the event
Shared.Events.ReloadPluginsPageEvent.Reset();
}
});
}

// MVVM stuff
public event PropertyChangedEventHandler PropertyChanged;

private void Page_Loaded(object sender, RoutedEventArgs e)
{
Logger.Info($"Re/Loading page: '{GetType().FullName}'...");
Interfacing.CurrentAppState = "plugins";

// Execute the handler
Page_LoadedHandler();

// Mark as loaded
_pluginsPageLoadedOnce = true;
}

private void Page_LoadedHandler()
{
OnPropertyChanged(); // Just everything
}

private void OnPropertyChanged(string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}

0 comments on commit 3dd98ba

Please sign in to comment.