Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hurl Rewrite Project #112

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Hurl.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hurl.Library", "Source\Hurl
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hurl.RulesetManager", "Source\Hurl.RulesetManager\Hurl.RulesetManager.csproj", "{CDA5934B-912D-43EF-8E9C-6AF5A829C036}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hurl.App", "Source\Hurl.App\Hurl.App.csproj", "{83456B10-257D-4A86-B6CC-F5D4CAB0DC90}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -73,6 +75,22 @@ Global
{CDA5934B-912D-43EF-8E9C-6AF5A829C036}.Release|x64.Build.0 = Release|Any CPU
{CDA5934B-912D-43EF-8E9C-6AF5A829C036}.Release|x86.ActiveCfg = Release|Any CPU
{CDA5934B-912D-43EF-8E9C-6AF5A829C036}.Release|x86.Build.0 = Release|Any CPU
{83456B10-257D-4A86-B6CC-F5D4CAB0DC90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{83456B10-257D-4A86-B6CC-F5D4CAB0DC90}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83456B10-257D-4A86-B6CC-F5D4CAB0DC90}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{83456B10-257D-4A86-B6CC-F5D4CAB0DC90}.Debug|ARM64.Build.0 = Debug|Any CPU
{83456B10-257D-4A86-B6CC-F5D4CAB0DC90}.Debug|x64.ActiveCfg = Debug|Any CPU
{83456B10-257D-4A86-B6CC-F5D4CAB0DC90}.Debug|x64.Build.0 = Debug|Any CPU
{83456B10-257D-4A86-B6CC-F5D4CAB0DC90}.Debug|x86.ActiveCfg = Debug|Any CPU
{83456B10-257D-4A86-B6CC-F5D4CAB0DC90}.Debug|x86.Build.0 = Debug|Any CPU
{83456B10-257D-4A86-B6CC-F5D4CAB0DC90}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83456B10-257D-4A86-B6CC-F5D4CAB0DC90}.Release|Any CPU.Build.0 = Release|Any CPU
{83456B10-257D-4A86-B6CC-F5D4CAB0DC90}.Release|ARM64.ActiveCfg = Release|Any CPU
{83456B10-257D-4A86-B6CC-F5D4CAB0DC90}.Release|ARM64.Build.0 = Release|Any CPU
{83456B10-257D-4A86-B6CC-F5D4CAB0DC90}.Release|x64.ActiveCfg = Release|Any CPU
{83456B10-257D-4A86-B6CC-F5D4CAB0DC90}.Release|x64.Build.0 = Release|Any CPU
{83456B10-257D-4A86-B6CC-F5D4CAB0DC90}.Release|x86.ActiveCfg = Release|Any CPU
{83456B10-257D-4A86-B6CC-F5D4CAB0DC90}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
18 changes: 18 additions & 0 deletions Source/Hurl.App/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Application
x:Class="Hurl.App.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Hurl.App"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
DispatcherUnhandledException="Application_DispatcherUnhandledException"
Startup="Application_Startup">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- TODO: Light/Dark -->
<ui:ThemesDictionary Theme="Dark" />
<ui:ControlsDictionary />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
37 changes: 37 additions & 0 deletions Source/Hurl.App/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Configuration;
using System.Data;
using System.Text.Json;
using System.Windows;
using System.Windows.Threading;

namespace Hurl.App;

public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
MainWindow mainWindow = new();
mainWindow.Show();
}

private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
// TODO: reuse the code across the projects
string ErrorMsgBuffer;
string ErrorWndTitle;
switch (e.Exception?.InnerException)
{
case JsonException:
ErrorMsgBuffer = "The UserSettings.json file is in invalid JSON format. \n";
ErrorWndTitle = "Invalid JSON";
break;
default:
ErrorMsgBuffer = "An unknown error has occurred. \n";
ErrorWndTitle = "Unknown Error";
break;

}
string errorMessage = string.Format("{0}\n{1}\n\n{2}", ErrorMsgBuffer, e.Exception.InnerException?.Message, e.Exception?.Message);
MessageBox.Show(errorMessage, ErrorWndTitle, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
10 changes: 10 additions & 0 deletions Source/Hurl.App/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
16 changes: 16 additions & 0 deletions Source/Hurl.App/Hurl.App.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="WPF-UI" Version="3.0.3" />
<PackageReference Include="WPF-UI.Tray" Version="3.0.3" />
</ItemGroup>

</Project>
20 changes: 20 additions & 0 deletions Source/Hurl.App/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<ui:FluentWindow
x:Class="Hurl.App.MainWindow"
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:local="clr-namespace:Hurl.App"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Title="MainWindow"
Width="800"
Height="450"
ExtendsContentIntoTitleBar="True"
WindowBackdropType="Mica"
WindowCornerPreference="Round"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">
<Grid>
<ui:TitleBar Title="Hurl [BETA]" Grid.ColumnSpan="3" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Urgently recommend not to use the same Grid idea

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it makes everything way too complicated. You need to remember to put everything in the middle, and you will never have a scrollviewer that touches the sides. The same effect can be achieved with MaxWidth of the content.

</Grid>
</ui:FluentWindow>
20 changes: 20 additions & 0 deletions Source/Hurl.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Hurl.App;

public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
}
}
53 changes: 53 additions & 0 deletions Source/Hurl.App/Utils/SingleInstance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hurl.App.Utils;

internal class SingleInstance
{
// TAKEN from https://github.com/BartoszCichecki/LenovoLegionToolkit/blob/master/LenovoLegionToolkit.WPF/App.xaml.cs
// TODO: Support sharing the Cmd Args between the instances
private const string MUTEX_NAME = "hurl_app_mutex";
private const string EVENT_NAME = "hurl_app_mutex";

private Mutex? _singleInstanceMutex;
private EventWaitHandle? _singleInstanceWaitHandle;

private void EnsureSingleInstance()
{
_singleInstanceMutex = new Mutex(true, MUTEX_NAME, out var isOwned);
_singleInstanceWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, EVENT_NAME);

if (!isOwned)
{
_singleInstanceWaitHandle.Set();
Shutdown();
return;
}

new Thread(() =>
{
while (_singleInstanceWaitHandle.WaitOne())
{
Current.Dispatcher.BeginInvoke(async () =>
{
if (Current.MainWindow is { } window)
{
window.BringToForeground();
}
else
{
await ShutdownAsync();
}
});
}
})
{
IsBackground = true
}.Start();
}
}