Files
winutil/scripts/main.ps1
T

558 lines
20 KiB
PowerShell
Raw Normal View History

2023-07-27 16:06:41 -05:00
# SPDX-License-Identifier: MIT
2023-10-19 17:12:55 -05:00
# Set the maximum number of threads for the RunspacePool to the number of threads on the machine
+2
2023-05-09 13:14:27 -05:00
$maxthreads = [int]$env:NUMBER_OF_PROCESSORS
2023-10-19 17:12:55 -05:00
# Create a new session state for parsing variables into our runspace
+2
2023-05-09 13:14:27 -05:00
$hashVars = New-object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'sync',$sync,$Null
$InitialSessionState = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
2023-10-19 17:12:55 -05:00
# Add the variable to the session state
+2
2023-05-09 13:14:27 -05:00
$InitialSessionState.Variables.Add($hashVars)
2023-10-19 17:12:55 -05:00
# Get every private function and add them to the session state
$functions = (Get-ChildItem function:\).where{$_.name -like "*winutil*" -or $_.name -like "*WPF*"}
foreach ($function in $functions) {
+2
2023-05-09 13:14:27 -05:00
$functionDefinition = Get-Content function:\$($function.name)
$functionEntry = New-Object System.Management.Automation.Runspaces.SessionStateFunctionEntry -ArgumentList $($function.name), $functionDefinition
2023-10-19 17:12:55 -05:00
+2
2023-05-09 13:14:27 -05:00
$initialSessionState.Commands.Add($functionEntry)
}
2023-10-19 17:12:55 -05:00
# Create the runspace pool
$sync.runspace = [runspacefactory]::CreateRunspacePool(
1, # Minimum thread count
$maxthreads, # Maximum thread count
$InitialSessionState, # Initial session state
$Host # Machine to create runspaces on
)
+2
2023-05-09 13:14:27 -05:00
2023-10-19 17:12:55 -05:00
# Open the RunspacePool instance
+2
2023-05-09 13:14:27 -05:00
$sync.runspace.Open()
2023-10-19 17:12:55 -05:00
# Create classes for different exceptions
+3
2023-03-07 12:28:00 -08:00
class WingetFailedInstall : Exception {
[string] $additionalData
WingetFailedInstall($Message) : base($Message) {}
}
2023-10-19 17:12:55 -05:00
+3
2023-03-07 12:28:00 -08:00
class ChocoFailedInstall : Exception {
[string] $additionalData
ChocoFailedInstall($Message) : base($Message) {}
}
class GenericException : Exception {
[string] $additionalData
GenericException($Message) : base($Message) {}
}
2023-10-19 17:12:55 -05:00
+3
2023-03-07 12:28:00 -08:00
$inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^<Win.*', '<Window'
2023-07-27 16:06:41 -05:00
$defaulttheme = '_default'
2024-01-02 15:45:06 -06:00
if ((Get-WinUtilToggleStatus WPFToggleDarkMode) -eq $True) {
if (Invoke-WinUtilGPU -eq $True) {
+8
2024-03-21 16:23:24 -07:00
$ctttheme = 'Matrix'
} else {
+8
2024-03-21 16:23:24 -07:00
$ctttheme = 'Dark'
}
} else {
2023-07-27 16:06:41 -05:00
$ctttheme = 'Classic'
}
$returnVal = Set-WinUtilUITheme -inputXML $inputXML -customThemeName $ctttheme -defaultThemeName $defaulttheme
if ($returnVal[0] -eq "") {
Write-Host "Failed to statically apply theming to xaml content using Set-WinUtilTheme, please check previous Error/Warning messages." -ForegroundColor Red
Write-Host "Quitting winutil..." -ForegroundColor Red
$sync.runspace.Dispose()
$sync.runspace.Close()
[System.GC]::Collect()
exit 1
}
$inputXML = $returnVal[0]
$ctttheme = $returnVal[1]
2023-07-13 15:46:00 -05:00
+3
2023-03-07 12:28:00 -08:00
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = $inputXML
2023-10-19 17:12:55 -05:00
# Read the XAML file
$readerOperationSuccessful = $false # There's more cases of failure then success.
+3
2023-03-07 12:28:00 -08:00
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
2024-07-08 22:59:58 +03:00
try {
$sync["Form"] = [Windows.Markup.XamlReader]::Load( $reader )
$readerOperationSuccessful = $true
2024-07-08 22:59:58 +03:00
} catch [System.Management.Automation.MethodInvocationException] {
2024-08-29 00:55:40 +03:00
Write-Host "We ran into a problem with the XAML code. Check the syntax for this control..." -ForegroundColor Red
+3
2023-03-07 12:28:00 -08:00
Write-Host $error[0].Exception.Message -ForegroundColor Red
2024-07-08 22:59:58 +03:00
+3
2023-03-07 12:28:00 -08:00
If ($error[0].Exception.Message -like "*button*") {
2024-08-29 00:55:40 +03:00
write-Host "Ensure your &lt;button in the `$inputXML does NOT have a Click=ButtonClick property. PS can't handle this`n`n`n`n" -ForegroundColor Red
+3
2023-03-07 12:28:00 -08:00
}
2024-07-08 22:59:58 +03:00
} catch {
2024-08-29 00:55:40 +03:00
Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed." -ForegroundColor Red
+3
2023-03-07 12:28:00 -08:00
}
if (-NOT ($readerOperationSuccessful)) {
Write-Host "Failed to parse xaml content using Windows.Markup.XamlReader's Load Method." -ForegroundColor Red
Write-Host "Quitting winutil..." -ForegroundColor Red
$sync.runspace.Dispose()
$sync.runspace.Close()
[System.GC]::Collect()
exit 1
}
2024-08-29 00:55:40 +03:00
# Load the configuration files
#Invoke-WPFUIElements -configVariable $sync.configs.nav -targetGridName "WPFMainGrid"
Invoke-WPFUIElements -configVariable $sync.configs.applications -targetGridName "appspanel" -columncount 5
Invoke-WPFUIElements -configVariable $sync.configs.tweaks -targetGridName "tweakspanel" -columncount 2
Invoke-WPFUIElements -configVariable $sync.configs.feature -targetGridName "featurespanel" -columncount 2
+3
2023-03-07 12:28:00 -08:00
#===========================================================================
# Store Form Objects In PowerShell
#===========================================================================
+2
2023-05-09 13:14:27 -05:00
$xaml.SelectNodes("//*[@Name]") | ForEach-Object {$sync["$("$($psitem.Name)")"] = $sync["Form"].FindName($psitem.Name)}
+3
2023-03-07 12:28:00 -08:00
+2
2023-05-09 13:14:27 -05:00
$sync.keys | ForEach-Object {
if($sync.$psitem) {
if($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "ToggleButton") {
+12
2023-11-28 16:11:11 -06:00
$sync["$psitem"].Add_Click({
[System.Object]$Sender = $args[0]
Invoke-WPFButton $Sender.name
})
}
2023-07-27 16:06:41 -05:00
if($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "Button") {
2023-07-27 16:06:41 -05:00
$sync["$psitem"].Add_Click({
[System.Object]$Sender = $args[0]
2024-01-12 00:34:41 -06:00
Invoke-WPFButton $Sender.name
2023-07-27 16:06:41 -05:00
})
}
2024-01-12 00:34:41 -06:00
if ($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "TextBlock") {
if ($sync["$psitem"].Name.EndsWith("Link")) {
$sync["$psitem"].Add_MouseUp({
[System.Object]$Sender = $args[0]
Start-Process $Sender.ToolTip -ErrorAction Stop
2024-01-15 11:32:19 -06:00
Write-Debug "Opening: $($Sender.ToolTip)"
2024-01-12 00:34:41 -06:00
})
}
+2
2024-02-02 16:22:08 -06:00
2024-01-12 00:34:41 -06:00
}
2023-07-27 16:06:41 -05:00
}
}
+3
2023-03-07 12:28:00 -08:00
#===========================================================================
# Setup background config
#===========================================================================
2023-10-19 17:12:55 -05:00
# Load computer information in the background
+3
2023-03-07 12:28:00 -08:00
Invoke-WPFRunspace -ScriptBlock {
try {
$oldProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
$sync.ConfigLoaded = $False
$sync.ComputerInfo = Get-ComputerInfo
$sync.ConfigLoaded = $True
}
finally{
$ProgressPreference = "Continue"
}
+3
2023-03-07 12:28:00 -08:00
} | Out-Null
#===========================================================================
2023-10-19 17:12:55 -05:00
# Setup and Show the Form
+3
2023-03-07 12:28:00 -08:00
#===========================================================================
2023-10-19 17:12:55 -05:00
# Print the logo
+3
2023-03-07 12:28:00 -08:00
Invoke-WPFFormVariables
# Progress bar in taskbaritem > Set-WinUtilProgressbar
$sync["Form"].TaskbarItemInfo = New-Object System.Windows.Shell.TaskbarItemInfo
Set-WinUtilTaskbaritem -state "None"
2023-10-19 17:12:55 -05:00
# Set the titlebar
+2
2023-05-09 13:14:27 -05:00
$sync["Form"].title = $sync["Form"].title + " " + $sync.version
2023-10-19 17:12:55 -05:00
# Set the commands that will run when the form is closed
+2
2023-05-09 13:14:27 -05:00
$sync["Form"].Add_Closing({
$sync.runspace.Dispose()
$sync.runspace.Close()
[System.GC]::Collect()
})
2024-01-12 00:34:41 -06:00
# Attach the event handler to the Click event
2024-07-08 22:59:58 +03:00
$sync.SearchBarClearButton.Add_Click({
$sync.SearchBar.Text = ""
$sync.SearchBarClearButton.Visibility = "Collapsed"
2024-01-12 00:34:41 -06:00
})
+12
2023-11-28 16:11:11 -06:00
# add some shortcuts for people that don't like clicking
$commonKeyEvents = {
if ($sync.ProcessRunning -eq $true) {
return
}
if ($_.Key -eq "Escape") {
2024-07-08 22:59:58 +03:00
$sync.SearchBar.SelectAll()
$sync.SearchBar.Text = ""
$sync.SearchBarClearButton.Visibility = "Collapsed"
2024-01-12 00:34:41 -06:00
return
+12
2023-11-28 16:11:11 -06:00
}
# don't ask, I know what I'm doing, just go...
if (($_.Key -eq "Q" -and $_.KeyboardDevice.Modifiers -eq "Ctrl")) {
+12
2023-11-28 16:11:11 -06:00
$this.Close()
}
if ($_.KeyboardDevice.Modifiers -eq "Alt") {
if ($_.SystemKey -eq "I") {
Invoke-WPFButton "WPFTab1BT"
}
if ($_.SystemKey -eq "T") {
Invoke-WPFButton "WPFTab2BT"
}
if ($_.SystemKey -eq "C") {
Invoke-WPFButton "WPFTab3BT"
}
if ($_.SystemKey -eq "U") {
Invoke-WPFButton "WPFTab4BT"
}
if ($_.SystemKey -eq "M") {
Invoke-WPFButton "WPFTab5BT"
}
2024-01-12 00:34:41 -06:00
if ($_.SystemKey -eq "P") {
Write-Host "Your Windows Product Key: $((Get-WmiObject -query 'select * from SoftwareLicensingService').OA3xOriginalProductKey)"
}
+12
2023-11-28 16:11:11 -06:00
}
# shortcut for the filter box
if ($_.Key -eq "F" -and $_.KeyboardDevice.Modifiers -eq "Ctrl") {
2024-07-08 22:59:58 +03:00
if ($sync.SearchBar.Text -eq "Ctrl-F to filter") {
$sync.SearchBar.SelectAll()
$sync.SearchBar.Text = ""
+12
2023-11-28 16:11:11 -06:00
}
2024-07-08 22:59:58 +03:00
$sync.SearchBar.Focus()
+12
2023-11-28 16:11:11 -06:00
}
}
2024-01-12 00:34:41 -06:00
+12
2023-11-28 16:11:11 -06:00
$sync["Form"].Add_PreViewKeyDown($commonKeyEvents)
$sync["Form"].Add_MouseLeftButtonDown({
2024-01-15 11:32:19 -06:00
if ($sync["SettingsPopup"].IsOpen) {
$sync["SettingsPopup"].IsOpen = $false
}
+12
2023-11-28 16:11:11 -06:00
$sync["Form"].DragMove()
})
2023-12-19 13:55:55 -06:00
$sync["Form"].Add_MouseDoubleClick({
if ($sync["Form"].WindowState -eq [Windows.WindowState]::Normal) {
2023-12-19 13:55:55 -06:00
$sync["Form"].WindowState = [Windows.WindowState]::Maximized;
} else {
2023-12-19 13:55:55 -06:00
$sync["Form"].WindowState = [Windows.WindowState]::Normal;
}
})
2024-01-15 11:32:19 -06:00
$sync["Form"].Add_Deactivated({
Write-Debug "WinUtil lost focus"
if ($sync["SettingsPopup"].IsOpen) {
$sync["SettingsPopup"].IsOpen = $false
+12
2023-11-28 16:11:11 -06:00
}
2024-01-15 11:32:19 -06:00
})
$sync["Form"].Add_ContentRendered({
+12
2023-11-28 16:11:11 -06:00
+2
2024-02-02 16:22:08 -06:00
try {
2024-01-12 00:34:41 -06:00
[void][Window]
} catch {
2024-01-15 11:32:19 -06:00
Add-Type @"
+12
2023-11-28 16:11:11 -06:00
using System;
using System.Runtime.InteropServices;
public class Window {
2024-01-15 11:32:19 -06:00
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
+12
2023-11-28 16:11:11 -06:00
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
+2
2024-02-02 16:22:08 -06:00
+12
2023-11-28 16:11:11 -06:00
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MoveWindow(IntPtr handle, int x, int y, int width, int height, bool redraw);
+2
2024-02-02 16:22:08 -06:00
+12
2023-11-28 16:11:11 -06:00
[DllImport("user32.dll")]
2024-01-12 00:34:41 -06:00
public static extern int GetSystemMetrics(int nIndex);
2024-01-15 11:32:19 -06:00
};
+12
2023-11-28 16:11:11 -06:00
public struct RECT {
public int Left; // x position of upper-left corner
public int Top; // y position of upper-left corner
public int Right; // x position of lower-right corner
public int Bottom; // y position of lower-right corner
}
"@
}
2024-01-12 00:34:41 -06:00
foreach ($proc in (Get-Process).where{ $_.MainWindowTitle -and $_.MainWindowTitle -like "*titus*" }) {
+26
2024-06-04 20:27:27 -07:00
# Check if the process's MainWindowHandle is valid
if ($proc.MainWindowHandle -ne [System.IntPtr]::Zero) {
2024-01-15 11:32:19 -06:00
Write-Debug "MainWindowHandle: $($proc.Id) $($proc.MainWindowTitle) $($proc.MainWindowHandle)"
$windowHandle = $proc.MainWindowHandle
} else {
Write-Warning "Process found, but no MainWindowHandle: $($proc.Id) $($proc.MainWindowTitle)"
2024-01-15 11:32:19 -06:00
}
}
+12
2023-11-28 16:11:11 -06:00
$rect = New-Object RECT
2024-01-15 11:32:19 -06:00
[Window]::GetWindowRect($windowHandle, [ref]$rect)
+12
2023-11-28 16:11:11 -06:00
$width = $rect.Right - $rect.Left
$height = $rect.Bottom - $rect.Top
2024-01-12 00:34:41 -06:00
Write-Debug "UpperLeft:$($rect.Left),$($rect.Top) LowerBottom:$($rect.Right),$($rect.Bottom). Width:$($width) Height:$($height)"
# Load the Windows Forms assembly
Add-Type -AssemblyName System.Windows.Forms
$primaryScreen = [System.Windows.Forms.Screen]::PrimaryScreen
# Check if the primary screen is found
if ($primaryScreen) {
# Extract screen width and height for the primary monitor
$screenWidth = $primaryScreen.Bounds.Width
$screenHeight = $primaryScreen.Bounds.Height
# Print the screen size
Write-Debug "Primary Monitor Width: $screenWidth pixels"
Write-Debug "Primary Monitor Height: $screenHeight pixels"
# Compare with the primary monitor size
if ($width -gt $screenWidth -or $height -gt $screenHeight) {
Write-Debug "The specified width and/or height is greater than the primary monitor size."
[void][Window]::MoveWindow($windowHandle, 0, 0, $screenWidth, $screenHeight, $True)
} else {
Write-Debug "The specified width and height are within the primary monitor size limits."
}
} else {
Write-Debug "Unable to retrieve information about the primary monitor."
}
+2
2024-02-02 16:22:08 -06:00
+12
2023-11-28 16:11:11 -06:00
Invoke-WPFTab "WPFTab1BT"
$sync["Form"].Focus()
2024-01-15 11:32:19 -06:00
# maybe this is not the best place to load and execute config file?
# maybe community can help?
if ($PARAM_CONFIG) {
2024-01-15 11:32:19 -06:00
Invoke-WPFImpex -type "import" -Config $PARAM_CONFIG
if ($PARAM_RUN) {
2024-01-15 11:32:19 -06:00
while ($sync.ProcessRunning) {
Start-Sleep -Seconds 5
}
Start-Sleep -Seconds 5
Write-Host "Applying tweaks..."
Invoke-WPFtweaksbutton
while ($sync.ProcessRunning) {
Start-Sleep -Seconds 5
}
Start-Sleep -Seconds 5
Write-Host "Installing features..."
Invoke-WPFFeatureInstall
while ($sync.ProcessRunning) {
Start-Sleep -Seconds 5
}
Start-Sleep -Seconds 5
Write-Host "Installing applications..."
while ($sync.ProcessRunning) {
Start-Sleep -Seconds 1
}
Invoke-WPFInstall
Start-Sleep -Seconds 5
Write-Host "Done."
}
}
+12
2023-11-28 16:11:11 -06:00
})
2024-07-09 05:06:12 +09:00
# Load Checkboxes and Labels outside of the Filter function only once on startup for performance reasons
+26
2024-06-04 20:27:27 -07:00
$filter = Get-WinUtilVariables -Type CheckBox
$CheckBoxes = ($sync.GetEnumerator()).where{ $psitem.Key -in $filter }
+26
2024-06-04 20:27:27 -07:00
$filter = Get-WinUtilVariables -Type Label
$labels = @{}
($sync.GetEnumerator()).where{$PSItem.Key -in $filter} | ForEach-Object {$labels[$_.Key] = $_.Value}
+26
2024-06-04 20:27:27 -07:00
$allCategories = $checkBoxes.Name | ForEach-Object {$sync.configs.applications.$_} | Select-Object -Unique -ExpandProperty category
+26
2024-06-04 20:27:27 -07:00
2024-07-08 22:59:58 +03:00
$sync["SearchBar"].Add_TextChanged({
if ($sync.SearchBar.Text -ne "") {
$sync.SearchBarClearButton.Visibility = "Visible"
} else {
2024-07-08 22:59:58 +03:00
$sync.SearchBarClearButton.Visibility = "Collapsed"
2024-01-12 00:34:41 -06:00
}
+26
2024-06-04 20:27:27 -07:00
$activeApplications = @()
+2
2024-02-02 16:22:08 -06:00
$textToSearch = $sync.SearchBar.Text.ToLower()
2024-01-12 00:34:41 -06:00
foreach ($CheckBox in $CheckBoxes) {
# Check if the checkbox is null or if it doesn't have content
+2
2024-02-02 16:22:08 -06:00
if ($CheckBox -eq $null -or $CheckBox.Value -eq $null -or $CheckBox.Value.Content -eq $null) {
+12
2023-11-28 16:11:11 -06:00
continue
}
+2
2024-02-02 16:22:08 -06:00
2024-01-12 00:34:41 -06:00
$checkBoxName = $CheckBox.Key
$textBlockName = $checkBoxName + "Link"
+2
2024-02-02 16:22:08 -06:00
2024-01-12 00:34:41 -06:00
# Retrieve the corresponding text block based on the generated name
$textBlock = $sync[$textBlockName]
+2
2024-02-02 16:22:08 -06:00
2024-01-12 00:34:41 -06:00
if ($CheckBox.Value.Content.ToLower().Contains($textToSearch)) {
$CheckBox.Value.Visibility = "Visible"
+26
2024-06-04 20:27:27 -07:00
$activeApplications += $sync.configs.applications.$checkboxName
# Set the corresponding text block visibility
if ($textBlock -ne $null -and $textBlock -is [System.Windows.Controls.TextBlock]) {
2024-01-12 00:34:41 -06:00
$textBlock.Visibility = "Visible"
}
} else {
$CheckBox.Value.Visibility = "Collapsed"
2024-01-12 00:34:41 -06:00
# Set the corresponding text block visibility
if ($textBlock -ne $null -and $textBlock -is [System.Windows.Controls.TextBlock]) {
2024-01-12 00:34:41 -06:00
$textBlock.Visibility = "Collapsed"
}
}
}
+26
2024-06-04 20:27:27 -07:00
$activeCategories = $activeApplications | Select-Object -ExpandProperty category -Unique
+2
2024-02-02 16:22:08 -06:00
foreach ($category in $activeCategories) {
$sync[$category].Visibility = "Visible"
+26
2024-06-04 20:27:27 -07:00
}
if ($activeCategories) {
+26
2024-06-04 20:27:27 -07:00
$inactiveCategories = Compare-Object -ReferenceObject $allCategories -DifferenceObject $activeCategories -PassThru
} else {
+26
2024-06-04 20:27:27 -07:00
$inactiveCategories = $allCategories
}
foreach ($category in $inactiveCategories) {
$sync[$category].Visibility = "Collapsed"
}
+12
2023-11-28 16:11:11 -06:00
})
$sync["Form"].Add_Loaded({
param($e)
$sync["Form"].MaxWidth = [Double]::PositiveInfinity
$sync["Form"].MaxHeight = [Double]::PositiveInfinity
})
# Initialize the hashtable
$winutildir = @{}
# Set the path for the winutil directory
$winutildir["path"] = "$env:LOCALAPPDATA\winutil\"
if (-NOT (Test-Path -Path $winutildir["path"])) {
New-Item -Path $winutildir["path"] -ItemType Directory
}
# Set the path for the logo and checkmark images
$winutildir["logo.png"] = $winutildir["path"] + "cttlogo.png"
$winutildir["logo.ico"] = $winutildir["path"] + "cttlogo.ico"
if (-NOT (Test-Path -Path $winutildir["logo.png"])) {
Invoke-WebRequest -Uri "https://christitus.com/images/logo-full.png" -OutFile $winutildir["logo.png"]
}
if (-NOT (Test-Path -Path $winutildir["logo.ico"])) {
ConvertTo-Icon -bitmapPath $winutildir["logo.png"] -iconPath $winutildir["logo.ico"]
}
$winutildir["checkmark.png"] = $winutildir["path"] + "checkmark.png"
$winutildir["warning.png"] = $winutildir["path"] + "warning.png"
if (-NOT (Test-Path -Path $winutildir["checkmark.png"])) {
Invoke-WebRequest -Uri "https://christitus.com/images/checkmark.png" -OutFile $winutildir["checkmark.png"]
}
if (-NOT (Test-Path -Path $winutildir["warning.png"])) {
Invoke-WebRequest -Uri "https://christitus.com/images/warning.png" -OutFile $winutildir["warning.png"]
}
Set-WinUtilTaskbaritem -overlay "logo"
$sync["Form"].Add_Activated({
Set-WinUtilTaskbaritem -overlay "logo"
})
2024-01-15 11:32:19 -06:00
# Define event handler for button click
$sync["SettingsButton"].Add_Click({
Write-Debug "SettingsButton clicked"
if ($sync["SettingsPopup"].IsOpen) {
$sync["SettingsPopup"].IsOpen = $false
} else {
2024-01-15 11:32:19 -06:00
$sync["SettingsPopup"].IsOpen = $true
}
$_.Handled = $false
})
# Define event handlers for menu items
$sync["ImportMenuItem"].Add_Click({
# Handle Import menu item click
Write-Debug "Import clicked"
$sync["SettingsPopup"].IsOpen = $false
Invoke-WPFImpex -type "import"
$_.Handled = $false
})
$sync["ExportMenuItem"].Add_Click({
# Handle Export menu item click
Write-Debug "Export clicked"
$sync["SettingsPopup"].IsOpen = $false
Invoke-WPFImpex -type "export"
$_.Handled = $false
})
$sync["AboutMenuItem"].Add_Click({
# Handle Export menu item click
Write-Debug "About clicked"
$sync["SettingsPopup"].IsOpen = $false
$authorInfo = @"
2024-06-25 20:54:18 +02:00
Author : <a href="https://github.com/ChrisTitusTech">@christitustech</a>
Runspace : <a href="https://github.com/DeveloperDurp">@DeveloperDurp</a>
MicroWin : <a href="https://github.com/KonTy">@KonTy</a>
GitHub : <a href="https://github.com/ChrisTitusTech/winutil">ChrisTitusTech/winutil</a>
Version : <a href="https://github.com/ChrisTitusTech/winutil/releases/tag/$($sync.version)">$($sync.version)</a>
+2
2024-02-02 16:22:08 -06:00
"@
2024-07-08 22:59:58 +03:00
$FontSize = $sync.configs.themes.$ctttheme.CustomDialogFontSize
$HeaderFontSize = $sync.configs.themes.$ctttheme.CustomDialogFontSizeHeader
$IconSize = $sync.configs.themes.$ctttheme.CustomDialogIconSize
$Width = $sync.configs.themes.$ctttheme.CustomDialogWidth
$Height = $sync.configs.themes.$ctttheme.CustomDialogHeight
Show-CustomDialog -Message $authorInfo -Width $Width -Height $Height -FontSize $FontSize -HeaderFontSize $HeaderFontSize -IconSize $IconSize
2024-01-15 11:32:19 -06:00
})
2024-07-14 18:50:40 -05:00
$sync["SponsorMenuItem"].Add_Click({
# Handle Export menu item click
Write-Debug "Sponsors clicked"
$sync["SettingsPopup"].IsOpen = $false
$authorInfo = @"
<a href="https://github.com/sponsors/ChrisTitusTech">Current sponsors for ChrisTitusTech:</a>
"@
$authorInfo += "`n"
try {
# Call the function to get the sponsors
$sponsors = Invoke-WinUtilSponsors
# Append the sponsors to the authorInfo
$sponsors | ForEach-Object { $authorInfo += "$_`n" }
} catch {
2024-07-14 18:50:40 -05:00
$authorInfo += "An error occurred while fetching or processing the sponsors: $_`n"
}
$FontSize = $sync.configs.themes.$ctttheme.CustomDialogFontSize
$HeaderFontSize = $sync.configs.themes.$ctttheme.CustomDialogFontSizeHeader
$IconSize = $sync.configs.themes.$ctttheme.CustomDialogIconSize
$Width = $sync.configs.themes.$ctttheme.CustomDialogWidth
$Height = $sync.configs.themes.$ctttheme.CustomDialogHeight
Show-CustomDialog -Message $authorInfo -Width $Width -Height $Height -FontSize $FontSize -HeaderFontSize $HeaderFontSize -IconSize $IconSize -EnableScroll $true
})
+12
2023-11-28 16:11:11 -06:00
$sync["Form"].ShowDialog() | out-null
+8
2024-03-21 16:23:24 -07:00
Stop-Transcript