Skip to content

Commit

Permalink
Merge pull request #143 from U-C-S/experiment/winui3
Browse files Browse the repository at this point in the history
Experiment: Try building with WinUI (yet again)
  • Loading branch information
U-C-S authored Aug 15, 2024
2 parents 702ddcb + e844cca commit 7e861f7
Show file tree
Hide file tree
Showing 47 changed files with 1,804 additions and 23 deletions.
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("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hurl.Settings", "Source\Hurl.Settings\Hurl.Settings.csproj", "{C4DB15A3-1D60-437C-BD29-688E9E280E87}"
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
{C4DB15A3-1D60-437C-BD29-688E9E280E87}.Debug|Any CPU.ActiveCfg = Debug|x64
{C4DB15A3-1D60-437C-BD29-688E9E280E87}.Debug|Any CPU.Build.0 = Debug|x64
{C4DB15A3-1D60-437C-BD29-688E9E280E87}.Debug|ARM64.ActiveCfg = Debug|ARM64
{C4DB15A3-1D60-437C-BD29-688E9E280E87}.Debug|ARM64.Build.0 = Debug|ARM64
{C4DB15A3-1D60-437C-BD29-688E9E280E87}.Debug|x64.ActiveCfg = Debug|x64
{C4DB15A3-1D60-437C-BD29-688E9E280E87}.Debug|x64.Build.0 = Debug|x64
{C4DB15A3-1D60-437C-BD29-688E9E280E87}.Debug|x86.ActiveCfg = Debug|x64
{C4DB15A3-1D60-437C-BD29-688E9E280E87}.Debug|x86.Build.0 = Debug|x64
{C4DB15A3-1D60-437C-BD29-688E9E280E87}.Release|Any CPU.ActiveCfg = Release|x64
{C4DB15A3-1D60-437C-BD29-688E9E280E87}.Release|Any CPU.Build.0 = Release|x64
{C4DB15A3-1D60-437C-BD29-688E9E280E87}.Release|ARM64.ActiveCfg = Release|ARM64
{C4DB15A3-1D60-437C-BD29-688E9E280E87}.Release|ARM64.Build.0 = Release|ARM64
{C4DB15A3-1D60-437C-BD29-688E9E280E87}.Release|x64.ActiveCfg = Release|x64
{C4DB15A3-1D60-437C-BD29-688E9E280E87}.Release|x64.Build.0 = Release|x64
{C4DB15A3-1D60-437C-BD29-688E9E280E87}.Release|x86.ActiveCfg = Release|x64
{C4DB15A3-1D60-437C-BD29-688E9E280E87}.Release|x86.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion Source/Hurl.BrowserSelector/Helpers/UriLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static void ResolveAutomatically(string uri, Browser browser, int? altLau
{
if (altLaunchIndex is not null)
{
if (browser.AlternateLaunches.Length - 1 < altLaunchIndex) //
if (browser.AlternateLaunches?.Count - 1 < altLaunchIndex) //
throw new Exception("Alternate Launch profile does not exist");
else
Alternative(uri, browser, (int)altLaunchIndex);
Expand Down
27 changes: 17 additions & 10 deletions Source/Hurl.BrowserSelector/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async private void Window_KeyEvents(object sender, KeyEventArgs e)
break;
case Key.R:
MinimizeWindow();
Process.Start(Constants.SETTINGS_APP);
Process.Start(Constants.SETTINGS_APP, "--page rulesets");
break;
case Key.T:
new TimeSelectWindow(SettingsGlobal.Value.Browsers).ShowDialog();
Expand All @@ -133,7 +133,7 @@ private void LinkCopyBtnClick(object sender, RoutedEventArgs e)
}
}

private void SettingsBtnClick(object sender, RoutedEventArgs e) => Process.Start("explorer", "\"" + Constants.APP_SETTINGS_MAIN + "\"");
private void SettingsBtnClick(object sender, RoutedEventArgs e) => Process.Start(Constants.SETTINGS_APP, "--page settings");
private void Draggable(object sender, MouseButtonEventArgs e) => DragMove();
private void CloseBtnClick(object sender, RoutedEventArgs e) => MinimizeWindow();

Expand Down Expand Up @@ -163,7 +163,7 @@ private void TrayMenuItem_OnClick(object sender, RoutedEventArgs e)
ShowWindow();
break;
case "settings":
Process.Start("explorer", "\"" + Constants.APP_SETTINGS_MAIN + "\"");
Process.Start(Constants.SETTINGS_APP, "--page settings");
break;
case "exit":
Application.Current.Shutdown();
Expand Down Expand Up @@ -198,15 +198,22 @@ private void PositionWindowUnderTheMouse()
{
var settings = SettingsGlobal.Value;

if (settings.AppSettings != null && settings.AppSettings.LaunchUnderMouse)
try
{
var transform = PresentationSource.FromVisual(this).CompositionTarget.TransformFromDevice;
var mouse = transform.Transform(CursorPosition.LimitCursorWithin((int)Width, (int)Height));
Left = mouse.X;
Top = mouse.Y;
if (settings.AppSettings != null && settings.AppSettings.LaunchUnderMouse)
{
var transform = PresentationSource.FromVisual(this)?.CompositionTarget?.TransformFromDevice;
if (transform is Matrix t)
{
var mouse = t.Transform(CursorPosition.LimitCursorWithin((int)Width, (int)Height));
Left = mouse.X;
Top = mouse.Y;

Debug.WriteLine($"{Left}×{Top} with screen resolution: {SystemParameters.FullPrimaryScreenWidth}×{SystemParameters.FullPrimaryScreenHeight}");
Debug.WriteLine($"{Left}×{Top} with screen resolution: {SystemParameters.FullPrimaryScreenWidth}×{SystemParameters.FullPrimaryScreenHeight}");
}
}
}
catch (Exception _) { }
}

private void Button_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -236,6 +243,6 @@ async private void Linkpreview_Click(object sender, RoutedEventArgs e)
private void Button_Click_1(object sender, RoutedEventArgs e)
{
MinimizeWindow();
Process.Start(Constants.SETTINGS_APP);
Process.Start(Constants.SETTINGS_APP, "--page rulesets");
}
}
5 changes: 3 additions & 2 deletions Source/Hurl.Library/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ public class Constants
public const string DESCRIPTION = "Hurl - A tool to select the browsers dynamically";
public const string URLAssociations = "HandleURL3721";
public const string VERSION = "0.9.0";
public const string SOURCE_CODE_LINK= "https://github.com/U-C-S/Hurl";

public static string APP_PARENT_DIR = AppContext.BaseDirectory;
public static string APP_LAUNCH_PATH = Environment.GetCommandLineArgs()[0];
public static string ROAMING = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
public static string APP_SETTINGS_DIR = Path.Combine(ROAMING, "Hurl");
public static string APP_SETTINGS_MAIN = Path.Combine(APP_SETTINGS_DIR, "UserSettings.json");
#if DEBUG
public static string SETTINGS_APP = Path.GetFullPath(Path.Combine(APP_PARENT_DIR, "../../../../Hurl.RulesetManager/bin/Debug/net8.0-windows/Hurl.RulesetManager.exe"));
public static string SETTINGS_APP = Path.GetFullPath(Path.Combine(APP_PARENT_DIR, "../../../../Hurl.Settings/bin/x64/Debug/net8.0-windows10.0.22621.0/Hurl.Settings.exe"));
#else
public static string SETTINGS_APP = Path.Combine(APP_PARENT_DIR, "Hurl.RulesetManager.exe");
public static string SETTINGS_APP = Path.Combine(APP_PARENT_DIR, "Hurl.Settings.exe");
#endif

public const string NEW_LINE = "1&#x0a;";
Expand Down
10 changes: 10 additions & 0 deletions Source/Hurl.Library/Models/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,15 @@ public class AppSettings

public string BackgroundType { get; set; } = "mica";

public bool RuleMatching { get; set; } = false;

public int[] WindowSize { get; set; } = [420, 210];
}


