Add headless macOS CLI workflow
This commit is contained in:
134
Core.psm1
134
Core.psm1
@@ -14,6 +14,14 @@ function Get-ModuleVersion
|
||||
'3.9.6'
|
||||
}
|
||||
|
||||
function Invoke-AppDoEvents
|
||||
{
|
||||
if("System.Windows.Forms.Application" -as [type])
|
||||
{
|
||||
[System.Windows.Forms.Application]::DoEvents()
|
||||
}
|
||||
}
|
||||
|
||||
function Initialize-Window
|
||||
{
|
||||
param($xamlFile)
|
||||
@@ -67,7 +75,27 @@ function Start-CoreApp
|
||||
$global:AppRootFolder = $PSScriptRoot
|
||||
|
||||
# Load all modules in the Modules folder
|
||||
$global:modulesPath = [IO.Path]::GetDirectoryName($PSCommandPath) + "\Extensions"
|
||||
$global:modulesPath = Join-Path ([IO.Path]::GetDirectoryName($PSCommandPath)) "Extensions"
|
||||
|
||||
if($global:hideUI -eq $true)
|
||||
{
|
||||
$global:skipModules = @(
|
||||
"Compare.psm1",
|
||||
"Copy.psm1",
|
||||
"Documentation.psm1",
|
||||
"DocumentationCustom.psm1",
|
||||
"DocumentationHTML.psm1",
|
||||
"DocumentationMD.psm1",
|
||||
"DocumentationWord.psm1",
|
||||
"IntuneAssignments.psm1",
|
||||
"IntuneFilterUsage.psm1",
|
||||
"IntuneTools.psm1"
|
||||
)
|
||||
}
|
||||
else
|
||||
{
|
||||
$global:skipModules = @()
|
||||
}
|
||||
|
||||
Add-DefaultSettings
|
||||
|
||||
@@ -122,7 +150,7 @@ function Start-CoreApp
|
||||
$global:MainAppStarted = $false
|
||||
|
||||
Set-SplashWindowText "Initialize views"
|
||||
[System.Windows.Forms.Application]::DoEvents()
|
||||
Invoke-AppDoEvents
|
||||
|
||||
Invoke-ModuleFunction "Invoke-InitializeModule"
|
||||
|
||||
@@ -176,8 +204,6 @@ function Start-CoreApp
|
||||
Write-Log "SilentBatchFile $($global:SilentBatchFile) not found" 3
|
||||
return
|
||||
}
|
||||
Invoke-ModuleFunction "Invoke-ShowMainWindow"
|
||||
|
||||
Invoke-ModuleFunction "Invoke-InitSilentBatchJob"
|
||||
|
||||
Start-RunSilentBatchJob
|
||||
@@ -199,13 +225,13 @@ function Start-RunSilentBatchJob
|
||||
|
||||
function Import-AllModules
|
||||
{
|
||||
foreach($file in (Get-Item -path "$($global:modulesPath)\*.psm1"))
|
||||
foreach($file in (Get-Item -path (Join-Path $global:modulesPath "*.psm1")))
|
||||
{
|
||||
$fileName = [IO.Path]::GetFileName($file)
|
||||
if($skipModules -contains $fileName) { Write-Warning "Module $fileName excluded"; continue; }
|
||||
|
||||
Set-SplashWindowText "Import module $fileName"
|
||||
[System.Windows.Forms.Application]::DoEvents()
|
||||
Invoke-AppDoEvents
|
||||
|
||||
$module = Import-Module $file -PassThru -Force -Global -ErrorAction SilentlyContinue
|
||||
if($module)
|
||||
@@ -422,7 +448,14 @@ function Set-XamlProperty
|
||||
{
|
||||
if($obj)
|
||||
{
|
||||
$obj."$propertyName" = $value
|
||||
if(-not ($obj.PSObject.Properties.Name -contains $propertyName))
|
||||
{
|
||||
$obj | Add-Member -MemberType NoteProperty -Name $propertyName -Value $value -Force
|
||||
}
|
||||
else
|
||||
{
|
||||
$obj."$propertyName" = $value
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -571,15 +604,15 @@ function Set-BatchProperties
|
||||
|
||||
try
|
||||
{
|
||||
if($obj -is [System.Windows.Controls.CheckBox])
|
||||
if($obj.PSObject.Properties.Name -contains "IsChecked")
|
||||
{
|
||||
$obj.IsChecked = $prop.Value -eq $true
|
||||
}
|
||||
elseif($obj -is [System.Windows.Controls.TextBox])
|
||||
elseif($obj.PSObject.Properties.Name -contains "Text")
|
||||
{
|
||||
$obj.Text = $prop.Value
|
||||
}
|
||||
elseif($obj -is [System.Windows.Controls.ComboBox])
|
||||
elseif($obj.PSObject.Properties.Name -contains "SelectedValue")
|
||||
{
|
||||
$obj.SelectedValue = $prop.Value
|
||||
}
|
||||
@@ -601,6 +634,60 @@ function Set-BatchProperties
|
||||
}
|
||||
#endregion
|
||||
|
||||
function New-HeadlessControl
|
||||
{
|
||||
param(
|
||||
[string]$Name,
|
||||
[ValidateSet("TextBox","CheckBox","ComboBox","Label","DataGrid")]
|
||||
[string]$Type = "TextBox"
|
||||
)
|
||||
|
||||
$control = [PSCustomObject]@{
|
||||
Name = $Name
|
||||
Focusable = $true
|
||||
Visibility = "Visible"
|
||||
IsEnabled = $true
|
||||
Text = ""
|
||||
IsChecked = $false
|
||||
SelectedValue = $null
|
||||
ItemsSource = @()
|
||||
Content = ""
|
||||
}
|
||||
|
||||
if($Type -eq "DataGrid")
|
||||
{
|
||||
$control.Focusable = $false
|
||||
}
|
||||
|
||||
$control
|
||||
}
|
||||
|
||||
function New-HeadlessForm
|
||||
{
|
||||
param($Controls)
|
||||
|
||||
$form = [PSCustomObject]@{
|
||||
Controls = @{}
|
||||
}
|
||||
|
||||
foreach($control in $Controls)
|
||||
{
|
||||
$form.Controls[$control.Name] = $control
|
||||
}
|
||||
|
||||
$form | Add-Member -MemberType ScriptMethod -Name FindName -Value {
|
||||
param($name)
|
||||
$this.Controls[$name]
|
||||
}
|
||||
|
||||
$form | Add-Member -MemberType ScriptMethod -Name RegisterName -Value {
|
||||
param($name, $control)
|
||||
$this.Controls[$name] = $control
|
||||
}
|
||||
|
||||
$form
|
||||
}
|
||||
|
||||
#region Dialogs
|
||||
|
||||
function Show-AboutDialog
|
||||
@@ -1204,6 +1291,21 @@ function Expand-FileName
|
||||
|
||||
#endregion
|
||||
|
||||
function Get-CloudApiDataFolder
|
||||
{
|
||||
if($env:LOCALAPPDATA)
|
||||
{
|
||||
return (Join-Path $env:LOCALAPPDATA "CloudAPIPowerShellManagement")
|
||||
}
|
||||
|
||||
if(Test-IsWindowsPlatform)
|
||||
{
|
||||
return (Join-Path $env:USERPROFILE "AppData/Local/CloudAPIPowerShellManagement")
|
||||
}
|
||||
|
||||
return (Join-Path $HOME "Library/Application Support/CloudAPIPowerShellManagement")
|
||||
}
|
||||
|
||||
#region Save/Read Settings functions
|
||||
########################################################################
|
||||
#
|
||||
@@ -1231,7 +1333,7 @@ function Initialize-JsonSettings
|
||||
{
|
||||
if(-not $global:JSonSettingFile)
|
||||
{
|
||||
$global:JSonSettingFile = "$($env:LOCALAPPDATA)\CloudAPIPowerShellManagement\Settings.json"
|
||||
$global:JSonSettingFile = Join-Path (Get-CloudApiDataFolder) "Settings.json"
|
||||
$fi = [IO.FileInfo]$global:JSonSettingFile
|
||||
if($fi.Exists -eq $false)
|
||||
{
|
||||
@@ -1548,7 +1650,7 @@ function Add-RegKeyToSettings
|
||||
try
|
||||
{
|
||||
$keyObj = Get-Item -Path $regKey -ErrorAction SilentlyContinue
|
||||
foreach($keyValue in ($keyObj.GetValueNames() | Sort))
|
||||
foreach($keyValue in ($keyObj.GetValueNames() | Sort-Object))
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -1560,7 +1662,7 @@ function Add-RegKeyToSettings
|
||||
}
|
||||
}
|
||||
|
||||
foreach($subKey in ($keyObj.GetSubKeyNames() | Sort))
|
||||
foreach($subKey in ($keyObj.GetSubKeyNames() | Sort-Object))
|
||||
{
|
||||
|
||||
$settingObjSub = [ordered]@{}
|
||||
@@ -1967,7 +2069,7 @@ function Add-DefaultSettings
|
||||
Value = ""
|
||||
}
|
||||
|
||||
foreach($color in ([System.Drawing.Color].GetProperties() | Where { $_.PropertyType -eq [System.Drawing.Color] } | Sort -Property Name | Select Name).Name)
|
||||
foreach($color in ([System.Drawing.Color].GetProperties() | Where { $_.PropertyType -eq [System.Drawing.Color] } | Sort-Object -Property Name | Select Name).Name)
|
||||
{
|
||||
$script:lstColors += [PSCustomObject]@{
|
||||
Name = $color
|
||||
@@ -2286,7 +2388,7 @@ function Add-ViewItem
|
||||
if($viewObject.ViewInfo.Permissions -is [Object[]] -and $viewObject.ViewInfo.Permissions -notcontains $scope) { $viewObject.ViewInfo.Permissions += $scope }
|
||||
}
|
||||
|
||||
if($viewItem.Icon -or [IO.File]::Exists(($global:AppRootFolder + "\Xaml\Icons\$($viewItem.Id).xaml")))
|
||||
if($global:hideUI -ne $true -and ($viewItem.Icon -or [IO.File]::Exists(($global:AppRootFolder + "\Xaml\Icons\$($viewItem.Id).xaml"))))
|
||||
{
|
||||
$ctrl = Get-XamlObject ($global:AppRootFolder + "\Xaml\Icons\$((?? $viewItem.Icon $viewItem.Id)).xaml")
|
||||
$viewItem | Add-Member -NotePropertyName "IconImage" -NotePropertyValue $ctrl
|
||||
@@ -2926,4 +3028,4 @@ function Get-GUIDs
|
||||
|
||||
New-Alias -Name ?? -value Invoke-Coalesce
|
||||
New-Alias -Name ?: -value Invoke-IfTrue
|
||||
Export-ModuleMember -alias * -function *
|
||||
Export-ModuleMember -alias * -function *
|
||||
|
||||
Reference in New Issue
Block a user