Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Pd233 committed Jan 7, 2024
1 parent 9b041f2 commit c49ce1b
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 80 deletions.
10 changes: 7 additions & 3 deletions src/LipUI/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.UI.Xaml;
using System.IO;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

Expand All @@ -15,7 +16,7 @@ public partial class App : Application
/// </summary>
public App()
{
this.InitializeComponent();
InitializeComponent();
}

/// <summary>
Expand All @@ -24,12 +25,15 @@ public App()
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
//Main.Initialize();

m_window = new MainWindow();
m_window.Activate();

//ExtendAcrylicIntoTitleBar();
UnhandledException += App_UnhandledException;
}

private void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
}

internal Window? m_window;
Expand Down
7 changes: 5 additions & 2 deletions src/LipUI/Language/zh-CN/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
<data name="home$emptyDesc" xml:space="preserve">
<value>无描述</value>
</data>
<data name="home$nullServerPath" xml:space="preserve">
<value>未选择服务器</value>
</data>
<data name="infoBar$error" xml:space="preserve">
<value>错误</value>
</data>
Expand All @@ -138,8 +141,8 @@
<data name="infoBar$warning" xml:space="preserve">
<value>警告</value>
</data>
<data name="lipExecution$nullServerPath" xml:space="preserve">
<value>未知的服务器路径!</value>
<data name="lipExecution$nullLipPath" xml:space="preserve">
<value>未知的Lip路径!</value>
</data>
<data name="lipInstaller$cancel.Content" xml:space="preserve">
<value>取消</value>
Expand Down
2 changes: 1 addition & 1 deletion src/LipUI/LipUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls.Markdown" Version="7.1.2" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.231115000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.2428" />
<PackageReference Include="Octokit" Version="9.0.0" />
<PackageReference Include="Octokit" Version="9.1.0" />
<PackageReference Include="PInvoke.User32" Version="0.7.124" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>
Expand Down
9 changes: 6 additions & 3 deletions src/LipUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ public MainWindow()

Closed += MainWindow_Closed;

Helpers.MainWindow = this;
Services.MainWindow = this;
}

private async void MainWindow_Closed(object sender, WindowEventArgs args)
=> await Main.SaveConfigAsync();
{
Services.OnWindowClosed();
await Main.SaveConfigAsync();
}

private NativeMethods.WinProc? newWndProc = null;
private nint oldWndProc = nint.Zero;
Expand Down Expand Up @@ -297,7 +300,7 @@ private bool TryGoBack()
NavView.DisplayMode is NavigationViewDisplayMode.Minimal))
return false;

ContentFrame.GoBack();
ContentFrame.TryGoBack();
return true;
}

Expand Down
7 changes: 3 additions & 4 deletions src/LipUI/Models/GlobalResources.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using LipUI.Assets;
using LipUI.Pages;
using Microsoft.UI.Xaml.Media.Imaging;


namespace LipUI.Models;

internal static class GlobalResources
{
public static readonly BitmapImage GrassBlock = Helpers.CreateImageFromBytes(Images.grass_block);
public static readonly BitmapImage Netherrack = Helpers.CreateImageFromBytes(Images.netherrack);
public static readonly BitmapImage Glass = Helpers.CreateImageFromBytes(Images.glass);
public static readonly BitmapImage GrassBlock = Services.CreateImageFromBytes(Images.grass_block);
public static readonly BitmapImage Netherrack = Services.CreateImageFromBytes(Images.netherrack);
public static readonly BitmapImage Glass = Services.CreateImageFromBytes(Images.glass);
}
6 changes: 4 additions & 2 deletions src/LipUI/Models/ILipUIModules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ public interface ILipUIModulesNonGeneric

public Type PageType { get; }

public FrameworkElement? IconContent { get; }
public FrameworkElement? IconContent { get => null; }

public Brush? IconBackground { get; }
public Brush? IconBackground { get => null; }

public void OnIconInitialze(ModuleIcon icon) { }

public void OnExit() { }
}

public interface ILipUIModules<TSelf> : ILipUIModulesNonGeneric
Expand Down
5 changes: 2 additions & 3 deletions src/LipUI/Pages/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Loaded="Page_Loaded">
mc:Ignorable="d">

