Skip to content

Commit

Permalink
Added warning banners for conflicting software
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoszCichecki committed Aug 21, 2024
1 parent c1b4b37 commit 5ff8a03
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ public class SoftwareDisablerException(string message, Exception innerException)

public abstract class AbstractSoftwareDisabler
{
public class AbstractSoftwareDisablerEventArgs : EventArgs
{
public SoftwareStatus Status { get; init; }
}

protected abstract IEnumerable<string> ScheduledTasksPaths { get; }
protected abstract IEnumerable<string> ServiceNames { get; }
protected abstract IEnumerable<string> ProcessNames { get; }

public event EventHandler<AbstractSoftwareDisablerEventArgs>? OnRefreshed;

public Task<SoftwareStatus> GetStatusAsync() => Task.Run(() =>
{
bool isEnabled;
Expand Down Expand Up @@ -50,23 +57,30 @@ public Task<SoftwareStatus> GetStatusAsync() => Task.Run(() =>
if (Log.Instance.IsTraceEnabled)
Log.Instance.Trace($"Status: {isEnabled},{isInstalled} [type={GetType().Name}]");

SoftwareStatus status;

if (isEnabled)
return SoftwareStatus.Enabled;
status = SoftwareStatus.Enabled;
else if (!isInstalled)
status = SoftwareStatus.NotFound;
else
status = SoftwareStatus.Disabled;

if (!isInstalled)
return SoftwareStatus.NotFound;
OnRefreshed?.Invoke(this, new() { Status = status });

return SoftwareStatus.Disabled;
return status;
});

public virtual Task EnableAsync() => Task.Run(() =>
public virtual Task EnableAsync() => Task.Run(async () =>
{
if (Log.Instance.IsTraceEnabled)
Log.Instance.Trace($"Enabling... [type={GetType().Name}]");

SetScheduledTasksEnabled(true);
SetServicesEnabled(true);

_ = await GetStatusAsync().ConfigureAwait(false);

if (Log.Instance.IsTraceEnabled)
Log.Instance.Trace($"Enabled [type={GetType().Name}]");
});
Expand All @@ -80,6 +94,8 @@ public virtual Task DisableAsync() => Task.Run(async () =>
SetServicesEnabled(false);
await KillProcessesAsync().ConfigureAwait(false);

_ = await GetStatusAsync().ConfigureAwait(false);

if (Log.Instance.IsTraceEnabled)
Log.Instance.Trace($"Disabled [type={GetType().Name}]");
});
Expand Down Expand Up @@ -252,7 +268,7 @@ protected virtual async Task KillProcessesAsync()
{
if (process.ProcessName.StartsWith(processName, StringComparison.InvariantCultureIgnoreCase))
{
process.Kill();
process.Kill(true);
await process.WaitForExitAsync().ConfigureAwait(false);
}
}
Expand Down
3 changes: 2 additions & 1 deletion LenovoLegionToolkit.WPF/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ private async void Application_Startup(object sender, StartupEventArgs e)
var mainWindow = new MainWindow
{
WindowStartupLocation = WindowStartupLocation.CenterScreen,
TrayTooltipEnabled = !flags.DisableTrayTooltip
TrayTooltipEnabled = !flags.DisableTrayTooltip,
DisableConflictingSoftwareWarning = flags.DisableConflictingSoftwareWarning
};
MainWindow = mainWindow;

Expand Down
5 changes: 4 additions & 1 deletion LenovoLegionToolkit.WPF/Flags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Flags
public string? ProxyPassword { get; }
public bool ProxyAllowAllCerts { get; }
public bool DisableUpdateChecker { get; }
public bool DisableConflictingSoftwareWarning { get; }

public Flags(IEnumerable<string> startupArgs)
{
Expand All @@ -45,6 +46,7 @@ public Flags(IEnumerable<string> startupArgs)
ProxyPassword = StringValue(args, "--proxy-password");
ProxyAllowAllCerts = BoolValue(args, "--proxy-allow-all-certs");
DisableUpdateChecker = BoolValue(args, "--disable-update-checker");
DisableConflictingSoftwareWarning = BoolValue(args, "--disable-conflicting-software-warning");
}

private static string[] LoadExternalArgs()
Expand Down Expand Up @@ -83,5 +85,6 @@ public override string ToString() =>
$" {nameof(ProxyUsername)}: {ProxyUsername}," +
$" {nameof(ProxyPassword)}: {ProxyPassword}," +
$" {nameof(ProxyAllowAllCerts)}: {ProxyAllowAllCerts}," +
$" {nameof(DisableUpdateChecker)}: {DisableUpdateChecker}";
$" {nameof(DisableUpdateChecker)}: {DisableUpdateChecker}, " +
$" {nameof(DisableConflictingSoftwareWarning)}: {DisableConflictingSoftwareWarning}";
}
27 changes: 27 additions & 0 deletions LenovoLegionToolkit.WPF/Resources/Resource.Designer.cs

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

9 changes: 9 additions & 0 deletions LenovoLegionToolkit.WPF/Resources/Resource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2179,4 +2179,13 @@ Supported formats are: {1}.</value>
<data name="SettingsPage_Temperature_Message" xml:space="preserve">
<value>Select units for temperature sensors.</value>
</data>
<data name="MainWindows_FnKeysRunning" xml:space="preserve">
<value>Lenovo Hotkeys is running in the background.</value>
</data>
<data name="MainWindow_LegionZoneRunning" xml:space="preserve">
<value>Legion Zone is running in the background.</value>
</data>
<data name="MainWindows_VantageRunning" xml:space="preserve">
<value>Lenovo Vantage and/or ImController is running in the background.</value>
</data>
</root>
61 changes: 59 additions & 2 deletions LenovoLegionToolkit.WPF/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<wpfui:TitleBar Grid.Row="0" />
Expand Down Expand Up @@ -175,9 +178,63 @@
</Grid>

<Border
x:Name="_updateIndicator"
x:Name="_vantageIndicator"
Grid.Row="2"
Padding="8,4,8,4"
Padding="8,4,8,6"
Background="Orange"
Visibility="Collapsed">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<wpfui:SymbolIcon
Margin="0,0,4,0"
Foreground="Black"
Symbol="Warning24" />
<TextBlock
Focusable="True"
Foreground="Black"
Text="Lenovo Vantage and/or ImController is running in the background." />
</StackPanel>
</Border>

<Border
x:Name="_legionZoneIndicator"
Grid.Row="3"
Padding="8,4,8,6"
Background="Orange"
Visibility="Collapsed">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<wpfui:SymbolIcon
Margin="0,0,4,0"
Foreground="Black"
Symbol="Warning24" />
<TextBlock
Focusable="True"
Foreground="Black"
Text="Legion Zone is running in the background." />
</StackPanel>
</Border>

<Border
x:Name="_fnKeysIndicator"
Grid.Row="4"
Padding="8,4,8,6"
Background="Orange"
Visibility="Collapsed">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<wpfui:SymbolIcon
Margin="0,0,4,0"
Foreground="Black"
Symbol="Warning24" />
<TextBlock
Focusable="True"
Foreground="Black"
Text="Lenovo Hotkeys is running in the background." />
</StackPanel>
</Border>

<Border
x:Name="_updateIndicator"
Grid.Row="5"
Padding="8,4,8,6"
Background="{DynamicResource SystemFillColorSuccessBrush}"
Cursor="Hand"
MouseLeftButtonDown="UpdateIndicator_Click"
Expand Down
37 changes: 35 additions & 2 deletions LenovoLegionToolkit.WPF/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using LenovoLegionToolkit.Lib.Messaging;
using LenovoLegionToolkit.Lib.Messaging.Messages;
using LenovoLegionToolkit.Lib.Settings;
using LenovoLegionToolkit.Lib.SoftwareDisabler;
using LenovoLegionToolkit.Lib.Utils;
using LenovoLegionToolkit.WPF.Extensions;
using LenovoLegionToolkit.WPF.Pages;
Expand All @@ -29,13 +30,16 @@ namespace LenovoLegionToolkit.WPF.Windows;
public partial class MainWindow
{
private readonly ApplicationSettings _applicationSettings = IoCContainer.Resolve<ApplicationSettings>();
private readonly UpdateChecker _updateChecker = IoCContainer.Resolve<UpdateChecker>();
private readonly SpecialKeyListener _specialKeyListener = IoCContainer.Resolve<SpecialKeyListener>();
private readonly VantageDisabler _vantageDisabler = IoCContainer.Resolve<VantageDisabler>();
private readonly LegionZoneDisabler _legionZoneDisabler = IoCContainer.Resolve<LegionZoneDisabler>();
private readonly FnKeysDisabler _fnKeysDisabler = IoCContainer.Resolve<FnKeysDisabler>();
private readonly UpdateChecker _updateChecker = IoCContainer.Resolve<UpdateChecker>();

private TrayHelper? _trayHelper;

public bool TrayTooltipEnabled { get; init; } = true;

public bool DisableConflictingSoftwareWarning { get; set; }
public bool SuppressClosingEventHandler { get; set; }

public Snackbar Snackbar => _snackbar;
Expand Down Expand Up @@ -88,6 +92,7 @@ private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
_contentGrid.Visibility = Visibility.Visible;

LoadDeviceInfo();
UpdateIndicators();
CheckForUpdates();

InputBindings.Add(new KeyBinding(new ActionCommand(_navigationStore.NavigateToNext), Key.Tab, ModifierKeys.Control));
Expand Down Expand Up @@ -197,6 +202,34 @@ private void LoadDeviceInfo()
}, TaskScheduler.FromCurrentSynchronizationContext());
}

