Skip to content

Commit

Permalink
Merge pull request #155 from BalassaMarton/webview-newwindow
Browse files Browse the repository at this point in the history
Support multiple web windows
  • Loading branch information
BalassaMarton authored Feb 21, 2023
2 parents dae97c6 + f880459 commit fee34a5
Show file tree
Hide file tree
Showing 17 changed files with 237 additions and 271 deletions.
33 changes: 17 additions & 16 deletions Tryouts/Prototypes/Shell/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@
// * and limitations under the License.
// */

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows;
using Shell.Utilities;

namespace Shell
{
Expand All @@ -30,17 +24,24 @@ public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
if (e.Args.Length != 0)
if (e.Args.Length != 0
&& CommandLineParser.TryParse<WebWindowOptions>(e.Args, out var webWindowOptions)
&& webWindowOptions.Url != null)
{
MainWebWindowOptions webWindowOptions = MainWebWindowOptionsParser.Parse(e.Args);
Application.Current.MainWindow = new MainWebWindow(webWindowOptions);
Application.Current.MainWindow.Show();
}
else
{
Application.Current.MainWindow = new MainWindow();
Application.Current.MainWindow.Show();
StartWithWebWindowOptions(webWindowOptions);

return;
}

Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
new MainWindow().Show();
}

private void StartWithWebWindowOptions(WebWindowOptions options)
{
var webWindow = new WebWindow(options);
Application.Current.ShutdownMode = ShutdownMode.OnLastWindowClose;
webWindow.Show();
}
}
}
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
46 changes: 0 additions & 46 deletions Tryouts/Prototypes/Shell/MainWebWindow.xaml.cs

This file was deleted.

22 changes: 0 additions & 22 deletions Tryouts/Prototypes/Shell/MainWebWindowOptions.cs

This file was deleted.

47 changes: 0 additions & 47 deletions Tryouts/Prototypes/Shell/MainWebWindowOptionsParser.cs

This file was deleted.

57 changes: 21 additions & 36 deletions Tryouts/Prototypes/Shell/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,11 @@
// * and limitations under the License.
// */

using Manifest;
using Shell.ImageSource;
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 @@ -38,47 +25,45 @@ namespace Shell
/// </summary>
public partial class MainWindow : Window
{
internal List<WebContent> WebContentList { get; set; } = new List<WebContent>();
private ManifestModel _config;
private ModuleModel[]? _modules;
private ImageSourceProvider _iconProvider = new ImageSourceProvider(new EnvironmentImageSourcePolicy());
internal List<WebWindow> webWindows { get; set; } = new List<WebWindow>();
private ManifestModel config;
private ModuleModel[]? modules;

public MainWindow()
{
InitializeComponent();

_config = ManifestParser.OpenManifestFile("exampleManifest.json");
_modules = _config.Modules;
DataContext = _modules;
config = ManifestParser.OpenManifestFile("exampleManifest.json");
modules = config.Modules;
DataContext = modules;
}

private void CreateViews(ModuleModel item)
private void CreateWebWindow(ModuleModel item)
{
var opt = new WebContentOptions()
var options = new WebWindowOptions
{
Title = item.AppName,
Uri = new Uri(item.Url),
IconUri = string.IsNullOrEmpty(item.IconUrl) ? null : new Uri(item.IconUrl)
Url = item.Url,
IconUrl = item.IconUrl
};

var webContent = new WebContent(opt, _iconProvider);
webContent.Owner = this;
webContent.Closed += WebContent_Closed;

WebContentList.Add(webContent);
webContent.Show();
var webWindow = new WebWindow(options);
webWindow.Owner = this;
webWindow.Closed += WebWindowClosed;
webWindows.Add(webWindow);
webWindow.Show();
}

private void WebContent_Closed(object? sender, EventArgs e)
private void WebWindowClosed(object? sender, EventArgs e)
{
WebContentList.Remove((WebContent)sender);
webWindows.Remove((WebWindow)sender!);
}

private void ShowChild_Click(object sender, RoutedEventArgs e)
{
var context = ((Button)sender).DataContext;

CreateViews((ModuleModel)context);
CreateWebWindow((ModuleModel)context);
}
}
}
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": "--title=Jane --width=1800 --height=800 --url=http://www.google.com --icon=/images/branding/googleg/1x/googleg_standard_color_128dp.png"
"commandLineArgs": "--title Jane --width 1800 --height 800 --url http://www.google.com --icon /images/branding/googleg/1x/googleg_standard_color_128dp.png"
}
}
}
12 changes: 6 additions & 6 deletions Tryouts/Prototypes/Shell/Shell.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
</PropertyGroup>

<ItemGroup>
<None Remove="MainWebWindow.xaml" />
<None Remove="MainWindow.xaml" />
<None Remove="WebContent.xaml" />
<None Remove="WebWindow.xaml" />
</ItemGroup>

<ItemGroup>
Expand All @@ -20,19 +19,20 @@
</ItemGroup>

<ItemGroup>
<Page Include="MainWebWindow.xaml">
<Page Include="WebWindow.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml" />
<Page Include="WebContent.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>

<ItemGroup>
<None Update="Manifest\exampleManifest.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<Folder Include="Utilities\" />
</ItemGroup>

</Project>
Loading

0 comments on commit fee34a5

Please sign in to comment.