Skip to content

Commit

Permalink
Init Support for opening Uwp Browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
U-C-S committed Oct 11, 2024
1 parent 5b5afb6 commit 8a6c840
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Source/Hurl.BrowserSelector/Controls/BrowserButton.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public BrowserButton(Browser browser)

private void BrowserButton_Click(object sender, RoutedEventArgs e)
{
UriLauncher.Default(OpenedUri.Value, (Browser)DataContext);
UriLauncher.ResolveAutomatically(OpenedUri.Value, (Browser)DataContext, null);
MinimizeWindow();
}

Expand Down
19 changes: 18 additions & 1 deletion Source/Hurl.BrowserSelector/Helpers/UriLauncher.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
using Hurl.Library.Models;
using System;
using System.Diagnostics;
using Windows.System;

namespace Hurl.BrowserSelector.Helpers;

class UriLauncher
{
public static void ResolveAutomatically(string uri, Browser browser, int? altLaunchIndex)
{
if (altLaunchIndex is not null)
if (browser.IsUwp)
{
Uwp(uri, browser);
}
else if (altLaunchIndex is not null)
{
if (browser.AlternateLaunches?.Count - 1 < altLaunchIndex) //
throw new Exception("Alternate Launch profile does not exist");
Expand Down Expand Up @@ -62,5 +67,17 @@ public static void Alternative(string uri, Browser browser, AlternateLaunch alt)
Process.Start(browser.ExePath, args);
}
}

public static async void Uwp(string uri, Browser browser)
{
var uri_object = new Uri(uri);
var options = new LauncherOptions
{
//options.TargetApplicationPackageFamilyName = "TheBrowserCompany.Arc_ttt1ap7aakyb4";
//TargetApplicationPackageFamilyName = "Mozilla.Firefox_n80bbvh6b1yt2"
TargetApplicationPackageFamilyName = browser.ExePath
};
await Launcher.LaunchUriAsync(uri_object, options);
}
}

7 changes: 4 additions & 3 deletions Source/Hurl.BrowserSelector/Hurl.BrowserSelector.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
<UseWPF>true</UseWPF>
<Nullable>enable</Nullable>
Expand All @@ -10,7 +10,7 @@
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<ApplicationIcon>Assets\internet.ico</ApplicationIcon>
<StartupObject>Hurl.BrowserSelector.App</StartupObject>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<WindowsSdkPackageVersion>10.0.26100.47</WindowsSdkPackageVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget>
Expand All @@ -22,6 +22,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.5" />
<PackageReference Include="System.Drawing.Common" Version="8.0.10" />
<PackageReference Include="WPF-UI" Version="3.0.5" />
<PackageReference Include="WPF-UI.Tray" Version="3.0.5" />
Expand Down
4 changes: 4 additions & 0 deletions Source/Hurl.Library/IconExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ internal static class IconUtilites

public static ImageSource? ToImageSource(this Icon icon)
{
if (icon is null)
{
return null;
}
try
{
Bitmap bitmap = icon.ToBitmap();
Expand Down
2 changes: 2 additions & 0 deletions Source/Hurl.Library/Models/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public Browser(string Name, string ExePath)

public string ExePath { get; set; }

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

public string? LaunchArgs { get; set; }

public List<AlternateLaunch>? AlternateLaunches { get; set; }
Expand Down

0 comments on commit 8a6c840

Please sign in to comment.