Skip to content

Commit

Permalink
Merged changes from pull request morganstanley#154 (manual merge due …
Browse files Browse the repository at this point in the history
…to lots of renames)
  • Loading branch information
BalassaMarton committed Feb 21, 2023
1 parent ba79670 commit a3113eb
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 53 deletions.
4 changes: 3 additions & 1 deletion Tryouts/Prototypes/Shell/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
if (e.Args.Length != 0 && CommandLineParser.TryParse<WebWindowOptions>(e.Args, out var webWindowOptions))
if (e.Args.Length != 0
&& CommandLineParser.TryParse<WebWindowOptions>(e.Args, out var webWindowOptions)
&& webWindowOptions.Url != null)
{
StartWithWebWindowOptions(webWindowOptions);

Expand Down
4 changes: 0 additions & 4 deletions Tryouts/Prototypes/Shell/ImageSource/IImageSourcePolicy.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shell.ImageSource
{
Expand Down
26 changes: 10 additions & 16 deletions Tryouts/Prototypes/Shell/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,11 @@
// * and limitations under the License.
// */

using Manifest;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
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;
using Manifest;

namespace Shell
{
Expand All @@ -50,10 +38,16 @@ public MainWindow()
DataContext = modules;
}

private void CreateWebWindow(ModuleModel item)
private void CreateWebWindow(ModuleModel item)
{
var webWindow = new WebWindow(new WebWindowOptions{Url = item.Url});
webWindow.Title = item.AppName;
var options = new WebWindowOptions
{
Title = item.AppName,
Url = item.Url,
IconUrl = item.IconUrl
};

var webWindow = new WebWindow(options);
webWindow.Owner = this;
webWindow.Closed += WebWindowClosed;
webWindows.Add(webWindow);
Expand Down
4 changes: 0 additions & 4 deletions Tryouts/Prototypes/Shell/Manifest/ManifestModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
// * and limitations under the License.
// */

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;
using System.Text.Json;

namespace Manifest
Expand Down
6 changes: 0 additions & 6 deletions Tryouts/Prototypes/Shell/Manifest/ManifestParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@
// */

using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Policy;
using System.Text;
using System.Text.Json;
using System.Windows.Automation;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;

namespace Manifest
{
Expand Down
2 changes: 1 addition & 1 deletion Tryouts/Prototypes/Shell/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"Shell": {
"commandName": "Project",
"commandLineArgs": "--url \"https://google.com\" --width 1600 --height 900 --title \"Compose Demo\""
"commandLineArgs": "--title Jane --width 1800 --height 800 --url http://www.google.com --icon /images/branding/googleg/1x/googleg_standard_color_128dp.png"
}
}
}
10 changes: 5 additions & 5 deletions Tryouts/Prototypes/Shell/Utilities/CommandLineParser.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Collections.Generic;
using System.CommandLine.Parsing;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Parsing;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Reflection;

namespace Shell.Utilities;

Expand Down
15 changes: 0 additions & 15 deletions Tryouts/Prototypes/Shell/WebContentOptions.cs

This file was deleted.

19 changes: 19 additions & 0 deletions Tryouts/Prototypes/Shell/WebWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Windows;
using Microsoft.Web.WebView2.Core;
using Shell.ImageSource;

namespace Shell
{
Expand All @@ -17,6 +18,7 @@ public WebWindow(WebWindowOptions webWindowOptions)
Width = webWindowOptions.Width ?? WebWindowOptions.DefaultWidth;
Height = webWindowOptions.Height ?? WebWindowOptions.DefaultHeight;
webView.Source = new Uri(webWindowOptions.Url ?? WebWindowOptions.DefaultUrl);
TrySetIconUrl(webWindowOptions);

webView.CoreWebView2InitializationCompleted += (sender, args) =>
{
Expand All @@ -27,6 +29,23 @@ public WebWindow(WebWindowOptions webWindowOptions)
};
}

private readonly ImageSourceProvider _iconProvider = new ImageSourceProvider(new EnvironmentImageSourcePolicy());

private void TrySetIconUrl(WebWindowOptions webWindowOptions)
{
if (webWindowOptions.IconUrl == null)
return;

// TODO: What's the default URL if the app is running from a manifest? We should probably not allow relative urls in that case.
var appUrl = new Uri(webWindowOptions.Url ?? WebWindowOptions.DefaultUrl);
var iconUrl = webWindowOptions.IconUrl != null ? new Uri(webWindowOptions.IconUrl, UriKind.RelativeOrAbsolute) : null;

if (iconUrl != null)
{
Icon = _iconProvider.GetImageSource(iconUrl, appUrl);
}
}

private async void OnNewWindowRequested(CoreWebView2NewWindowRequestedEventArgs e)
{
e.Handled = true;
Expand Down
2 changes: 1 addition & 1 deletion Tryouts/Prototypes/Shell/WebWindowOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class WebWindowOptions
[Display(Description = $"Set the url for the web view. Default: {DefaultUrl}")]
public string? Url { get; set; }

[Display(Description = $"Set the icon url for the window.")]
[Display(Name = "icon", Description = $"Set the icon url for the window.")]
public string? IconUrl { get; set; }

[Display(Description = $"Set the width of the window. Default: 800")]
Expand Down

0 comments on commit a3113eb

Please sign in to comment.