Browse Source

Merge branch 'feature/blank-screen' into develop

Antony Male 4 years ago
parent
commit
8c986f873d

+ 9 - 0
src/SyncTrayzor/Bootstrapper.cs

@@ -27,6 +27,8 @@ using System.Reflection;
 using SyncTrayzor.Localization;
 using SyncTrayzor.Services.Ipc;
 using System.Net;
+using System.Windows.Media;
+using System.Windows.Interop;
 
 namespace SyncTrayzor
 {
@@ -195,6 +197,13 @@ namespace SyncTrayzor
             MessageBoxViewModel.DefaultFlowDirection = Localizer.FlowDirection;
 
             RecycleBinDeleter.Logger = s => LogManager.GetLogger(typeof(RecycleBinDeleter).FullName).Error(s);
+
+            // Workaround for Intel Xe processors, which mess up CefSharp unless we disable hardware
+            // rendering for WPF. See #606.
+            if (configuration.DisableHardwareRendering)
+            {
+                RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
+            }
         }
 
         protected override void Launch()

+ 19 - 1
src/SyncTrayzor/Pages/BarAlerts/BarAlertsViewModel.cs

@@ -1,6 +1,7 @@
 using Stylet;
 using SyncTrayzor.Pages.ConflictResolution;
 using SyncTrayzor.Services;
+using SyncTrayzor.Services.Config;
 using SyncTrayzor.Syncthing;
 using System;
 using System.Collections.Generic;
@@ -12,23 +13,33 @@ namespace SyncTrayzor.Pages.BarAlerts
         private readonly IAlertsManager alertsManager;
         private readonly ISyncthingManager syncthingManager;
         private readonly Func<ConflictResolutionViewModel> conflictResolutionViewModelFactory;
+        private readonly Func<IntelXeGraphicsAlertViewModel> intelXeGraphicsAlertViewModelFactory;
         private readonly IWindowManager windowManager;
+        private readonly IConfigurationProvider configurationProvider;
+        private readonly GraphicsCardDetector graphicsCardDetector;
 
         public BarAlertsViewModel(
             IAlertsManager alertsManager,
             ISyncthingManager syncthingManager,
             Func<ConflictResolutionViewModel> conflictResolutionViewModelFactory,
-            IWindowManager windowManager)
+            Func<IntelXeGraphicsAlertViewModel> intelXeGraphicsAlertViewModelFactory,
+            IWindowManager windowManager,
+            IConfigurationProvider configurationProvider,
+            GraphicsCardDetector graphicsCardDetector)
         {
             this.alertsManager = alertsManager;
             this.syncthingManager = syncthingManager;
             this.conflictResolutionViewModelFactory = conflictResolutionViewModelFactory;
+            this.intelXeGraphicsAlertViewModelFactory = intelXeGraphicsAlertViewModelFactory;
             this.windowManager = windowManager;
+            this.configurationProvider = configurationProvider;
+            this.graphicsCardDetector = graphicsCardDetector;
         }
 
         protected override void OnInitialActivate()
         {
             this.alertsManager.AlertsStateChanged += this.AlertsStateChanged;
+            this.configurationProvider.ConfigurationChanged += this.AlertsStateChanged;
             this.Load();
         }
 
@@ -69,6 +80,12 @@ namespace SyncTrayzor.Pages.BarAlerts
                 var vm = new PausedDevicesFromMeteringViewModel(pausedDeviceNames);
                 this.Items.Add(vm);
             }
+
+            var configuration = this.configurationProvider.Load();
+            if (!configuration.DisableHardwareRendering && !configuration.HideIntelXeWarningMessage && this.graphicsCardDetector.IsIntelXe)
+            {
+                this.Items.Add(this.intelXeGraphicsAlertViewModelFactory());
+            }
         }
 
         private void OpenConflictResolver()
@@ -80,6 +97,7 @@ namespace SyncTrayzor.Pages.BarAlerts
         protected override void OnClose()
         {
             this.alertsManager.AlertsStateChanged -= this.AlertsStateChanged;
+            this.configurationProvider.ConfigurationChanged -= this.AlertsStateChanged;
         }
     }
 }

+ 21 - 0
src/SyncTrayzor/Pages/BarAlerts/IntelXeGraphicsAlertView.xaml

@@ -0,0 +1,21 @@
+<UserControl x:Class="SyncTrayzor.Pages.BarAlerts.IntelXeGraphicsAlertView"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             xmlns:s="https://github.com/canton7/Stylet"
+             xmlns:l="clr-namespace:SyncTrayzor.Localization"
+             xmlns:local="clr-namespace:SyncTrayzor.Pages.BarAlerts"
+             mc:Ignorable="d" 
+             d:DesignHeight="450" d:DesignWidth="800"
+             d:DataContext="{d:DesignInstance local:IntelXeGraphicsAlertViewModel}">
+    <StackPanel>
+        <TextBlock TextWrapping="Wrap"
+                   Text="{l:Loc BarAlertsView_IntelXeGraphics_AlertText}"/>
+        <TextBlock>
+            <Hyperlink Command="{s:Action Dismiss}">
+                <TextBlock Text="{l:Loc BarAlertsView_IntelXeGraphics_DismissLink}"/>
+            </Hyperlink>
+        </TextBlock>
+    </StackPanel>
+</UserControl>