private void UpdateIndicators()
{
if (DisableConflictingSoftwareWarning)
return;

_vantageDisabler.OnRefreshed += (_, e) => Dispatcher.Invoke(() =>
{
_vantageIndicator.Visibility = e.Status == SoftwareStatus.Enabled ? Visibility.Visible : Visibility.Collapsed;
});

_legionZoneDisabler.OnRefreshed += (_, e) => Dispatcher.Invoke(() =>
{
_legionZoneIndicator.Visibility = e.Status == SoftwareStatus.Enabled ? Visibility.Visible : Visibility.Collapsed;
});

_fnKeysDisabler.OnRefreshed += (_, e) => Dispatcher.Invoke(() =>
{
_fnKeysIndicator.Visibility = e.Status == SoftwareStatus.Enabled ? Visibility.Visible : Visibility.Collapsed;
});

Task.Run(async () =>
{
_ = await _vantageDisabler.GetStatusAsync().ConfigureAwait(false);
_ = await _legionZoneDisabler.GetStatusAsync().ConfigureAwait(false);
_ = await _fnKeysDisabler.GetStatusAsync().ConfigureAwait(false);
});
}

private void CheckForUpdates()
{
Task.Run(_updateChecker.CheckAsync)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ Some, less frequently needed, features or options can be enabled by using additi
* `--proxy-password=some_password` - if applicable, specifies proxy server password to use
* `--proxy-allow-all-certs` - if needed relaxes criteria needed to establish HTTPS/SSL connections via proxy server
* `--disable-update-checker` - disable update checks in LLT, in case you want to rely on winget, scoop etc.
* `--disable-conflicting-software-warning` - disables warning banners when conflicting software is running

If you decide to use the arguments with `args.txt` file:
1. Go to `%LOCALAPPDATA%\LenovoLegionToolkit`
Expand Down

0 comments on commit 5ff8a03

Please sign in to comment.