Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for background service #382

Closed
wants to merge 11 commits into from
20 changes: 16 additions & 4 deletions Source/ChocolateyGui.Shared/Models/ChocolateySource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public class ChocolateySource : IEquatable<ChocolateySource>
[DataMember]
public string CertificatePassword { get; set; }

public bool ByPassProxy { get; set; }

public bool SelfService { get; set; }

public bool Equals(ChocolateySource other)
{
if (ReferenceEquals(null, other))
Expand All @@ -48,10 +52,16 @@ public bool Equals(ChocolateySource other)
return true;
}

return string.Equals(Id, other.Id) && string.Equals(Value, other.Value) && Disabled == other.Disabled
&& string.Equals(UserName, other.UserName) && string.Equals(Password, other.Password)
&& Priority == other.Priority && string.Equals(Certificate, other.Certificate)
&& string.Equals(CertificatePassword, other.CertificatePassword);
return string.Equals(Id, other.Id)
&& string.Equals(Value, other.Value)
&& Disabled == other.Disabled
&& string.Equals(UserName, other.UserName)
&& string.Equals(Password, other.Password)
&& Priority == other.Priority
&& string.Equals(Certificate, other.Certificate)
&& string.Equals(CertificatePassword, other.CertificatePassword)
&& ByPassProxy == other.ByPassProxy
&& SelfService == other.SelfService;
}

public override bool Equals(object obj)
Expand Down Expand Up @@ -86,6 +96,8 @@ public override int GetHashCode()
hashCode = (hashCode * 397) ^ Priority;
hashCode = (hashCode * 397) ^ (Certificate?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (CertificatePassword?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ ByPassProxy.GetHashCode();
hashCode = (hashCode * 397) ^ SelfService.GetHashCode();
return hashCode;
}
}
Expand Down
2 changes: 2 additions & 0 deletions Source/ChocolateyGui.Subprocess/ChocolateyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ public async Task AddSource(ChocolateySource source)
config.SourceCommand.Certificate = source.Certificate;
config.SourceCommand.CertificatePassword = source.CertificatePassword;
config.SourceCommand.Priority = source.Priority;

// TODO: Put ByPassProxy and SelfService properties here
});

await choco.RunAsync();
Expand Down
15 changes: 15 additions & 0 deletions Source/ChocolateyGui/Base/ConnectionClosedException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// <copyright file="ConnectionClosedException.cs" company="Chocolatey">
// Copyright 2014 - Present Rob Reynolds, the maintainers of Chocolatey, and RealDimensions Software, LLC
// </copyright>

using System;

namespace ChocolateyGui.Base
{
/// <summary>
/// Used to represent that a connection closed peacefully while performing operation. Likely means application is closing.
/// </summary>
public class ConnectionClosedException : Exception
{
}
}
26 changes: 22 additions & 4 deletions Source/ChocolateyGui/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Autofac;
using Caliburn.Micro;
using CefSharp;
using ChocolateyGui.Properties;
using ChocolateyGui.Services;
using ChocolateyGui.Startup;
using ChocolateyGui.Utilities;
using ChocolateyGui.ViewModels;
Expand Down Expand Up @@ -86,10 +88,26 @@ protected override void Configure()
Internationalization.Initialize();
}

protected override void OnStartup(object sender, StartupEventArgs e)
protected override async void OnStartup(object sender, StartupEventArgs e)
{
App.SplashScreen.Close(TimeSpan.FromMilliseconds(300));
DisplayRootViewFor<ShellViewModel>();
try
{
var packageSerice = Container.Resolve<IChocolateyPackageService>();
var features = await packageSerice.GetFeatures();

var backgroundFeature = features.FirstOrDefault(feature => string.Equals(feature.Name, "useBackgroundService", StringComparison.OrdinalIgnoreCase));
var elevationProvider = Elevation.Instance;
elevationProvider.IsBackgroundRunning = backgroundFeature?.Enabled ?? false;

App.SplashScreen.Close(TimeSpan.FromMilliseconds(300));
DisplayRootViewFor<ShellViewModel>();
}
catch (Exception ex)
{
MessageBox.Show($"Failed to start application.\n{ex.Message}\n\nMore details available in application logs.");
Logger.Fatal(ex, "Failed to start application.");
await OnExitAsync();
}
}

