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

[Refractor] Update Tab #3230

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ body:
attributes:
value: |
# 🐞 **Issue Report**
Thank you for taking the time to report an issue! Please provide as much detail as possible to help us address the problem efficiently.
Thank you for taking the time to report an issue! Please provide as much detail as possible to help us address the problem efficiently.
## ⚠️ **IMPORTANT**
- 🛠️ **Supported environments only:** We only support Windows 11. Custom ISOs that are not made using Microwin are not supported.
## ⚠️ **IMPORTANT**
- 🛠️ **Supported environments only:** We only support Windows 11. Custom ISOs that are not made using Microwin are not supported.
- 💡 For general questions, use the [Discussions section](https://github.com/Christitustech/winutil/discussions) or join our Community-driven [Discord Server](https://discord.gg/RUbZUZyByQ).
- type: checkboxes
Expand Down
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ body:
# ✨ **Feature request**
Thank you for taking the time to suggest a feature! Please provide as much detail as possible to help us understand and evaluate your request.
## ⚠️ **IMPORTANT**
## ⚠️ **IMPORTANT**
- 🛠️ **Supported environments only:** We only support Windows 11.
- 💡 For general questions, use the [Discussions section](https://github.com/Christitustech/winutil/discussions) or join our Community-driven [Discord Server](https://discord.gg/RUbZUZyByQ).
Expand Down Expand Up @@ -54,4 +54,4 @@ body:
label: 🖼️ Additional context
placeholder: "Include screenshots, code blocks (use triple backticks ```), or any other relevant information."
validations:
required: false
required: false
5 changes: 5 additions & 0 deletions functions/public/Invoke-WPFButton.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,10 @@ function Invoke-WPFButton {
"WPFWinUtilInstallPSProfile" {Invoke-WinUtilInstallPSProfile}
"WPFWinUtilUninstallPSProfile" {Invoke-WinUtilUninstallPSProfile}
"WPFWinUtilSSHServer" {Invoke-WPFSSHServer}
"WPFScanUpdates" {Invoke-WPFUpdatesScan}
"WPFShowUpdateHistory" { Invoke-WPFUpdateHistoryToggle }
"WPFUpdateSelectedInstall" {Invoke-WPFUpdateMGMT -Selected}
"WPFUpdateAllInstall" {Invoke-WPFUpdateMGMT -All}
"WPFUpdateScanHistory" {Invoke-WPFUpdateScanHistory}
}
}
11 changes: 11 additions & 0 deletions functions/public/Invoke-WPFUpdateHistoryToggle.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function Invoke-WPFUpdateHistoryToggle {
if ($sync["WPFShowUpdateHistory"].Content -eq "Show History") {
$sync["WPFShowUpdateHistory"].Content = "Show available Updates"
$sync["HistoryGrid"].Visibility = "Visible"
$sync["UpdatesGrid"].Visibility = "Collapsed"
} else {
$sync["WPFShowUpdateHistory"].Content = "Show History"
$sync["HistoryGrid"].Visibility = "Collapsed"
$sync["UpdatesGrid"].Visibility = "Visible"
}
}
45 changes: 45 additions & 0 deletions functions/public/Invoke-WPFUpdateMGMGT.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
function Invoke-WPFUpdateMGMT {
param (
[switch]$Selected,
[switch]$All
)

if ($All) {
Write-Host "Installing all available updates ..."
Invoke-WPFRunspace -ArgumentList $sync["WPFUpdateVerbose"].IsChecked -DebugPreference $DebugPreference -ScriptBlock {
param ($WPFUpdateVerbose)
if ($WPFUpdateVerbose) {
Install-WindowsUpdate -Verbose -Confirm:$false -IgnoreReboot:$true -IgnoreRebootRequired:$true
} else {
Install-WindowsUpdate -Confirm:$false -IgnoreReboot:$true -IgnoreRebootRequired:$true
}
Write-Host "All Update Processes Completed"
}
} elseif (($Selected) -and ($sync["WPFUpdatesList"].SelectedItems.Count -gt 0)) {
write-host "Installing selected updates..."
$selectedUpdates = $sync["WPFUpdatesList"].SelectedItems | ForEach-Object {
[PSCustomObject]@{
ComputerName = $_.ComputerName
Title = $_.LongTitle
KB = $_.KB
Size = $_.Size
}
}
Invoke-WPFRunspace -ParameterList @(("selectedUpdates", $selectedUpdates), ("WPFUpdateVerbose", $sync["WPFUpdateVerbose"].IsChecked)) -DebugPreference $DebugPreference -ScriptBlock {
param ($selectedUpdates, $WPFUpdateVerbose)
foreach ($update in $selectedUpdates) {
Write-Host "Installing update $($update.Title) on $($update.ComputerName)"
if ($WPFUpdateVerbose) {
Get-WindowsUpdate -ComputerName $update.ComputerName -Title $update.Title -Install -Confirm:$false -Verbose -IgnoreReboot:$true -IgnoreRebootRequired:$true
} else {
Get-WindowsUpdate -ComputerName $update.ComputerName -Title $update.Title -Install -Confirm:$false -IgnoreReboot:$true -IgnoreRebootRequired:$true
}
}
Write-Host "Selected Update Processes Completed"
}
} else {
Write-Host "No updates selected"
return
}

}
46 changes: 46 additions & 0 deletions functions/public/Invoke-WPFUpdateScanHistory.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function Invoke-WPFUpdateScanHistory {
$sync["WPFUpdateHistory"].Items.Clear()
Invoke-WPFRunspace -DebugPreference $DebugPreference -ScriptBlock {
write-host "Scanning for Windows update history..."
$UpdateHistory = Get-WUHistory -Last 50 -ErrorAction SilentlyContinue
if ($UpdateHistory) {
foreach ($update in $UpdateHistory) {
$item = New-Object PSObject -Property @{
ComputerName = $update.ComputerName
Result = $update.Result
Title = $update.Title -replace '\s*\(KB\d+\)', '' -replace '\s*KB\d+\b', '' # Remove KB number from title, first in parentheses, then standalone
KB = $update.KB
Date = $update.Date
}
$Computers = $item | Select-Object -ExpandProperty ComputerName -Unique
$sync.form.Dispatcher.Invoke([action] {
$sync["WPFUpdateHistory"].Items.Add($item)
if ($item.Result -eq "Succeeded") {
# does not work : $sync["WPFUpdateHistory"].Items[$sync["WPFUpdateHistory"].Items.Count - 1].Foreground = "Green"
#write-host "$($item.Title) was successful"
}
elseif ($item.Result -eq "Failed") {
# does not work : $sync["WPFUpdateHistory"].Items[$sync["WPFUpdateHistory"].Items.Count - 1].Foreground = "Red"
#write-host "$($item.Title) failed"
}
})
}
write-host "Found $($UpdateHistory.Count) updates."
$sync.form.Dispatcher.Invoke([action] {
if ($Computers.Count -gt 1) {
$sync["WPFUpdateHistory"].Columns[0].Visibility = "Visible"
}
else {
Write-Debug "Hiding ComputerName column, only $item.ComputerName"
$sync["WPFUpdateHistory"].Columns[0].Visibility = "Collapsed"
}
})
}
else {
$sync.form.Dispatcher.Invoke([action] {
$sync["WPFUpdateHistory"].Items.Clear()
})
Write-Host "No update history available."
}
}
}
58 changes: 58 additions & 0 deletions functions/public/Invoke-WPFUpdatesScan.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
function Invoke-WPFUpdatesScan {


Invoke-WPFRunspace -DebugPreference $DebugPreference -ScriptBlock {
# Check if the PSWindowsUpdate module is installed
if (-not (Get-Module -ListAvailable -Name PSWindowsUpdate)) {
try {
Write-Host "PSWindowsUpdate module not found. Attempting to install..."
Install-Module -Name PSWindowsUpdate -Force -Scope CurrentUser
Write-Host "PSWindowsUpdate module installed successfully."
}
catch {
Write-Error "Failed to install PSWindowsUpdate module: $_"
return
}
}

# Import the module
try {
Import-Module PSWindowsUpdate -ErrorAction Stop
Write-Host "PSWindowsUpdate module imported successfully."
}
catch {
Write-Error "Failed to import PSWindowsUpdate module: $_"
return
}

try {
$sync.form.Dispatcher.Invoke([action] { $sync["WPFUpdatesList"].Items.Clear() })
Write-Host "Scanning for Windows updates..."
$updates = Get-WindowsUpdate -ErrorAction Stop
Write-Host "Found $($updates.Count) updates."

$sync.form.Dispatcher.Invoke([action] {
foreach ($update in $updates) {
$item = New-Object PSObject -Property @{
LongTitle = $update.Title
ComputerName = $update.ComputerName
KB = $update.KB
Size = $update.Size
Title = $update.Title -replace '\s*\(KB\d+\)', '' -replace '\s*KB\d+\b', '' # Remove KB number from title, first in parentheses, then standalone
Status = "Not Installed"
}
$Computers = $item | Select-Object -ExpandProperty ComputerName -Unique
$sync["WPFUpdatesList"].Items.Add($item)
}
if ($Computers.Count -gt 1) {
$sync["WPFUpdatesList"].Columns[0].Visibility = "Visible"
} else {
Write-Debug "Hiding ComputerName column, only $item.ComputerName"
$sync["WPFUpdatesList"].Columns[0].Visibility = "Collapsed"
}
})
} catch {
Write-Error "Error scanning for updates: $_"
}
}
}
Loading