Skip to content
This repository has been archived by the owner on Jan 26, 2025. It is now read-only.

Commit

Permalink
Plugin system & fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Pd233 committed Jan 14, 2024
1 parent 92e2321 commit 3e08a9c
Show file tree
Hide file tree
Showing 44 changed files with 1,431 additions and 451 deletions.
2 changes: 1 addition & 1 deletion src/LipUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public App()
{
InitializeComponent();

Current.RequestedTheme = Main.Config.PersonalizationSettings.ColorTheme switch
Current.RequestedTheme = InternalServices.ApplicationTheme = Main.Config.PersonalizationSettings.ColorTheme switch
{
ElementTheme.Dark => ApplicationTheme.Dark,
ElementTheme.Light => ApplicationTheme.Light,
Expand Down
50 changes: 48 additions & 2 deletions src/LipUI/Services.cs → src/LipUI/InternalServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Windows.UI;

namespace LipUI;

Expand All @@ -28,7 +29,13 @@ public static bool TryGoBack(this Frame frame)
}
}

public static class Services
internal static class ColorExtensions
{
public static Color Invert(this in Color color)
=> Color.FromArgb(color.A, (byte)(255 - color.R), (byte)(255 - color.G), (byte)(255 - color.B));
}

internal static class InternalServices
{
public static BitmapImage CreateImageFromBytes(byte[] bytes)
{
Expand Down Expand Up @@ -65,10 +72,49 @@ public static async ValueTask ShowInfoBarAsync(
{
if (interval == default)
interval = TimeSpan.FromSeconds(5);
await ShowInfoBarAsync(ex.GetType().Name, containsStacktrace ? ex.ToString() : ex.Message, severity, interval, barContent);
await ShowInfoBarAsync(
ex.GetType().Name,
containsStacktrace ? ex.ToString() : ex.Message,
severity,
interval,
barContent);
}

public static void ShowInfoBar(
string? title,
string? message = null,
InfoBarSeverity severity = InfoBarSeverity.Informational,
TimeSpan interval = default,
UIElement? barContent = null,
Action? completed = null)
{
if (interval == default)
interval = TimeSpan.FromSeconds(3);

MainWindow?.ShowInfoBar(title, message, severity, interval, barContent, completed);
}

public static void ShowInfoBar(
Exception ex,
bool containsStacktrace = false,
InfoBarSeverity severity = InfoBarSeverity.Error,
TimeSpan interval = default,
UIElement? barContent = null,
Action? completed = null)
{
if (interval == default)
interval = TimeSpan.FromSeconds(5);
ShowInfoBar(ex.GetType().Name,
containsStacktrace ? ex.ToString() : ex.Message,
severity,
interval,
barContent,
completed);
}

public static event Action? WindowClosed;

internal static void OnWindowClosed() => WindowClosed?.Invoke();

public static ApplicationTheme ApplicationTheme { get; internal set; }
}
6 changes: 3 additions & 3 deletions src/LipUI/Language/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@
<data name="navigationView$localPackages.Content" xml:space="preserve">
<value>Local packages</value>
</data>
<data name="navigationView$moduleManager.Content" xml:space="preserve">
<value>Module manager</value>
</data>
<data name="navigationView$packageIndex.Content" xml:space="preserve">
<value>Lip index</value>
</data>
<data name="navigationView$packTooth.Content" xml:space="preserve">
<value>Pack Tooth package</value>
</data>
<data name="propertiesEditor$nullServerPath" xml:space="preserve">
<value>Unknown server path!</value>
</data>
Expand Down
6 changes: 3 additions & 3 deletions src/LipUI/Language/zh-CN/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@
<data name="navigationView$localPackages.Content" xml:space="preserve">
<value>本地包</value>
</data>
<data name="navigationView$moduleManager.Content" xml:space="preserve">
<value>组件管理</value>
</data>
<data name="navigationView$packageIndex.Content" xml:space="preserve">
<value>包索引</value>
</data>
<data name="navigationView$packTooth.Content" xml:space="preserve">
<value>打包Tooth包</value>
</data>
<data name="propertiesEditor$nullServerPath" xml:space="preserve">
<value>未知的服务器路径!</value>
</data>
Expand Down
24 changes: 22 additions & 2 deletions src/LipUI/LipUI.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>

<WindowsPackageType>None</WindowsPackageType>
<!--<WindowsPackageType>None</WindowsPackageType>-->
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>

<OutputType>WinExe</OutputType>
Expand Down Expand Up @@ -35,11 +35,22 @@
<Content Remove="Assets\netherrack.png" />
</ItemGroup>
<ItemGroup>
<None Remove="Models\Plugin\ILipuiPlugin.cs~RF4957fb5.TMP" />
<None Remove="Models\Plugin\ILipuiPlugin.cs~RF49dcca6.TMP" />
<None Remove="Models\Plugin\ILipuiPlugin.cs~RF9ae41b7.TMP" />
<None Remove="Models\Plugin\ILipuiPluginModule.cs~RF4a8b04e.TMP" />
<None Remove="Models\Plugin\ILipuiPluginUI.cs~RF4a44265.TMP" />
<None Remove="Models\Plugin\ILipuiPluginUI.cs~RFa063bdf.TMP" />
<None Remove="Models\Plugin\LipuiRuntimeInfo.cs~RF49a61a6.TMP" />
<None Remove="Models\Plugin\PluginSystem.cs~RF4aaea31.TMP" />
<None Remove="Pages\Home\Modules\AllowListViewerPage.xaml" />
<None Remove="Pages\Home\Modules\BdsPropertiesEditorPage.xaml" />
<None Remove="Pages\Home\Modules\ModulesPage.xaml" />
<None Remove="Pages\LipExecutionPanel\ConsoleLineView.xaml" />
<None Remove="Pages\LipExecutionPanel\LipExecutionPanelPage.xaml" />
<None Remove="Pages\LocalPackage\LocalPackagePage.xaml" />
<None Remove="Pages\ModuleManager\LipuiPluginsView.xaml" />
<None Remove="Pages\ModuleManager\ModuleManagerPage.xaml.cs~RF8701840.TMP" />
<None Remove="Pages\PackTooth\PackToothPage.xaml" />
<None Remove="Pages\SelectServer\SelectServerPage.xaml" />
<None Remove="Pages\Settings\SettingsPage.xaml" />
Expand Down Expand Up @@ -192,10 +203,19 @@
<ItemGroup>
<Folder Include="Pages\Home\" />
<Folder Include="Pages\Index\" />
<Folder Include="Pages\LipExecutionPanel\" />
<Folder Include="Pages\LocalPackage\" />
<Folder Include="Pages\ServerSelection\" />
</ItemGroup>
<ItemGroup>
<Page Update="Pages\ModuleManager\LipuiPluginsView.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Page Update="Pages\LipExecutionPanel\ConsoleLineView.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>

<!--
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
Expand Down
91 changes: 91 additions & 0 deletions src/LipUI/MainWIndowWin32Invoke.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.Runtime.InteropServices;
using WinRT;
using static PInvoke.User32;

namespace LipUI;

internal partial class MainWindow
{
private readonly int MinWidth = 800;
private readonly int MinHeight = 450;

private NativeMethods.WinProc? newWndProc = null;
private nint oldWndProc = nint.Zero;

private void SubClassing()
{
var hwnd = this.As<NativeMethods.IWindowNative>().WindowHandle;
if (hwnd == nint.Zero)
{
int error = Marshal.GetLastWin32Error();
throw new InvalidOperationException($"Failed to get window handler: error code {error}");
}

newWndProc = new(NewWindowProc);

// Here we use the NativeMethods class 👇
oldWndProc = NativeMethods.SetWindowLong(hwnd, WindowLongIndexFlags.GWL_WNDPROC, newWndProc);
if (oldWndProc == nint.Zero)
{
int error = Marshal.GetLastWin32Error();
throw new InvalidOperationException($"Failed to set GWL_WNDPROC: error code {error}");
}
}

private nint NewWindowProc(nint hWnd, WindowMessage Msg, nint wParam, nint lParam)
{
[DllImport("user32.dll")]
static extern nint CallWindowProc(nint lpPrevWndFunc, nint hWnd, WindowMessage Msg, nint wParam, nint lParam);

switch (Msg)
{
case WindowMessage.WM_GETMINMAXINFO:
var dpi = GetDpiForWindow(hWnd);
float scalingFactor = (float)dpi / 96;

MINMAXINFO minMaxInfo = Marshal.PtrToStructure<MINMAXINFO>(lParam);
minMaxInfo.ptMinTrackSize.x = (int)(MinWidth * scalingFactor);
minMaxInfo.ptMinTrackSize.y = (int)(MinHeight * scalingFactor);
Marshal.StructureToPtr(minMaxInfo, lParam, true);
break;

}
return CallWindowProc(oldWndProc, hWnd, Msg, wParam, lParam);
}

private static class NativeMethods
{
[StructLayout(LayoutKind.Sequential)]
struct MINMAXINFO
{
public PInvoke.POINT ptReserved;
public PInvoke.POINT ptMaxSize;
public PInvoke.POINT ptMaxPosition;
public PInvoke.POINT ptMinTrackSize;
public PInvoke.POINT ptMaxTrackSize;
}


public delegate nint WinProc(nint hWnd, WindowMessage Msg, nint wParam, nint lParam);

// We have to handle the 32-bit and 64-bit functions separately.
// 'SetWindowLongPtr' is the 64-bit version of 'SetWindowLong', and isn't available in user32.dll for 32-bit processes.
[DllImport("user32.dll", EntryPoint = "SetWindowLong")]
private static extern nint SetWindowLong32(nint hWnd, WindowLongIndexFlags nIndex, WinProc newProc);

[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")]
private static extern nint SetWindowLong64(nint hWnd, WindowLongIndexFlags nIndex, WinProc newProc);

public static nint SetWindowLong(nint hWnd, WindowLongIndexFlags nIndex, WinProc newProc)
=> nint.Size is 4 ? SetWindowLong32(hWnd, nIndex, newProc) : SetWindowLong64(hWnd, nIndex, newProc);

[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("EECDBF0E-BAE9-4CB6-A68E-9598E1CB57BB")]
internal interface IWindowNative
{
nint WindowHandle { get; }
}
}
}
21 changes: 18 additions & 3 deletions src/LipUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
Grid.Row="1"
x:Name="NavView"
PaneDisplayMode="LeftCompact"
IsBackButtonVisible="Collapsed"
Loading="NavView_Loading"
Loaded="NavView_Loaded"
ItemInvoked="NavView_ItemInvoked"
Expand All @@ -74,17 +75,31 @@
x:Uid="navigationView$localPackages"/>

<NavigationViewItem
Icon="Add"
Tag="{x:Bind NavigationPage.PackToothPage}"
x:Uid="navigationView$packTooth"/>
Icon="Library"
Tag="{x:Bind NavigationPage.ModuleManagerPage}"
x:Uid="navigationView$moduleManager"/>

<NavigationViewItem
Icon="Find"
Tag="{x:Bind NavigationPage.IndexPage}"
x:Uid="navigationView$packageIndex"/>

<NavigationViewItemSeparator/>

</NavigationView.MenuItems>

<NavigationView.FooterMenuItems>

<NavigationViewItem
x:Name="NavigationViewItem_More"
Icon="More"
Content="i18n.more"
SelectsOnInvoked="False"/>

<NavigationViewItemSeparator/>

</NavigationView.FooterMenuItems>

<Frame
x:Name="ContentFrame"
IsTabStop="True"
Expand Down
Loading

0 comments on commit 3e08a9c

Please sign in to comment.