public enum BackgroundMaterial
{
Acrylic,
Mica,
Solid
}
4 changes: 2 additions & 2 deletions Source/Hurl.Library/Models/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public Browser(string Name, string ExePath)

public string LaunchArgs { get; set; }

public AlternateLaunch[] AlternateLaunches { get; set; }
public List<AlternateLaunch> AlternateLaunches { get; set; }

public string CustomIconPath { get; set; }

Expand Down Expand Up @@ -57,7 +57,7 @@ public Visibility ShowAdditionalBtn
{
get
{
return AlternateLaunches == null || AlternateLaunches.Length == 0 ? Visibility.Hidden : Visibility.Visible;
return AlternateLaunches == null || AlternateLaunches.Count == 0 ? Visibility.Hidden : Visibility.Visible;
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions Source/Hurl.Library/Models/Ruleset.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;

namespace Hurl.Library.Models;

public class Ruleset
{
[JsonIgnore]
public Guid Id { get; set; } = Guid.NewGuid();

public List<string> Rules { get; set; }

public string RulesetName { get; set; }
Expand All @@ -17,9 +20,9 @@ public class Ruleset
public enum RuleMode
{
Domain,
String,
Glob,
Regex,
Glob
String,
}

public class Rule
Expand Down
6 changes: 3 additions & 3 deletions Source/Hurl.Library/Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public class Settings

public string LastUpdated { get; set; } = DateTime.Now.ToString();

public List<Browser> Browsers { get; set; }
public List<Browser> Browsers { get; set; } = [];

public AppSettings AppSettings { get; set; }
public AppSettings AppSettings { get; set; } = new AppSettings();

public List<Ruleset> Rulesets { get; set; }
public List<Ruleset> Rulesets { get; set; } = [];
}
16 changes: 16 additions & 0 deletions Source/Hurl.Settings/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<Application
x:Class="Hurl.Settings.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Hurl.Settings">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
</ResourceDictionary.MergedDictionaries>

<SolidColorBrush x:Key="WindowCaptionBackground">Transparent</SolidColorBrush>
</ResourceDictionary>
</Application.Resources>
</Application>
47 changes: 47 additions & 0 deletions Source/Hurl.Settings/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Microsoft.UI.Xaml;
using System;
using System.Diagnostics;

namespace Hurl.Settings;

public partial class App : Application
{
public App()
{
this.InitializeComponent();
}

private MainWindow m_window;

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
var cmdArgs = Environment.GetCommandLineArgs();

m_window = new MainWindow();

if (cmdArgs.Length > 1)
{
ProcessArgs(cmdArgs);
}
else
{
m_window.Activate();
}
}


void ProcessArgs(string[] args)
{
Debug.WriteLine(args[0]);
var primaryArg = args[1];

if (primaryArg.Equals("--page"))
{
if (args.Length > 2)
{
m_window.NavigateToPage(args[2]);
m_window.Activate();
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Source/Hurl.Settings/Assets/StoreLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions Source/Hurl.Settings/Controls/ComingSoon.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8" ?>
<UserControl
x:Class="Hurl.Settings.Controls.ComingSoon"
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="using:Hurl.Settings.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<StackPanel
Padding="4"
HorizontalAlignment="Center"
Background="{StaticResource SubtleFillColorTertiary}"
CornerRadius="8">
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}"
Style="{StaticResource TitleTextBlockStyle}"
Text="Soon™" />
<NavigationViewItemSeparator Width="320" />
<TextBlock
Width="400"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="Editing the values here is coming soon. In the meantime, you can edit the JSON file directly."
TextAlignment="Center"
TextWrapping="Wrap" />
<Button
Margin="0,12"
HorizontalAlignment="Center"
Click="Button_Click"
Style="{StaticResource AccentButtonStyle}">
Edit the JSON file
</Button>
</StackPanel>
</UserControl>
19 changes: 19 additions & 0 deletions Source/Hurl.Settings/Controls/ComingSoon.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Hurl.Library;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System.Diagnostics;

namespace Hurl.Settings.Controls;

public sealed partial class ComingSoon : UserControl
{
public ComingSoon()
{
this.InitializeComponent();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
Process.Start("explorer", "\"" + Constants.APP_SETTINGS_MAIN + "\"");
}
}
28 changes: 28 additions & 0 deletions Source/Hurl.Settings/Controls/NewRuleCard.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>
<UserControl
x:Class="Hurl.Settings.Controls.NewRuleCard"
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="using:Hurl.Settings.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="using:CommunityToolkit.WinUI.Controls"
mc:Ignorable="d">
<Grid>
<toolkit:SettingsCard>
<toolkit:SettingsCard.Header>
<StackPanel Orientation="Horizontal" Spacing="8">
<ComboBox x:Name="RuleTypeControl" SelectedIndex="0" />
<TextBox
x:Name="RuleValueControl"
Width="240"
PlaceholderText="Rule" />
</StackPanel>
</toolkit:SettingsCard.Header>

<Button Click="DeleteButton_Click" Style="{StaticResource EllipsisButton}">
<SymbolIcon Symbol="Delete" />
</Button>
</toolkit:SettingsCard>
</Grid>
</UserControl>
42 changes: 42 additions & 0 deletions Source/Hurl.Settings/Controls/NewRuleCard.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Hurl.Library.Models;
using Microsoft.UI.Xaml.Controls;
using System;

namespace Hurl.Settings.Controls;

public sealed partial class NewRuleCard : UserControl
{
public NewRuleCard()
{
InitializeComponent();

RuleTypeControl.ItemsSource = Enum.GetValues(typeof(RuleMode));
}

public NewRuleCard(Rule rule)
{
InitializeComponent();
var ruleModes = Enum.GetValues(typeof(RuleMode));

RuleTypeControl.ItemsSource = ruleModes;
RuleTypeControl.SelectedIndex = Array.IndexOf(ruleModes, rule.Mode); ;
RuleValueControl.Text = rule.RuleContent;
}

public Rule? ConstructRule()
{
var ruleType = RuleTypeControl.SelectedValue.ToString();
var ruleValue = RuleValueControl.Text;

if (!string.IsNullOrWhiteSpace(ruleValue))
return new Rule(ruleValue, ruleType);
return null;
}

private void DeleteButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
if (Parent is StackPanel stackPanel)
stackPanel.Children.Remove(this);
}
}

Loading

0 comments on commit 7e861f7

Please sign in to comment.