+ 22 - 0
src/SyncTrayzor/Pages/BarAlerts/IntelXeGraphicsAlertViewModel.cs

@@ -0,0 +1,22 @@
+using Stylet;
+using SyncTrayzor.Services.Config;
+
+namespace SyncTrayzor.Pages.BarAlerts
+{
+    public class IntelXeGraphicsAlertViewModel : Screen, IBarAlert
+    {
+        private readonly IConfigurationProvider configurationProvider;
+
+        public AlertSeverity Severity => AlertSeverity.Info;
+
+        public IntelXeGraphicsAlertViewModel(IConfigurationProvider configurationProvider)
+        {
+            this.configurationProvider = configurationProvider;
+        }
+
+        public void Dismiss()
+        {
+            this.configurationProvider.AtomicLoadAndSave(config => config.HideIntelXeWarningMessage = true);
+        }
+    }
+}

+ 4 - 3
src/SyncTrayzor/Pages/ViewerViewModel.cs

@@ -113,9 +113,10 @@ namespace SyncTrayzor.Pages
 
                 if (configuration.DisableHardwareRendering)
                 {
-                    settings.CefCommandLineArgs.Add("disable-gpu", "1");
-                    settings.CefCommandLineArgs.Add("disable-gpu-vsync", "1");
-                    settings.CefCommandLineArgs.Add("disable-application-cache", "1");
+                    settings.CefCommandLineArgs.Add("disable-gpu");
+                    settings.CefCommandLineArgs.Add("disable-gpu-vsync");
+                    settings.CefCommandLineArgs.Add("disable-gpu-compositing");
+                    settings.CefCommandLineArgs.Add("disable-application-cache");
                 }
 
                 Cef.Initialize(settings);

+ 18 - 0
src/SyncTrayzor/Properties/Resources.Designer.cs

