Skip to content

Commit

Permalink
Show a bar alert when Xe graphics are detected
Browse files Browse the repository at this point in the history
Relates to: #606
  • Loading branch information
canton7 committed Mar 3, 2021
1 parent 219e336 commit 57822b6
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 2 deletions.
20 changes: 19 additions & 1 deletion src/SyncTrayzor/Pages/BarAlerts/BarAlertsViewModel.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,23 +13,33 @@ public class BarAlertsViewModel : Conductor<IBarAlert>.Collection.AllActive
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();
}

Expand Down Expand Up @@ -69,6 +80,12 @@ private void Load()
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()
Expand All @@ -80,6 +97,7 @@ private void OpenConflictResolver()
protected override void OnClose()
{
this.alertsManager.AlertsStateChanged -= this.AlertsStateChanged;
this.configurationProvider.ConfigurationChanged -= this.AlertsStateChanged;
}
}
}
21 changes: 21 additions & 0 deletions src/SyncTrayzor/Pages/BarAlerts/IntelXeGraphicsAlertView.xaml
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions src/SyncTrayzor/Pages/BarAlerts/IntelXeGraphicsAlertViewModel.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
18 changes: 18 additions & 0 deletions src/SyncTrayzor/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/SyncTrayzor/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
5 changes: 4 additions & 1 deletion src/SyncTrayzor/Services/Config/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public string LatestNotifiedVersionRaw
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; }

Expand Down Expand Up @@ -100,6 +101,7 @@ public Configuration()
this.SyncthingCustomPath = null;
this.SyncthingCustomHomePath = null;
this.DisableHardwareRendering = false;
this.HideIntelXeWarningMessage = false;
this.EnableFailedTransferAlerts = true;
this.EnableConflictFileMonitoring = true;
this.ConflictResolverDeletesToRecycleBin = true;
Expand Down Expand Up @@ -137,6 +139,7 @@ public Configuration(Configuration other)
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;
Expand All @@ -160,7 +163,7 @@ public override string ToString()
$"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}" +
Expand Down
42 changes: 42 additions & 0 deletions src/SyncTrayzor/Services/GraphicsCardDetector.cs
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions src/SyncTrayzor/SyncTrayzor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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" />
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 57822b6

Please sign in to comment.