Skip to content

Commit

Permalink
(chocolateyGH-741 chocolateyGH-749) Add missing package parameters
Browse files Browse the repository at this point in the history
I also switched to an helper.ps1 file for the package parameters to not
go over the 100 lines guideline.
Also the Package Parameter for UseDelayedSearch will now contain the
correct value.
  • Loading branch information
mkevenaar committed Apr 5, 2020
1 parent 99c4425 commit 6bf3797
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 49 deletions.
5 changes: 5 additions & 0 deletions nuspec/chocolatey/ChocolateyGUI.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ Chocolatey GUI is a delicious GUI on top of the Chocolatey command line tool.
- `/DefaultToTileViewForLocalSource` - Enables/disables whether or not Chocolatey GUI defauls to tile instead of list view for the local source view
- `/DefaultToTileViewForRemoteSource` - Enables/disables whether or not Chocolatey GUI defauls to tile instead of list view for all remote source views
- `/UseDelayedSearch` - Enables/disables whether or not Chocolatey GUI uses a live search, which returns results after a short delay without clicking the search button
- `/PreventPreload` - Prevents preloading results with a blank search when opening the remote source view.
- `/ExcludeInstalledPackages` - Enables/disables whether or not Chocolatey GUI shows packages that are already installed when viewing sources
- `/ShowAggregatedSourceView` - Enables/disables whether or not Chocolatey GUI shows an additional source combining all sources into one location
- `/ShowAdditionalPackageInformation` - Show additional package information on Local and Remote views.
- `/AllowNonAdminAccessToSettings` - Controls whether or not a non-administrator user can access the Settings Screen. NOTE: This feature will only work when using the licensed extension for Chocolatey and Chocolatey GUI.
- `/UseKeyboardBindings` - Allows keyboard bindings to be used to interact with different areas of the Chocolatey GUI User Interface.
- `/HidePackageDownloadCount` - Allows keyboard bindings to be used to interact with different areas of the Chocolatey GUI User Interface.
- `/OutdatedPackagesCacheDurationInMinutes` - The length of time, in minutes, which Chocolatey GUI will wait before invalidating the cached result of outdated packages for the machine

As an example, the following installation command could be used to enable `ShowConsoleOutput` to ensure `UseDelayedSearch` is disabled, and set the output cache to 120 minutes:
Expand Down
54 changes: 5 additions & 49 deletions nuspec/chocolatey/chocolateyInstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ $ErrorActionPreference = 'Stop';
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$fileLocation = Join-Path $toolsDir 'ChocolateyGUI.msi'

if(!$PSScriptRoot){ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent }
. "$PSScriptRoot\helper.ps1"

$packageArgs = @{
packageName = $env:ChocolateyPackageName
softwareName = 'Chocolatey GUI'
Expand All @@ -22,52 +25,5 @@ if ($installDirectory) {
Install-BinFile -Name "chocolateyguicli" -Path "$installDirectory\ChocolateyGuiCli.exe"
}

$pp = Get-PackageParameters

function Set-FeatureState {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string] $FeatureName,

[Parameter(Mandatory=$true)]
[bool] $EnableFeature
)

if ($EnableFeature) {
Write-Output "Enabling $FeatureName..."
Start-ChocolateyProcessAsAdmin -Statements "feature enable --name=$FeatureName" -ExeToRun "chocolateyguicli"
} else {
Write-Output "Disabling $FeatureName..."
Start-ChocolateyProcessAsAdmin -Statements "feature disable --name=$FeatureName" -ExeToRun "chocolateyguicli"
}
}

# Features
if($pp.ContainsKey("ShowConsoleOutput")) {
Set-FeatureState "ShowConsoleOutput" ($pp.ShowConsoleOutput -eq $true)
}

if($pp.ContainsKey("DefaultToTileViewForLocalSource")) {
Set-FeatureState "DefaultToTileViewForLocalSource" ($pp.DefaultToTileViewForLocalSource -eq $true)
}

if($pp.ContainsKey("DefaultToTileViewForRemoteSource")) {
Set-FeatureState "DefaultToTileViewForRemoteSource" ($pp.DefaultToTileViewForRemoteSource -eq $true)
}