@@ -205,6 +205,24 @@ namespace SyncTrayzor.Properties {
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized string similar to The area below may be blank when using Intel Xe graphics cards. Please disable hardware rendering under File -⁠&gt; Settings if you encounter this..
+        /// </summary>
+        public static string BarAlertsView_IntelXeGraphics_AlertText {
+            get {
+                return ResourceManager.GetString("BarAlertsView_IntelXeGraphics_AlertText", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to Dismiss.
+        /// </summary>
+        public static string BarAlertsView_IntelXeGraphics_DismissLink {
+            get {
+                return ResourceManager.GetString("BarAlertsView_IntelXeGraphics_DismissLink", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   Looks up a localized string similar to The following {0:p:device has|devices have} been paused because {0:p:it|they} connected using a metered network: {0:l:{}|, }..
         /// </summary>

+ 7 - 0
src/SyncTrayzor/Properties/Resources.resx

@@ -995,4 +995,11 @@ Please donate to my charity fundraising campaign.</value>
     <value>_Rescan All Folders</value>
     <comment>Menu option available when right-clicking the tray icon. Allows the user to re-scan all folders</comment>
   </data>
+  <data name="BarAlertsView_IntelXeGraphics_AlertText" xml:space="preserve">
+    <value>The area below may be blank when using Intel Xe graphics cards. Please disable hardware rendering under File&#160;-&#8288;&gt;&#160;Settings if you encounter this.</value>
+    <comment>Warning shown at the top of a page if Intel Xe graphics are detected</comment>
+  </data>
+  <data name="BarAlertsView_IntelXeGraphics_DismissLink" xml:space="preserve">
+    <value>Dismiss</value>
+  </data>
 </root>

+ 4 - 1
src/SyncTrayzor/Services/Config/Configuration.cs

@@ -61,6 +61,7 @@ namespace SyncTrayzor.Services.Config
         public string SyncthingCustomPath { get; set; }
         public string SyncthingCustomHomePath { get; set; }
         public bool DisableHardwareRendering { get; set; }
+        public bool HideIntelXeWarningMessage { get; set; }
         public bool EnableFailedTransferAlerts { get; set; }
         public bool EnableConflictFileMonitoring { get; set; }
 
@@ -100,6 +101,7 @@ namespace SyncTrayzor.Services.Config
             this.SyncthingCustomPath = null;
             this.SyncthingCustomHomePath = null;
             this.DisableHardwareRendering = false;
+            this.HideIntelXeWarningMessage = false;
             this.EnableFailedTransferAlerts = true;
             this.EnableConflictFileMonitoring = true;
             this.ConflictResolverDeletesToRecycleBin = true;
@@ -137,6 +139,7 @@ namespace SyncTrayzor.Services.Config
             this.SyncthingCustomPath = other.SyncthingCustomPath;
             this.SyncthingCustomHomePath = other.SyncthingCustomHomePath;
             this.DisableHardwareRendering = other.DisableHardwareRendering;
+            this.HideIntelXeWarningMessage = other.HideIntelXeWarningMessage;
             this.EnableFailedTransferAlerts = other.EnableFailedTransferAlerts;
             this.EnableConflictFileMonitoring = other.EnableConflictFileMonitoring;
             this.ConflictResolverDeletesToRecycleBin = other.ConflictResolverDeletesToRecycleBin;
@@ -160,7 +163,7 @@ namespace SyncTrayzor.Services.Config
                 $"ObfuscateDeviceIDs={this.ObfuscateDeviceIDs} UseComputerCulture={this.UseComputerCulture} SyncthingConsoleHeight={this.SyncthingConsoleHeight} WindowPlacement={this.WindowPlacement} " +
                 $"SyncthingWebBrowserZoomLevel={this.SyncthingWebBrowserZoomLevel} LastSeenInstallCount={this.LastSeenInstallCount} SyncthingCustomPath={this.SyncthingCustomPath} " +
                 $"SyncthingCustomHomePath={this.SyncthingCustomHomePath} ShowSynchronizedBalloonEvenIfNothingDownloaded={this.ShowSynchronizedBalloonEvenIfNothingDownloaded} " +
-                $"DisableHardwareRendering={this.DisableHardwareRendering} EnableFailedTransferAlerts={this.EnableFailedTransferAlerts} " +
+                $"DisableHardwareRendering={this.DisableHardwareRendering} HideIntelXeWarningMessage={this.HideIntelXeWarningMessage} EnableFailedTransferAlerts={this.EnableFailedTransferAlerts} " +
                 $"EnableConflictFileMonitoring={this.EnableConflictFileMonitoring} " +
                 $"ConflictResolverDeletesToRecycleBin={this.ConflictResolverDeletesToRecycleBin} PauseDevicesOnMeteredNetworks={this.PauseDevicesOnMeteredNetworks} " +
                 $"HaveDonated={this.HaveDonated} IconAnimationMode={this.IconAnimationMode} OpenFolderCommand={this.OpenFolderCommand} ShowFileInFolderCommand={this.ShowFileInFolderCommand}" +

+ 42 - 0
src/SyncTrayzor/Services/GraphicsCardDetector.cs

@@ -0,0 +1,42 @@
+using NLog;
+using System;
+using System.Management;
+
+namespace SyncTrayzor.Services
+{
+    public class GraphicsCardDetector
+    {
+        private static readonly Logger logger = LogManager.GetCurrentClassLogger();
+
+        private bool? _isIntelXe;
+        public bool IsIntelXe
+        {
+            get
+            {
+                if (this._isIntelXe == null)
+                    this._isIntelXe = GetIsIntelXe();
+                return this._isIntelXe.Value;
+            }
+        }
+
+        private static bool GetIsIntelXe()
+        { 
+            var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController");
+            foreach (ManagementObject obj in searcher.Get())
+            {
+                if (obj["CurrentBitsPerPixel"] != null && obj["CurrentHorizontalResolution"] != null)
+                {
+                    string name = obj["Name"]?.ToString();
+                    if (name.IndexOf("Intel", StringComparison.OrdinalIgnoreCase) >= 0 &&
+                        name.IndexOf(" Xe ", StringComparison.OrdinalIgnoreCase) >= 0)
+                    {
+                        logger.Info($"Graphics card: {name}");
+                        return true;
+                    }
+                }
+            }
+
+            return false;
+        }
+    }
+}

+ 7 - 0
src/SyncTrayzor/SyncTrayzor.csproj

@@ -101,6 +101,7 @@
     <Reference Include="System.Drawing" />
     <Reference Include="System.IO.Compression" />
     <Reference Include="System.IO.Compression.FileSystem" />
+    <Reference Include="System.Management" />
     <Reference Include="System.Net.Http" />
     <Reference Include="System.Net.Http.WebRequest" />
     <Reference Include="System.Numerics" />
@@ -140,6 +141,7 @@
     <Compile Include="Pages\BarAlerts\FailedTransfersAlertViewModel.cs" />
     <Compile Include="Pages\BarAlerts\IBarAlert.cs" />
     <Compile Include="Pages\BarAlerts\BarAlertsViewModel.cs" />
+    <Compile Include="Pages\BarAlerts\IntelXeGraphicsAlertViewModel.cs" />
     <Compile Include="Pages\BarAlerts\PausedDevicesFromMeteringView.xaml.cs">
       <DependentUpon>PausedDevicesFromMeteringView.xaml</DependentUpon>
     </Compile>
@@ -183,6 +185,7 @@
     <Compile Include="Services\FilesystemProvider.cs" />
     <Compile Include="Services\FileWatcher.cs" />
     <Compile Include="Services\FocusWindowProvider.cs" />
+    <Compile Include="Services\GraphicsCardDetector.cs" />
     <Compile Include="Services\Ipc\IpcCommsClient.cs" />
     <Compile Include="Services\Ipc\IpcCommsClientFactory.cs" />
     <Compile Include="Services\Ipc\IpcCommsServer.cs" />
@@ -392,6 +395,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Pages\BarAlerts\IntelXeGraphicsAlertView.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Pages\BarAlerts\PausedDevicesFromMeteringView.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>