diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-12-13 00:23:55 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-12-13 00:23:55 +0200 |
| commit | fea4547613d57f8fcc8cb94671c54d82a5b11dbb (patch) | |
| tree | 19db6439b6694884da2414df5d6ae92ba2464bcf /Software/Visual_Studio/PPC/Modules | |
| parent | 85e27ca4c292329a894a49ed950912285465fa2e (diff) | |
| download | Tango-fea4547613d57f8fcc8cb94671c54d82a5b11dbb.tar.gz Tango-fea4547613d57f8fcc8cb94671c54d82a5b11dbb.zip | |
Added browser cef loading error support.
Implemented better module loading error handling in general.
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules')
6 files changed, 89 insertions, 24 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs index cd8372277..dc7b294d5 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs @@ -10,6 +10,8 @@ using Tango.PPC.Browser.Views; using Tango.SharedUI.Helpers; using Tango.Core.DI; using Tango.PPC.Common.Application; +using System.IO; +using Tango.Core.Helpers; namespace Tango.PPC.Browser { @@ -68,7 +70,7 @@ namespace Tango.PPC.Browser { get { - return typeof(BrowserView); + return IsCefAvailable() ? typeof(BrowserView) : typeof(ErrorView); } } @@ -83,6 +85,11 @@ namespace Tango.PPC.Browser } } + private bool IsCefAvailable() + { + return File.Exists(Path.Combine(AssemblyHelper.GetCurrentAssemblyFolder(), "x86", "CefSharp.Core.dll")); + } + /// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Tango.PPC.Browser.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Tango.PPC.Browser.csproj index 58d525c32..b742d4d75 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Tango.PPC.Browser.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Tango.PPC.Browser.csproj @@ -80,6 +80,10 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="Views\ErrorView.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> </ItemGroup> <ItemGroup> <Compile Include="..\..\..\Versioning\GlobalVersionInfo.cs"> @@ -110,6 +114,9 @@ <Compile Include="Views\BrowserView.xaml.cs"> <DependentUpon>BrowserView.xaml</DependentUpon> </Compile> + <Compile Include="Views\ErrorView.xaml.cs"> + <DependentUpon>ErrorView.xaml</DependentUpon> + </Compile> <EmbeddedResource Include="Properties\Resources.resx"> <Generator>ResXFileCodeGenerator</Generator> <LastGenOutput>Resources.Designer.cs</LastGenOutput> diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/BrowserViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/BrowserViewVM.cs index 9f66bb6a6..9650aa342 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/BrowserViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/BrowserViewVM.cs @@ -1,6 +1,4 @@ -using CefSharp; -using CefSharp.Wpf; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -42,23 +40,6 @@ namespace Tango.PPC.Browser.ViewModels { DisplayAddressBar = true; - if (!DesignMode) - { - try - { - var settings = new CefSettings(); - settings.BrowserSubprocessPath = @"x86\CefSharp.BrowserSubprocess.exe"; - settings.UserAgent = "Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"; - - Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null); - } - catch (Exception ex) - { - //Log Here Not Throw! - throw; - } - } - GoCommand = new RelayCommand(Go); } @@ -76,6 +57,7 @@ namespace Tango.PPC.Browser.ViewModels public override void OnNavigatedTo() { base.OnNavigatedTo(); + KeyboardView.Default.OutputMode = KeyboardOutputMode.Windows; if (!_isFromObject) @@ -92,9 +74,9 @@ namespace Tango.PPC.Browser.ViewModels KeyboardView.Default.OutputMode = KeyboardOutputMode.Wpf; } - public override Task<bool> OnNavigateBackRequest() + public override Task<bool> OnNavigateBackRequest() { - if (View.CanGoBack()) + if (View != null && View.CanGoBack()) { View.GoBack(); return Task.FromResult(false); @@ -115,7 +97,10 @@ namespace Tango.PPC.Browser.ViewModels private void Go() { - View.NavigateTo(Address); + if (View != null) + { + View.NavigateTo(Address); + } } public void OnNavigatedToWithObject(BrowserNavigationRequest obj) diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs index e3f4c29e3..cdba301ed 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs @@ -19,6 +19,7 @@ using CefSharp; using CefSharp.Wpf; using Tango.Core.DI; using Tango.Core.Helpers; +using Tango.Logging; using Tango.PPC.Browser.BoundsObjects; using Tango.PPC.Browser.ViewContracts; using Tango.PPC.Common.Helpers; @@ -35,6 +36,19 @@ namespace Tango.PPC.Browser.Views public BrowserView() { + try + { + var settings = new CefSettings(); + settings.BrowserSubprocessPath = @"x86\CefSharp.BrowserSubprocess.exe"; + settings.UserAgent = "Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"; + + Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null); + } + catch (Exception ex) + { + LogManager.Default.Log(ex, "Error loading cef."); + } + InitializeComponent(); TangoIOC.Default.Register<IBrowserView>(this); diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/ErrorView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/ErrorView.xaml new file mode 100644 index 000000000..25e3381ba --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/ErrorView.xaml @@ -0,0 +1,23 @@ +<UserControl x:Class="Tango.PPC.Browser.Views.ErrorView" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:vm="clr-namespace:Tango.PPC.Browser.ViewModels" + xmlns:global="clr-namespace:Tango.PPC.Browser" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:local="clr-namespace:Tango.PPC.Browser.Views" + mc:Ignorable="d" + d:DesignHeight="1280" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:BrowserViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.BrowserViewVM}" Background="{StaticResource TangoPrimaryBackgroundBrush}"> + <Grid> + <Grid Background="White" IsHitTestVisible="False"> + <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> + <touch:TouchIcon Icon="Alert" Foreground="{StaticResource TangoGrayTextBrush}" Width="100" Height="100" /> + <TextBlock HorizontalAlignment="Center" Foreground="{StaticResource TangoGrayTextBrush}" FontSize="40" Margin="0 20 0 0">Browser Not Loaded</TextBlock> + <TextBlock Margin="0 10 0 0" Foreground="{StaticResource TangoGrayTextBrush}" HorizontalAlignment="Center" Width="600" TextAlignment="Center" TextWrapping="Wrap"> + The browser module was not loaded properly or has caused some error. + </TextBlock> + </StackPanel> + </Grid> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/ErrorView.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/ErrorView.xaml.cs new file mode 100644 index 000000000..0d59b80f0 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/ErrorView.xaml.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +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 Tango.PPC.Browser.ViewContracts; + +namespace Tango.PPC.Browser.Views +{ + /// <summary> + /// Interaction logic for ErrorView.xaml + /// </summary> + public partial class ErrorView : UserControl + { + public ErrorView() + { + InitializeComponent(); + } + } +} |