if($pp.ContainsKey("UseDelayedSearch")) {
Set-FeatureState "UseDelayedSearch" ($pp.DefaultToTileViewForRemoteSource -eq $true)
}

if($pp.ContainsKey("ExcludeInstalledPackages")) {
Set-FeatureState "ExcludeInstalledPackages" ($pp.ExcludeInstalledPackages -eq $true)
}

if($pp.ContainsKey("ShowAggregatedSourceView")) {
Set-FeatureState "ShowAggregatedSourceView" ($pp.ShowAggregatedSourceView -eq $true)
}

if($pp.ContainsKey("OutdatedPackagesCacheDurationInMinutes")) {
Start-ChocolateyProcessAsAdmin -Statements "config set --name=OutdatedPackagesCacheDurationInMinutes --value=$($pp.OutdatedPackagesCacheDurationInMinutes)" -ExeToRun "chocolateyguicli"
}
# Process package parameters
Set-UserSettings
75 changes: 75 additions & 0 deletions nuspec/chocolatey/helper.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
function Set-FeatureState {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string] $FeatureName,

[Parameter(Mandatory=$true)]
[bool] $EnableFeature
)

if ($EnableFeature) {
Write-Output "Enabling $FeatureName..."
Start-ChocolateyProcessAsAdmin -Statements "feature enable --name=$FeatureName" -ExeToRun "chocolateyguicli"
} else {
Write-Output "Disabling $FeatureName..."
Start-ChocolateyProcessAsAdmin -Statements "feature disable --name=$FeatureName" -ExeToRun "chocolateyguicli"
}
}

function Set-UserSettings {
[CmdletBinding()]
param(
[hashtable]$pp = ( Get-PackageParameters )

)
# Features
if($pp.ContainsKey("ShowConsoleOutput")) {
Set-FeatureState "ShowConsoleOutput" ($pp.ShowConsoleOutput -eq $true)
}

if($pp.ContainsKey("DefaultToTileViewForLocalSource")) {
Set-FeatureState "DefaultToTileViewForLocalSource" ($pp.DefaultToTileViewForLocalSource -eq $true)
}

if($pp.ContainsKey("DefaultToTileViewForRemoteSource")) {
Set-FeatureState "DefaultToTileViewForRemoteSource" ($pp.DefaultToTileViewForRemoteSource -eq $true)
}

if($pp.ContainsKey("UseDelayedSearch")) {
Set-FeatureState "UseDelayedSearch" ($pp.UseDelayedSearch -eq $true)
}

if($pp.ContainsKey("PreventPreload")) {
Set-FeatureState "PreventPreload" ($pp.PreventPreload -eq $true)
}

if($pp.ContainsKey("ExcludeInstalledPackages")) {
Set-FeatureState "ExcludeInstalledPackages" ($pp.ExcludeInstalledPackages -eq $true)
}

if($pp.ContainsKey("ShowAggregatedSourceView")) {
Set-FeatureState "ShowAggregatedSourceView" ($pp.ShowAggregatedSourceView -eq $true)
}

if($pp.ContainsKey("ShowAdditionalPackageInformation")) {
Set-FeatureState "ShowAdditionalPackageInformation" ($pp.ShowAdditionalPackageInformation -eq $true)
}

if($pp.ContainsKey("AllowNonAdminAccessToSettings")) {
Set-FeatureState "AllowNonAdminAccessToSettings" ($pp.AllowNonAdminAccessToSettings -eq $true)
}

if($pp.ContainsKey("UseKeyboardBindings")) {
Set-FeatureState "UseKeyboardBindings" ($pp.UseKeyboardBindings -eq $true)
}

if($pp.ContainsKey("HidePackageDownloadCount")) {
Set-FeatureState "HidePackageDownloadCount" ($pp.HidePackageDownloadCount -eq $true)
}

# config
if($pp.ContainsKey("OutdatedPackagesCacheDurationInMinutes")) {
Start-ChocolateyProcessAsAdmin -Statements "config set --name=OutdatedPackagesCacheDurationInMinutes --value=$($pp.OutdatedPackagesCacheDurationInMinutes)" -ExeToRun "chocolateyguicli"
}
}

0 comments on commit 6bf3797

Please sign in to comment.