<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<ResourceDictionary x:Key="Default">
<SolidColorBrush x:Key="MyButtonBackgroundDisabledBrush" Color="Transparent"/>
<SolidColorBrush x:Key="ButtonDisabledBorderThemeBrush" Color="Transparent"/>
<StaticResource x:Key="ButtonBackgroundDisabled" ResourceKey="MyButtonBackgroundDisabledBrush"/>
Expand Down
38 changes: 11 additions & 27 deletions src/LipUI/Pages/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,17 @@ private async void RefreshIcon()
{
ServerInstance? instance = Main.Config.SelectedServer;
ServerIconImage.Source = await ServerIcon.GetIcon(instance);
ServerDesc.Text = instance is null || string.IsNullOrWhiteSpace(instance.Description) ?
"home$emptyDesc".GetLocalized() : instance.Description;
ServerDesc.Text =
instance is null ?
"home$nullServerPath".GetLocalized() :
string.IsNullOrWhiteSpace(instance.Description) ?
"home$emptyDesc".GetLocalized() :
instance.Description;
}

private void SelectServerButton_Click(object sender, RoutedEventArgs e)
=> Frame.Navigate(typeof(ServerSelectionPage), () => { DispatcherQueue.TryEnqueue(() => { RefreshIcon(); }); });

private void Page_Loaded(object sender, RoutedEventArgs e)
=> ShowLipInstallerPageIfNotExist();

private void ShowLipInstallerPageIfNotExist()
{
if (File.Exists(Main.Config.Settings.LipPath))
{
return;
}

var dialog = new ContentDialog()
{
XamlRoot = XamlRoot,
Content = new LipInstallerView()
};

Task.Run(() =>
{
Task.Delay(100);
DispatcherQueue.TryEnqueue(async () => await dialog.ShowAsync());
});
}

private void StartServerButton_Click(object sender, RoutedEventArgs e)
{
if (Main.Config.SelectedServer is null)
Expand Down Expand Up @@ -97,7 +78,10 @@ private void BackButton_PointerExited(object sender, PointerRoutedEventArgs e)
=> AnimatedIcon.SetState(BackAnimatedIcon, "Normal");

private void BackButton_Click(object sender, RoutedEventArgs e)
=> ContentFrame.GoBack();
{
ModuleIcon.OnExit(ContentFrame.Content.GetType());
ContentFrame.TryGoBack();
}

private void ContentFrame_Navigated(object sender, NavigationEventArgs e)
{
Expand All @@ -113,7 +97,7 @@ private void ContentFrame_Navigated(object sender, NavigationEventArgs e)
}
catch (Exception ex)
{
await Helpers.ShowInfoBarAsync(ex);
await Services.ShowInfoBarAsync(ex);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using System.Threading.Tasks;
using Windows.System;
using Windows.UI;
using static LipUI.Pages.Helpers;
using static LipUI.Services;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
Expand Down Expand Up @@ -64,7 +64,7 @@ private async void Page_Loaded(object sender, RoutedEventArgs e)
{
await Task.Delay(500);
await ShowInfoBarAsync("propertiesEditor$nullServerPath".GetLocalized(), null, InfoBarSeverity.Error);
Frame.GoBack();
Frame.TryGoBack();
return;
};

Expand Down Expand Up @@ -126,7 +126,7 @@ private async void LoadPropertiesAndCreateUI()
catch (Exception ex)
{
await ShowInfoBarAsync(ex, default, null);
Frame.GoBack();
Frame.TryGoBack();
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/LipUI/Pages/IndexPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ where tooth.Name.ToLower().Contains(str)
}
catch (Exception ex)
{
await Helpers.ShowInfoBarAsync(ex);
await Services.ShowInfoBarAsync(ex);
}
});
}
Expand Down Expand Up @@ -143,7 +143,7 @@ where tooth.Name.ToLower().Contains(query)
}
catch (Exception ex)
{
await Helpers.ShowInfoBarAsync(ex);
await Services.ShowInfoBarAsync(ex);
}
});

Expand Down
13 changes: 11 additions & 2 deletions src/LipUI/Pages/LipExecutionPanelPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ public LipConsoleHandler(LipExecutionPanelPage page)

