Merge branch 'main' into refactoring-code-02

This commit is contained in:
Mr.k
2024-08-26 16:14:08 +03:00
207 changed files with 18828 additions and 21818 deletions

View File

@ -11,7 +11,7 @@ $InitialSessionState.Variables.Add($hashVars)
# 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){
foreach ($function in $functions) {
$functionDefinition = Get-Content function:\$($function.name)
$functionEntry = New-Object System.Management.Automation.Runspaces.SessionStateFunctionEntry -ArgumentList $($function.name), $functionDefinition
@ -55,12 +55,10 @@ $inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -repla
if ((Get-WinUtilToggleStatus WPFToggleDarkMode) -eq $True) {
if (Invoke-WinUtilGPU -eq $True) {
$ctttheme = 'Matrix'
}
else {
} else {
$ctttheme = 'Dark'
}
}
else {
} else {
$ctttheme = 'Classic'
}
@ -110,9 +108,9 @@ if (-NOT ($readerOperationSuccessful)) {
$xaml.SelectNodes("//*[@Name]") | ForEach-Object {$sync["$("$($psitem.Name)")"] = $sync["Form"].FindName($psitem.Name)}
$sync.keys | ForEach-Object {
if($sync.$psitem){
if($sync.$psitem) {
if($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "CheckBox" `
-and $sync["$psitem"].Name -like "WPFToggle*"){
-and $sync["$psitem"].Name -like "WPFToggle*") {
$sync["$psitem"].IsChecked = Get-WinUtilToggleStatus $sync["$psitem"].Name
$sync["$psitem"].Add_Click({
@ -121,14 +119,14 @@ $sync.keys | ForEach-Object {
})
}
if($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "ToggleButton"){
if($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "ToggleButton") {
$sync["$psitem"].Add_Click({
[System.Object]$Sender = $args[0]
Invoke-WPFButton $Sender.name
})
}
if($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "Button"){
if($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "Button") {
$sync["$psitem"].Add_Click({
[System.Object]$Sender = $args[0]
Invoke-WPFButton $Sender.name
@ -154,7 +152,7 @@ $sync.keys | ForEach-Object {
# Load computer information in the background
Invoke-WPFRunspace -ScriptBlock {
try{
try {
$oldProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
$sync.ConfigLoaded = $False
@ -199,8 +197,7 @@ $commonKeyEvents = {
return
}
if ($_.Key -eq "Escape")
{
if ($_.Key -eq "Escape") {
$sync.SearchBar.SelectAll()
$sync.SearchBar.Text = ""
$sync.SearchBarClearButton.Visibility = "Collapsed"
@ -208,8 +205,7 @@ $commonKeyEvents = {
}
# don't ask, I know what I'm doing, just go...
if (($_.Key -eq "Q" -and $_.KeyboardDevice.Modifiers -eq "Ctrl"))
{
if (($_.Key -eq "Q" -and $_.KeyboardDevice.Modifiers -eq "Ctrl")) {
$this.Close()
}
if ($_.KeyboardDevice.Modifiers -eq "Alt") {
@ -252,12 +248,9 @@ $sync["Form"].Add_MouseLeftButtonDown({
})
$sync["Form"].Add_MouseDoubleClick({
if ($sync["Form"].WindowState -eq [Windows.WindowState]::Normal)
{
if ($sync["Form"].WindowState -eq [Windows.WindowState]::Normal) {
$sync["Form"].WindowState = [Windows.WindowState]::Maximized;
}
else
{
} else {
$sync["Form"].WindowState = [Windows.WindowState]::Normal;
}
})
@ -303,11 +296,11 @@ Add-Type @"
foreach ($proc in (Get-Process).where{ $_.MainWindowTitle -and $_.MainWindowTitle -like "*titus*" }) {
# Check if the process's MainWindowHandle is valid
if ($proc.MainWindowHandle -ne [System.IntPtr]::Zero) {
if ($proc.MainWindowHandle -ne [System.IntPtr]::Zero) {
Write-Debug "MainWindowHandle: $($proc.Id) $($proc.MainWindowTitle) $($proc.MainWindowHandle)"
$windowHandle = $proc.MainWindowHandle
} else {
Write-Warning "Process found, but no MainWindowHandle: $($proc.Id) $($proc.MainWindowTitle)"
} else {
Write-Warning "Process found, but no MainWindowHandle: $($proc.Id) $($proc.MainWindowTitle)"
}
}
@ -348,9 +341,9 @@ Add-Type @"
# maybe this is not the best place to load and execute config file?
# maybe community can help?
if ($PARAM_CONFIG){
if ($PARAM_CONFIG) {
Invoke-WPFImpex -type "import" -Config $PARAM_CONFIG
if ($PARAM_RUN){
if ($PARAM_RUN) {
while ($sync.ProcessRunning) {
Start-Sleep -Seconds 5
}
@ -397,8 +390,7 @@ $sync["SearchBar"].Add_TextChanged({
if ($sync.SearchBar.Text -ne "") {
$sync.SearchBarClearButton.Visibility = "Visible"
}
else {
} else {
$sync.SearchBarClearButton.Visibility = "Collapsed"
}
@ -424,8 +416,7 @@ $sync["SearchBar"].Add_TextChanged({
if ($textBlock -ne $null) {
$textBlock.Visibility = "Visible"
}
}
else {
} else {
$CheckBox.Value.Visibility = "Collapsed"
# Set the corresponding text block visibility
if ($textBlock -ne $null) {
@ -435,17 +426,16 @@ $sync["SearchBar"].Add_TextChanged({
}
$activeCategories = $activeApplications | Select-Object -ExpandProperty category -Unique
foreach ($category in $activeCategories){
foreach ($category in $activeCategories) {
$label = $labels[$(Get-WPFObjectName -type "Label" -name $category)]
$label.Visibility = "Visible"
}
if ($activeCategories){
if ($activeCategories) {
$inactiveCategories = Compare-Object -ReferenceObject $allCategories -DifferenceObject $activeCategories -PassThru
}
else{
} else {
$inactiveCategories = $allCategories
}
foreach ($category in $inactiveCategories){
foreach ($category in $inactiveCategories) {
$label = $labels[$(Get-WPFObjectName -type "Label" -name $category)]
$label.Visibility = "Collapsed"}
})
@ -491,8 +481,7 @@ $sync["SettingsButton"].Add_Click({
Write-Debug "SettingsButton clicked"
if ($sync["SettingsPopup"].IsOpen) {
$sync["SettingsPopup"].IsOpen = $false
}
else {
} else {
$sync["SettingsPopup"].IsOpen = $true
}
$_.Handled = $false
@ -548,8 +537,7 @@ $sync["SponsorMenuItem"].Add_Click({
# Append the sponsors to the authorInfo
$sponsors | ForEach-Object { $authorInfo += "$_`n" }
}
catch {
} catch {
$authorInfo += "An error occurred while fetching or processing the sponsors: $_`n"
}

View File

@ -45,8 +45,7 @@ $sync.configs = @{}
$sync.ProcessRunning = $false
# If script isn't running as admin, show error message and quit
If (([Security.Principal.WindowsIdentity]::GetCurrent()).Owner.Value -ne "S-1-5-32-544")
{
If (([Security.Principal.WindowsIdentity]::GetCurrent()).Owner.Value -ne "S-1-5-32-544") {
Write-Host "===========================================" -Foregroundcolor Red
Write-Host "-- Scripts must be run as Administrator ---" -Foregroundcolor Red
Write-Host "-- Right-Click Start -> Terminal(Admin) ---" -Foregroundcolor Red