protected override object GetInstance(Type service, string key)
Expand Down
3 changes: 2 additions & 1 deletion Source/ChocolateyGui/ChocolateyGui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="Base\ConnectionClosedException.cs" />
<Compile Include="Controls\InternetImage.xaml.cs">
<DependentUpon>InternetImage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -233,7 +234,7 @@
<Compile Include="Providers\ChocolateyConfigurationProvider.cs" />
<Compile Include="Providers\ChocolateyCustomSchemeProvider.cs" />
<Compile Include="Providers\ChocoRequestHandler.cs" />
<Compile Include="Providers\ElevationStatusProvider.cs" />
<Compile Include="Elevation.cs" />
<Compile Include="Providers\IChocolateyConfigurationProvider.cs" />
<Compile Include="Providers\IPlatformProvider.cs" />
<Compile Include="Providers\IVersionNumberProvider.cs" />
Expand Down
62 changes: 62 additions & 0 deletions Source/ChocolateyGui/Elevation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Elevation.cs" company="Chocolatey">
// Copyright 2014 - Present Rob Reynolds, the maintainers of Chocolatey, and RealDimensions Software, LLC
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using Autofac;
using Caliburn.Micro;
using ChocolateyGui.Utilities;
using ChocolateyGui.Utilities.Extensions;

namespace ChocolateyGui
{
public class Elevation : PropertyChangedBase
{
private bool _isElevated = Hacks.IsElevated;
private bool _isBackgroundRunning = false;

public static Elevation Instance
{
get { return Bootstrapper.Container.Resolve<Elevation>(); }
}

public bool IsElevated
{
get
{
return _isElevated;
}

set
{
this.SetPropertyValue(ref _isElevated, value);
NotifyOfPropertyChange(nameof(CanDoCentralActions));
}
}

public bool IsBackgroundRunning
{
get
{
return _isBackgroundRunning;
}

set
{
this.SetPropertyValue(ref _isBackgroundRunning, value);
NotifyOfPropertyChange(nameof(CanDoCentralActions));
}
}

public bool CanDoCentralActions
{
get { return _isBackgroundRunning || _isElevated; }
}

public bool CanDoTertiaryActions
{
get { return _isElevated; }
}
}
}
36 changes: 36 additions & 0 deletions Source/ChocolateyGui/Properties/Resources.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 Source/ChocolateyGui/Properties/Resources.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@
<data name="PackageView_ButtonInstall" xml:space="preserve">
<value>Installieren</value>
</data>
<data name="PackageView_ButtonPin" xml:space="preserve">
<value>Pin</value>
</data>
<data name="PackageView_ButtonReinstall" xml:space="preserve">
<value>Erneut Installieren</value>
</data>
Expand Down Expand Up @@ -300,6 +303,9 @@
<data name="SettingsView_Sources" xml:space="preserve">
<value>Quellen</value>
</data>
<data name="SettingsView_SourcesByPassProxy" xml:space="preserve">
<value />
</data>
<data name="SettingsView_SourcesCertificate" xml:space="preserve">
<value>Zertifikat</value>
</data>
Expand All @@ -321,6 +327,9 @@
<data name="SettingsView_SourcesPriority" xml:space="preserve">
<value>Priorität</value>
</data>
<data name="SettingsView_SourcesSelfService" xml:space="preserve">
<value />
</data>
<data name="SettingsView_SourcesSource" xml:space="preserve">
<value>Quelle</value>
</data>
Expand Down
12 changes: 12 additions & 0 deletions Source/ChocolateyGui/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,16 @@ NOTE: Probably only necessary to change in RTL languages.</comment>
<data name="VersionNumberProvider_VersionFormat" xml:space="preserve">
<value>Version: {0}</value>
</data>
<data name="SettingsView_SourcesByPassProxy" xml:space="preserve">
<value>ByPass Proxy</value>
</data>
<data name="SettingsView_SourcesSelfService" xml:space="preserve">
<value>Self Service</value>
</data>
<data name="SettingsView_SourcesIsByPassProxy" xml:space="preserve">
<value>Is Proxy ByPassed</value>
</data>
<data name="SettingsView_SourcesIsSelfService" xml:space="preserve">
<value>Is Self Service</value>
</data>
</root>
6 changes: 6 additions & 0 deletions Source/ChocolateyGui/Properties/Resources.sv.resx
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@ NOTE: Probably only necessary to change in RTL languages.</comment>
<data name="SettingsView_Sources" xml:space="preserve">
<value>Källor</value>
</data>
<data name="SettingsView_SourcesByPassProxy" xml:space="preserve">
<value />
</data>
<data name="SettingsView_SourcesCertificate" xml:space="preserve">
<value>Certifikat</value>
</data>
Expand All @@ -543,6 +546,9 @@ NOTE: Probably only necessary to change in RTL languages.</comment>
<data name="SettingsView_SourcesPriority" xml:space="preserve">
<value>Prioritet</value>
</data>
<data name="SettingsView_SourcesSelfService" xml:space="preserve">
<value />
</data>
<data name="SettingsView_SourcesSource" xml:space="preserve">
<value>Källa</value>
</data>
Expand Down
Loading