public void Run()
{
Action closed = null!;
closed = () =>
{
process?.Kill();
Services.WindowClosed -= closed;
};
Services.WindowClosed += closed;

dispatcherQueue.TryEnqueue(async () =>
{
lip = await Main.CreateLipConsole(page.XamlRoot);
Expand All @@ -96,9 +104,9 @@ public void Run()
page.LipWorkingInfoText.Text = string.Empty;
page.ProgressRateText.Text = string.Empty;

await Helpers.ShowInfoBarAsync(
await Services.ShowInfoBarAsync(
"infobar$error".GetLocalized(),
"lipExecution$nullServerPath".GetLocalized(),
"lipExecution$nullLipPath".GetLocalized(),
InfoBarSeverity.Error);

return;
Expand Down Expand Up @@ -127,6 +135,7 @@ await Helpers.ShowInfoBarAsync(

break;
}
Services.WindowClosed -= closed;

});
}
Expand Down
8 changes: 4 additions & 4 deletions src/LipUI/Pages/LocalPackagePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void ReloadPackage(IEnumerable<ToothPackage>? items = null)
}
catch (Exception ex)
{
await Helpers.ShowInfoBarAsync(ex);
await Services.ShowInfoBarAsync(ex);
}

if (arr is not null)
Expand Down Expand Up @@ -91,7 +91,7 @@ private void RefreshUpgradableTeeth()
}
catch (Exception ex)
{
await Helpers.ShowInfoBarAsync(ex);
await Services.ShowInfoBarAsync(ex);
return;
}

Expand Down Expand Up @@ -137,7 +137,7 @@ where tooth.Info.Name.ToLower().Contains(str)
}
catch (Exception ex)
{
await Helpers.ShowInfoBarAsync(ex);
await Services.ShowInfoBarAsync(ex);
}
});
}
Expand Down Expand Up @@ -166,7 +166,7 @@ where tooth.Info.Name.ToLower().Contains(query)
}
catch (Exception ex)
{
await Helpers.ShowInfoBarAsync(ex);
await Services.ShowInfoBarAsync(ex);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/LipUI/Pages/ServerSelectionPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<ResourceDictionary x:Key="Default">
<SolidColorBrush x:Key="ToggleButtonBackgroundChecked" Color="{ThemeResource LayerOnAcrylicFillColorDefault}"/>
<SolidColorBrush x:Key="ToggleButtonBackgroundCheckedPointerOver" Color="{ThemeResource LayerOnAcrylicFillColorDefault}"/>
<SolidColorBrush x:Key="ToggleButtonBackgroundCheckedPressed" Color="{ThemeResource LayerOnAcrylicFillColorDefault}"/>
Expand Down
4 changes: 2 additions & 2 deletions src/LipUI/Pages/ServerSelectionPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private async ValueTask ItemClick_AddServerViewClicked(object sender, ItemClickE
{
if (instance == server)
{
await Helpers.ShowInfoBarAsync(
await Services.ShowInfoBarAsync(
"infoBar$error".GetLocalized(),
"serverSelection$existed".GetLocalized(),
InfoBarSeverity.Error);
Expand Down Expand Up @@ -219,7 +219,7 @@ private async void ItemClick_SelectMode(object sender, ItemClickEventArgs e)
Main.Config.SelectedServer = (e.ClickedItem as ServerInstanceView)!.ServerInstance;
refreshIcon!();
await Main.SaveConfigAsync();
Frame.GoBack();
Frame.TryGoBack();
}

private void ItemClick_EditMode(object sender, ItemClickEventArgs e)
Expand Down
23 changes: 20 additions & 3 deletions src/LipUI/Pages/Helpers.cs → src/LipUI/Services.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,29 @@
using Microsoft.Windows.ApplicationModel.Resources;
using System.Threading.Tasks;

namespace LipUI.Pages;
namespace LipUI;

public static class ResourceExtensions
internal static class ResourceExtensions
{
private static readonly ResourceLoader _resourceLoader = new();

public static string GetLocalized(this string resourceKey) => _resourceLoader.GetString(resourceKey);
}

internal static class Helpers
internal static class FrameExtensions
{
public static bool TryGoBack(this Frame frame)
{
if (frame.CanGoBack)
{
frame.GoBack();
return true;
}
return false;
}
}

internal static class Services
{
public static BitmapImage CreateImageFromBytes(byte[] bytes)
{
Expand Down Expand Up @@ -70,4 +83,8 @@ public static async ValueTask ShowInfoBarAsync(
interval = TimeSpan.FromSeconds(5);
await ShowInfoBarAsync(ex.GetType().Name, ex.Message, InfoBarSeverity.Error, interval, barContent);
}

public static event Action? WindowClosed;

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

0 comments on commit c49ce1b

Please sign in to comment.