Nahid_Utility.ps1
|
<#PSScriptInfo .VERSION 1.0.0 .GUID 8f696a63-fc1a-416a-bc32-6b4e52898647 .AUTHOR NotNahid .COMPANYNAME .COPYRIGHT .TAGS .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES #> <# .DESCRIPTION Dynamic utility launcher that downloads and runs various tools. #> Param() <# .SYNOPSIS Nahid Utility Launcher .DESCRIPTION Dynamic utility launcher that downloads and runs various tools. .AUTHOR NotNahid .VERSION 1.0.0 .GUID c44d214e-8c73-4cf8-b771-debdacb44f05 #> Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing # ============================= # UTILITY DATABASE (VALIDATED) # ============================= $Utilities = @( @{ Name="Ghost Typer"; Link="https://gist.githubusercontent.com/NotNahid/70de29086ac0bbeab57a9a75a4f04a89/raw/copy-script.ps1"; Desc="Auto-type text anywhere"; Category="Automation"; Tags=@("typing","automation","productivity") }, @{ Name="Portfolio"; Link="https://dub.sh/notnahid"; Desc="Open my portfolio website"; Category="Personal"; Tags=@("portfolio","website") }, @{ Name="Rename Tool"; Link="https://dub.sh/rename"; Desc="Bulk rename files easily"; Category="File Management"; Tags=@("files","rename","bulk") }, @{ Name="FFmpeg With GUI"; Link="https://gist.githubusercontent.com/NotNahid/597ba29f82e30a4a6d3b9f6c92e95dcc/raw/cc97c5c4cac6b89495e19871e3ce50318936650d/FFmpegGUI.ps1"; Desc="Use FFmpeg in GUI Edit Video and Audio too!"; Category="Editing"; Tags=@("system","info","diagnostic") }, @{ Name="Network Speed Monitor"; Link="https://gist.githubusercontent.com/NotNahid/4db4bcd3c7ee8b7ed4c9f936f2aba3cf/raw/d423b1fc6405063cd0f2f7fbc574abe07c272508/Network%2520Speed%2520Monitor.ps1"; Desc="Network Speed Monitor"; Category="Network"; Tags=@("network","scan","devices") }, @{ Name="File Organizer"; Link="https://gist.githubusercontent.com/NotNahid/4825d849656826c378aadb81390ce9d9/raw/File_Organizer.ps1"; Desc="File Organizer"; Category="Security"; Tags=@("password","security","generator") }, @{ Name="Christitus Ultimate Utility"; Link="christitus.com/win"; Desc="Advanced clipboard management"; Category="Productivity"; Tags=@("clipboard","copy","paste") } @{ Name="Quick Tools in System Trey"; Link="https://raw.githubusercontent.com/NotNahid/use/refs/heads/main/Powershell/Quick%20Utiltiy.ps1"; Desc="Advanced clipboard management"; Category="Productivity"; Tags=@("clipboard","copy","paste") } ) # ============================= # VALIDATE UTILITIES DATA # ============================= function Validate-Utilities { $validatedUtilities = @() $requiredFields = @("Name", "Link", "Desc", "Category", "Tags") foreach ($util in $Utilities) { $isValid = $true $missingFields = @() foreach ($field in $requiredFields) { if (-not $util.ContainsKey($field) -or [string]::IsNullOrWhiteSpace($util[$field])) { $isValid = $false $missingFields += $field } } if ($isValid) { $validatedUtilities += $util } else { Write-Warning "Skipping invalid utility: Missing fields [$($missingFields -join ', ')]" } } return $validatedUtilities } # Validate and use only valid utilities $script:ValidatedUtilities = Validate-Utilities if ($script:ValidatedUtilities.Count -eq 0) { Write-Error "No valid utilities found! Please check your utilities data." exit } # ============================= # THEME SYSTEM # ============================= $script:CurrentTheme = "Dark" $DarkTheme = @{ Background = [System.Drawing.Color]::FromArgb(18, 18, 18) Surface = [System.Drawing.Color]::FromArgb(28, 28, 30) SurfaceLight = [System.Drawing.Color]::FromArgb(38, 38, 40) SurfaceHover = [System.Drawing.Color]::FromArgb(48, 48, 50) Primary = [System.Drawing.Color]::FromArgb(0, 122, 255) PrimaryHover = [System.Drawing.Color]::FromArgb(10, 132, 255) Success = [System.Drawing.Color]::FromArgb(52, 199, 89) SuccessHover = [System.Drawing.Color]::FromArgb(62, 209, 99) Warning = [System.Drawing.Color]::FromArgb(255, 204, 0) Danger = [System.Drawing.Color]::FromArgb(255, 69, 58) DangerHover = [System.Drawing.Color]::FromArgb(255, 89, 78) Text = [System.Drawing.Color]::FromArgb(255, 255, 255) TextSecondary = [System.Drawing.Color]::FromArgb(174, 174, 178) Border = [System.Drawing.Color]::FromArgb(58, 58, 60) SearchBox = [System.Drawing.Color]::FromArgb(44, 44, 46) } $LightTheme = @{ Background = [System.Drawing.Color]::FromArgb(245, 245, 247) Surface = [System.Drawing.Color]::FromArgb(255, 255, 255) SurfaceLight = [System.Drawing.Color]::FromArgb(250, 250, 252) SurfaceHover = [System.Drawing.Color]::FromArgb(240, 240, 245) Primary = [System.Drawing.Color]::FromArgb(0, 122, 255) PrimaryHover = [System.Drawing.Color]::FromArgb(10, 132, 255) Success = [System.Drawing.Color]::FromArgb(52, 199, 89) SuccessHover = [System.Drawing.Color]::FromArgb(62, 209, 99) Warning = [System.Drawing.Color]::FromArgb(255, 204, 0) Danger = [System.Drawing.Color]::FromArgb(255, 69, 58) DangerHover = [System.Drawing.Color]::FromArgb(255, 89, 78) Text = [System.Drawing.Color]::FromArgb(0, 0, 0) TextSecondary = [System.Drawing.Color]::FromArgb(90, 90, 95) Border = [System.Drawing.Color]::FromArgb(200, 200, 205) SearchBox = [System.Drawing.Color]::FromArgb(250, 250, 252) } $script:Colors = $DarkTheme # ============================= # GLOBAL TOOLTIP # ============================= $script:tooltip = New-Object System.Windows.Forms.ToolTip $script:tooltip.AutoPopDelay = 5000 $script:tooltip.InitialDelay = 300 $script:tooltip.ReshowDelay = 100 $script:tooltip.ShowAlways = $true $script:tooltip.IsBalloon = $false # ============================= # CUSTOM DIALOG FUNCTIONS # ============================= function Show-CustomDialog { param( [string]$Title, [string]$Message, [array]$Buttons = @("OK"), [string]$DefaultButton = "OK", $ParentForm ) try { $dialog = New-Object System.Windows.Forms.Form $dialog.Text = $Title $dialog.Size = New-Object System.Drawing.Size(480, 220) $dialog.StartPosition = "CenterScreen" $dialog.FormBorderStyle = "FixedDialog" $dialog.BackColor = $script:Colors.Surface $dialog.ShowInTaskbar = $false $dialog.MaximizeBox = $false $dialog.MinimizeBox = $false $dialog.KeyPreview = $true # Message panel $messagePanel = New-Object System.Windows.Forms.Panel $messagePanel.Location = New-Object System.Drawing.Point(20, 20) $messagePanel.Size = New-Object System.Drawing.Size(440, 110) $messagePanel.BackColor = $script:Colors.Surface $messageLabel = New-Object System.Windows.Forms.Label $messageLabel.Text = $Message $messageLabel.Dock = "Fill" $messageLabel.Font = New-Object System.Drawing.Font("Segoe UI", 10) $messageLabel.ForeColor = $script:Colors.Text $messageLabel.TextAlign = "MiddleLeft" $messageLabel.Padding = New-Object System.Windows.Forms.Padding(10) $messagePanel.Controls.Add($messageLabel) # Button panel $buttonPanel = New-Object System.Windows.Forms.Panel $buttonPanel.Dock = "Bottom" $buttonPanel.Height = 60 $buttonPanel.BackColor = $script:Colors.Surface $buttonWidth = 100 $buttonSpacing = 10 $totalButtonWidth = ($Buttons.Count * $buttonWidth) + (($Buttons.Count - 1) * $buttonSpacing) $startX = ($dialog.Width - $totalButtonWidth) / 2 $script:dialogResult = $null $firstButton = $null for ($i = 0; $i -lt $Buttons.Count; $i++) { $btn = New-Object System.Windows.Forms.Button $btn.Text = $Buttons[$i] $btn.Size = New-Object System.Drawing.Size($buttonWidth, 36) $btn.Location = New-Object System.Drawing.Point(($startX + ($i * ($buttonWidth + $buttonSpacing))), 12) $btn.FlatStyle = "Flat" $btn.FlatAppearance.BorderSize = 1 $btn.Font = New-Object System.Drawing.Font("Segoe UI", 10) $btn.Cursor = [System.Windows.Forms.Cursors]::Hand $btn.Tag = $Buttons[$i] $btn.TabIndex = $i if ($Buttons[$i] -match "Yes|OK|Confirm|Launch|Run") { $btn.BackColor = $script:Colors.Primary $btn.ForeColor = [System.Drawing.Color]::White $btn.FlatAppearance.BorderColor = $script:Colors.Primary } else { $btn.BackColor = $script:Colors.SurfaceLight $btn.ForeColor = $script:Colors.Text $btn.FlatAppearance.BorderColor = $script:Colors.Border } $btn.Add_Click({ param($sender, $e) $script:dialogResult = $sender.Tag $dialog.Close() }) $btn.Add_MouseEnter({ if ($this.Text -match "Yes|OK|Confirm|Launch|Run") { $this.BackColor = $script:Colors.PrimaryHover } else { $this.BackColor = $script:Colors.SurfaceHover } }) $btn.Add_MouseLeave({ if ($this.Text -match "Yes|OK|Confirm|Launch|Run") { $this.BackColor = $script:Colors.Primary } else { $this.BackColor = $script:Colors.SurfaceLight } }) $buttonPanel.Controls.Add($btn) if ($i -eq 0) { $firstButton = $btn } if ($Buttons[$i] -eq $DefaultButton) { $dialog.AcceptButton = $btn } # Cancel button = Escape key if ($Buttons[$i] -match "Cancel|No") { $dialog.CancelButton = $btn } } # Keyboard navigation $dialog.Add_KeyDown({ param($sender, $e) if ($e.KeyCode -eq "Escape" -and $null -eq $dialog.CancelButton) { $script:dialogResult = "Cancel" $dialog.Close() $e.Handled = $true } }) $dialog.Controls.AddRange(@($buttonPanel, $messagePanel)) # Focus first button $dialog.Add_Shown({ if ($null -ne $firstButton) { $firstButton.Focus() } }) [void]$dialog.ShowDialog($ParentForm) return $script:dialogResult } catch { Write-Error "Dialog error: $_" return $null } } function Show-UtilityDetailsDialog { param($util, $ParentForm) try { if ($null -eq $util) { return $null } $dialog = New-Object System.Windows.Forms.Form $dialog.Text = $util.Name $dialog.Size = New-Object System.Drawing.Size(550, 400) $dialog.StartPosition = "CenterScreen" $dialog.FormBorderStyle = "FixedDialog" $dialog.BackColor = $script:Colors.Surface $dialog.ShowInTaskbar = $false $dialog.MaximizeBox = $false $dialog.MinimizeBox = $false $dialog.KeyPreview = $true # Content $contentPanel = New-Object System.Windows.Forms.Panel $contentPanel.Location = New-Object System.Drawing.Point(30, 20) $contentPanel.Size = New-Object System.Drawing.Size(490, 280) $contentPanel.BackColor = $script:Colors.Surface $yPos = 0 # Name $nameLabel = New-Object System.Windows.Forms.Label $nameLabel.Text = $util.Name $nameLabel.Location = New-Object System.Drawing.Point(0, $yPos) $nameLabel.Size = New-Object System.Drawing.Size(490, 35) $nameLabel.Font = New-Object System.Drawing.Font("Segoe UI", 16, [System.Drawing.FontStyle]::Bold) $nameLabel.ForeColor = $script:Colors.Text $yPos += 45 # Category $categoryLabel = New-Object System.Windows.Forms.Label $categoryLabel.Text = "Category: " + $util.Category $categoryLabel.Location = New-Object System.Drawing.Point(0, $yPos) $categoryLabel.AutoSize = $true $categoryLabel.Font = New-Object System.Drawing.Font("Segoe UI", 9) $categoryLabel.ForeColor = $script:Colors.Primary $yPos += 35 # Description $descHeader = New-Object System.Windows.Forms.Label $descHeader.Text = "Description" $descHeader.Location = New-Object System.Drawing.Point(0, $yPos) $descHeader.Size = New-Object System.Drawing.Size(490, 20) $descHeader.Font = New-Object System.Drawing.Font("Segoe UI", 10, [System.Drawing.FontStyle]::Bold) $descHeader.ForeColor = $script:Colors.Text $descText = New-Object System.Windows.Forms.Label $descText.Text = $util.Desc $descText.Location = New-Object System.Drawing.Point(0, ($yPos + 25)) $descText.Size = New-Object System.Drawing.Size(490, 40) $descText.Font = New-Object System.Drawing.Font("Segoe UI", 9) $descText.ForeColor = $script:Colors.TextSecondary $yPos += 75 # Tags $tagsHeader = New-Object System.Windows.Forms.Label $tagsHeader.Text = "Tags" $tagsHeader.Location = New-Object System.Drawing.Point(0, $yPos) $tagsHeader.Size = New-Object System.Drawing.Size(490, 20) $tagsHeader.Font = New-Object System.Drawing.Font("Segoe UI", 10, [System.Drawing.FontStyle]::Bold) $tagsHeader.ForeColor = $script:Colors.Text $tagsText = New-Object System.Windows.Forms.Label $tagsText.Text = $util.Tags -join ', ' $tagsText.Location = New-Object System.Drawing.Point(0, ($yPos + 25)) $tagsText.Size = New-Object System.Drawing.Size(490, 30) $tagsText.Font = New-Object System.Drawing.Font("Segoe UI", 9) $tagsText.ForeColor = $script:Colors.Primary $yPos += 65 # Link $linkHeader = New-Object System.Windows.Forms.Label $linkHeader.Text = "Source" $linkHeader.Location = New-Object System.Drawing.Point(0, $yPos) $linkHeader.Size = New-Object System.Drawing.Size(490, 20) $linkHeader.Font = New-Object System.Drawing.Font("Segoe UI", 10, [System.Drawing.FontStyle]::Bold) $linkHeader.ForeColor = $script:Colors.Text $linkText = New-Object System.Windows.Forms.Label $linkText.Text = $util.Link $linkText.Location = New-Object System.Drawing.Point(0, ($yPos + 25)) $linkText.Size = New-Object System.Drawing.Size(490, 30) $linkText.Font = New-Object System.Drawing.Font("Segoe UI", 9) $linkText.ForeColor = $script:Colors.TextSecondary $contentPanel.Controls.AddRange(@($nameLabel, $categoryLabel, $descHeader, $descText, $tagsHeader, $tagsText, $linkHeader, $linkText)) # Button panel $buttonPanel = New-Object System.Windows.Forms.Panel $buttonPanel.Dock = "Bottom" $buttonPanel.Height = 70 $buttonPanel.BackColor = $script:Colors.SurfaceLight $runBtn = New-Object System.Windows.Forms.Button $runBtn.Text = "Launch" $runBtn.Size = New-Object System.Drawing.Size(120, 40) $runBtn.Location = New-Object System.Drawing.Point(215, 15) $runBtn.BackColor = $script:Colors.Success $runBtn.ForeColor = [System.Drawing.Color]::White $runBtn.FlatStyle = "Flat" $runBtn.FlatAppearance.BorderSize = 0 $runBtn.Font = New-Object System.Drawing.Font("Segoe UI", 10, [System.Drawing.FontStyle]::Bold) $runBtn.Cursor = [System.Windows.Forms.Cursors]::Hand $runBtn.Add_Click({ $dialog.Tag = "Run"; $dialog.Close() }) $runBtn.Add_MouseEnter({ $this.BackColor = $script:Colors.SuccessHover }) $runBtn.Add_MouseLeave({ $this.BackColor = $script:Colors.Success }) $buttonPanel.Controls.Add($runBtn) $dialog.Controls.AddRange(@($buttonPanel, $contentPanel)) # Keyboard shortcuts $dialog.Add_KeyDown({ param($sender, $e) if ($e.KeyCode -eq "Enter") { $dialog.Tag = "Run" $dialog.Close() $e.Handled = $true } elseif ($e.KeyCode -eq "Escape") { $dialog.Close() $e.Handled = $true } }) [void]$dialog.ShowDialog($ParentForm) return $dialog.Tag } catch { Write-Error "Details dialog error: $_" return $null } } # ============================= # THEME TOGGLE # ============================= function Toggle-Theme { if ($script:CurrentTheme -eq "Dark") { $script:CurrentTheme = "Light" $script:Colors = $LightTheme } else { $script:CurrentTheme = "Dark" $script:Colors = $DarkTheme } Apply-Theme } function Apply-Theme { try { # Main form $script:mainForm.BackColor = $script:Colors.Background # Header $headerPanel.BackColor = $script:Colors.Surface $titleLabel.ForeColor = $script:Colors.Text $subtitleLabel.ForeColor = $script:Colors.TextSecondary # Search $searchContainer.BackColor = $script:Colors.SearchBox $script:searchBox.BackColor = $script:Colors.SearchBox $script:searchBox.ForeColor = $script:Colors.Text # Buttons $clearBtn.BackColor = $script:Colors.SurfaceLight $clearBtn.ForeColor = $script:Colors.TextSecondary $refreshBtn.BackColor = $script:Colors.SurfaceLight $refreshBtn.ForeColor = $script:Colors.Primary $themeBtn.BackColor = $script:Colors.SurfaceLight $themeBtn.ForeColor = $script:Colors.Text # Utilities panel $script:utilitiesPanel.BackColor = $script:Colors.Background # Status bar $statusBar.BackColor = $script:Colors.Surface $script:statusLabel.ForeColor = $script:Colors.Text $versionLabel.ForeColor = $script:Colors.Primary # Redraw utilities Update-UtilityDisplay } catch { Write-Warning "Theme apply error: $_" } } # ============================= # HELPER FUNCTIONS # ============================= function Add-Tooltip { param($control, $text) try { if ($null -ne $control -and $null -ne $script:tooltip) { $script:tooltip.SetToolTip($control, $text) } } catch { Write-Warning "Tooltip error: $_" } } function Update-StatusBar { param([string]$Message) try { if ($null -ne $script:statusLabel) { $script:statusLabel.Text = $Message } } catch { } } function Create-UtilityCard { param($util, $containerWidth) try { if ($null -eq $util) { return $null } $cardWidth = [Math]::Max(400, $containerWidth - 60) $cardHeight = 90 $card = New-Object System.Windows.Forms.Panel $card.Size = New-Object System.Drawing.Size($cardWidth, $cardHeight) $card.BackColor = $script:Colors.Surface $card.Tag = $util $card.Cursor = [System.Windows.Forms.Cursors]::Hand $card.Anchor = "Top,Left,Right" $card.BorderStyle = "FixedSingle" # Title $titleLabel = New-Object System.Windows.Forms.Label $titleLabel.Text = $util.Name $titleLabel.Location = New-Object System.Drawing.Point(20, 15) $titleLabel.Size = New-Object System.Drawing.Size(($cardWidth - 180), 24) $titleLabel.Font = New-Object System.Drawing.Font("Segoe UI", 12, [System.Drawing.FontStyle]::Bold) $titleLabel.ForeColor = $script:Colors.Text $titleLabel.BackColor = [System.Drawing.Color]::Transparent $titleLabel.Anchor = "Top,Left,Right" Add-Tooltip -control $titleLabel -text "Click to view details" # Description $descLabel = New-Object System.Windows.Forms.Label $descLabel.Text = $util.Desc $descLabel.Location = New-Object System.Drawing.Point(20, 42) $descLabel.Size = New-Object System.Drawing.Size(($cardWidth - 180), 18) $descLabel.Font = New-Object System.Drawing.Font("Segoe UI", 9) $descLabel.ForeColor = $script:Colors.TextSecondary $descLabel.BackColor = [System.Drawing.Color]::Transparent $descLabel.Anchor = "Top,Left,Right" # Category $categoryLabel = New-Object System.Windows.Forms.Label $categoryLabel.Text = $util.Category $categoryLabel.Location = New-Object System.Drawing.Point(20, 63) $categoryLabel.AutoSize = $true $categoryLabel.Font = New-Object System.Drawing.Font("Segoe UI", 8) $categoryLabel.ForeColor = $script:Colors.Primary $categoryLabel.BackColor = [System.Drawing.Color]::Transparent # Run button $runBtn = New-Object System.Windows.Forms.Button $runBtn.Text = "Run" $runBtn.Size = New-Object System.Drawing.Size(90, 35) $runBtn.Location = New-Object System.Drawing.Point(($cardWidth - 115), 28) $runBtn.BackColor = $script:Colors.Primary $runBtn.ForeColor = [System.Drawing.Color]::White $runBtn.FlatStyle = "Flat" $runBtn.FlatAppearance.BorderSize = 0 $runBtn.Font = New-Object System.Drawing.Font("Segoe UI", 9, [System.Drawing.FontStyle]::Bold) $runBtn.Cursor = [System.Windows.Forms.Cursors]::Hand $runBtn.Anchor = "Top,Right" Add-Tooltip -control $runBtn -text "Launch $($util.Name)" $runBtn.Add_Click({ param($sender, $e) try { $utilData = $sender.Parent.Tag if ($null -eq $utilData) { return } $result = Show-CustomDialog ` -Title "Launch Utility" ` -Message "Launch $($utilData.Name)?`n`n$($utilData.Desc)" ` -Buttons @("Launch", "Cancel") ` -DefaultButton "Launch" ` -ParentForm $script:mainForm if ($result -eq "Launch") { # Disable button and show launching state $sender.Enabled = $false $sender.Text = "Launching..." $sender.BackColor = $script:Colors.TextSecondary try { Write-Host "" Write-Host "=====================================" -ForegroundColor Cyan Write-Host "LAUNCHING: $($utilData.Name)" -ForegroundColor Yellow Write-Host "=====================================" -ForegroundColor Cyan Write-Host "Description: $($utilData.Desc)" -ForegroundColor Gray Write-Host "Source: $($utilData.Link)" -ForegroundColor Gray Write-Host "" Write-Host "Status: Initiating..." -ForegroundColor Yellow Update-StatusBar "Launching $($utilData.Name)..." # Launch utility Write-Host "Status: Downloading script..." -ForegroundColor Yellow $scriptContent = irm $utilData.Link Write-Host "Status: Executing..." -ForegroundColor Yellow Start-Job -ScriptBlock { param($script) Invoke-Expression $script } -ArgumentList $scriptContent | Out-Null Write-Host "Status: Launched successfully!" -ForegroundColor Green Write-Host "=====================================" -ForegroundColor Cyan Write-Host "" Update-StatusBar "Launched: $($utilData.Name)" # Re-enable button after short delay $timer = New-Object System.Windows.Forms.Timer $timer.Interval = 1500 $timer.Tag = $sender $timer.Add_Tick({ param($s, $ev) $btn = $s.Tag $btn.Enabled = $true $btn.Text = "Run" $btn.BackColor = $script:Colors.Primary $s.Stop() $s.Dispose() }) $timer.Start() } catch { Write-Host "Status: FAILED!" -ForegroundColor Red Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red Write-Host "=====================================" -ForegroundColor Cyan Write-Host "" Update-StatusBar "Failed to launch: $($utilData.Name)" # Re-enable button $sender.Enabled = $true $sender.Text = "Run" $sender.BackColor = $script:Colors.Primary Show-CustomDialog ` -Title "Launch Error" ` -Message "Failed to launch $($utilData.Name):`n`n$($_.Exception.Message)" ` -Buttons @("OK") ` -ParentForm $script:mainForm } } } catch { Write-Error "Run button error: $_" } }) $card.Add_Click({ try { $utilData = $this.Tag if ($null -eq $utilData) { return } $result = Show-UtilityDetailsDialog -util $utilData -ParentForm $script:mainForm if ($result -eq "Run") { foreach ($ctrl in $this.Controls) { if ($ctrl -is [System.Windows.Forms.Button] -and $ctrl.Text -eq "Run") { $ctrl.PerformClick() break } } } } catch { Write-Error "Card click error: $_" } }) $card.Add_MouseEnter({ $this.BackColor = $script:Colors.SurfaceHover }) $card.Add_MouseLeave({ $this.BackColor = $script:Colors.Surface }) $runBtn.Add_MouseEnter({ if ($this.Enabled) { $this.BackColor = $script:Colors.PrimaryHover } }) $runBtn.Add_MouseLeave({ if ($this.Enabled) { $this.BackColor = $script:Colors.Primary } }) $card.Controls.AddRange(@($titleLabel, $descLabel, $categoryLabel, $runBtn)) return $card } catch { Write-Error "Card creation error: $_" return $null } } # ============================= # CREATE MAIN FORM # ============================= $script:mainForm = New-Object System.Windows.Forms.Form $script:mainForm.Text = "Nahid Power Utilities" $script:mainForm.StartPosition = "Manual" $script:mainForm.WindowState = "Maximized" $script:mainForm.BackColor = $script:Colors.Background $script:mainForm.FormBorderStyle = "Sizable" $script:mainForm.MinimumSize = New-Object System.Drawing.Size(700, 550) $script:mainForm.KeyPreview = $true # ============================= # HEADER PANEL # ============================= $headerPanel = New-Object System.Windows.Forms.Panel $headerPanel.Dock = "Top" $headerPanel.Height = 130 $headerPanel.BackColor = $script:Colors.Surface $titleLabel = New-Object System.Windows.Forms.Label $titleLabel.Text = "Nahid Power Utilities" $titleLabel.Location = New-Object System.Drawing.Point(30, 20) $titleLabel.AutoSize = $true $titleLabel.Font = New-Object System.Drawing.Font("Segoe UI", 20, [System.Drawing.FontStyle]::Bold) $titleLabel.ForeColor = $script:Colors.Text Add-Tooltip -control $titleLabel -text "Dashboard v3.0" $subtitleLabel = New-Object System.Windows.Forms.Label $subtitleLabel.Text = "Your productivity toolkit" $subtitleLabel.Location = New-Object System.Drawing.Point(30, 55) $subtitleLabel.AutoSize = $true $subtitleLabel.Font = New-Object System.Drawing.Font("Segoe UI", 10) $subtitleLabel.ForeColor = $script:Colors.TextSecondary # Search container $searchContainer = New-Object System.Windows.Forms.Panel $searchContainer.Location = New-Object System.Drawing.Point(25, 85) $searchContainer.Size = New-Object System.Drawing.Size(($headerPanel.Width - 250), 35) $searchContainer.BackColor = $script:Colors.SearchBox $searchContainer.Anchor = "Top,Left,Right" $searchContainer.BorderStyle = "FixedSingle" $searchIcon = New-Object System.Windows.Forms.Label $searchIcon.Text = "Search" $searchIcon.Location = New-Object System.Drawing.Point(10, 8) $searchIcon.Size = New-Object System.Drawing.Size(45, 20) $searchIcon.Font = New-Object System.Drawing.Font("Segoe UI", 9) $searchIcon.ForeColor = $script:Colors.TextSecondary $script:searchBox = New-Object System.Windows.Forms.TextBox $script:searchBox.Location = New-Object System.Drawing.Point(60, 7) $script:searchBox.Size = New-Object System.Drawing.Size(($searchContainer.Width - 70), 22) $script:searchBox.Font = New-Object System.Drawing.Font("Segoe UI", 10) $script:searchBox.BackColor = $script:Colors.SearchBox $script:searchBox.ForeColor = $script:Colors.Text $script:searchBox.BorderStyle = "None" $script:searchBox.Anchor = "Top,Left,Right" Add-Tooltip -control $script:searchBox -text "Search utilities (Press / to focus)" $searchContainer.Controls.AddRange(@($searchIcon, $script:searchBox)) # Theme button $themeBtn = New-Object System.Windows.Forms.Button $themeBtn.Text = "Theme" $themeBtn.Size = New-Object System.Drawing.Size(60, 35) $themeBtn.Location = New-Object System.Drawing.Point(($headerPanel.Width - 210), 85) $themeBtn.BackColor = $script:Colors.SurfaceLight $themeBtn.ForeColor = $script:Colors.Text $themeBtn.FlatStyle = "Flat" $themeBtn.FlatAppearance.BorderSize = 0 $themeBtn.Font = New-Object System.Drawing.Font("Segoe UI", 9) $themeBtn.Cursor = [System.Windows.Forms.Cursors]::Hand $themeBtn.Anchor = "Top,Right" Add-Tooltip -control $themeBtn -text "Toggle dark/light mode (Ctrl+T)" $themeBtn.Add_Click({ Toggle-Theme }) $themeBtn.Add_MouseEnter({ $this.BackColor = $script:Colors.SurfaceHover }) $themeBtn.Add_MouseLeave({ $this.BackColor = $script:Colors.SurfaceLight }) # Clear button $clearBtn = New-Object System.Windows.Forms.Button $clearBtn.Text = "Clear" $clearBtn.Size = New-Object System.Drawing.Size(60, 35) $clearBtn.Location = New-Object System.Drawing.Point(($headerPanel.Width - 140), 85) $clearBtn.BackColor = $script:Colors.SurfaceLight $clearBtn.ForeColor = $script:Colors.TextSecondary $clearBtn.FlatStyle = "Flat" $clearBtn.FlatAppearance.BorderSize = 0 $clearBtn.Font = New-Object System.Drawing.Font("Segoe UI", 9) $clearBtn.Cursor = [System.Windows.Forms.Cursors]::Hand $clearBtn.Anchor = "Top,Right" Add-Tooltip -control $clearBtn -text "Clear search (Esc)" $clearBtn.Add_Click({ $script:searchBox.Text = "" $script:searchBox.Focus() Update-UtilityDisplay }) $clearBtn.Add_MouseEnter({ $this.BackColor = $script:Colors.Danger; $this.ForeColor = [System.Drawing.Color]::White }) $clearBtn.Add_MouseLeave({ $this.BackColor = $script:Colors.SurfaceLight; $this.ForeColor = $script:Colors.TextSecondary }) # Refresh button $refreshBtn = New-Object System.Windows.Forms.Button $refreshBtn.Text = "Refresh" $refreshBtn.Size = New-Object System.Drawing.Size(60, 35) $refreshBtn.Location = New-Object System.Drawing.Point(($headerPanel.Width - 70), 85) $refreshBtn.BackColor = $script:Colors.SurfaceLight $refreshBtn.ForeColor = $script:Colors.Primary $refreshBtn.FlatStyle = "Flat" $refreshBtn.FlatAppearance.BorderSize = 0 $refreshBtn.Font = New-Object System.Drawing.Font("Segoe UI", 9) $refreshBtn.Cursor = [System.Windows.Forms.Cursors]::Hand $refreshBtn.Anchor = "Top,Right" Add-Tooltip -control $refreshBtn -text "Refresh (F5)" $refreshBtn.Add_Click({ Update-UtilityDisplay Update-StatusBar "Refreshed" }) $refreshBtn.Add_MouseEnter({ $this.BackColor = $script:Colors.Primary; $this.ForeColor = [System.Drawing.Color]::White }) $refreshBtn.Add_MouseLeave({ $this.BackColor = $script:Colors.SurfaceLight; $this.ForeColor = $script:Colors.Primary }) $headerPanel.Controls.AddRange(@($titleLabel, $subtitleLabel, $searchContainer, $themeBtn, $clearBtn, $refreshBtn)) # ============================= # UTILITIES CONTAINER # ============================= $script:utilitiesPanel = New-Object System.Windows.Forms.Panel $script:utilitiesPanel.Dock = "Fill" $script:utilitiesPanel.AutoScroll = $true $script:utilitiesPanel.BackColor = $script:Colors.Background $script:utilitiesPanel.Padding = New-Object System.Windows.Forms.Padding(25) # ============================= # STATUS BAR # ============================= $statusBar = New-Object System.Windows.Forms.StatusStrip $statusBar.BackColor = $script:Colors.Surface $statusBar.Dock = "Bottom" $script:statusLabel = New-Object System.Windows.Forms.ToolStripStatusLabel $script:statusLabel.Text = "Ready | Total: $($script:ValidatedUtilities.Count) utilities" $script:statusLabel.ForeColor = $script:Colors.Text $script:statusLabel.Spring = $true $script:statusLabel.Font = New-Object System.Drawing.Font("Segoe UI", 9) $versionLabel = New-Object System.Windows.Forms.ToolStripStatusLabel $versionLabel.Text = "v3.0" $versionLabel.ForeColor = $script:Colors.Primary $versionLabel.Font = New-Object System.Drawing.Font("Segoe UI", 9, [System.Drawing.FontStyle]::Bold) $statusBar.Items.AddRange(@($script:statusLabel, $versionLabel)) | Out-Null # ============================= # UPDATE DISPLAY FUNCTION # ============================= function Update-UtilityDisplay { param( [string]$searchText = "" ) try { $script:utilitiesPanel.Controls.Clear() $filtered = $script:ValidatedUtilities if ($searchText -eq "") { $searchText = $script:searchBox.Text } if ($searchText -ne "") { $filtered = $filtered | Where-Object { $_.Name -like "*$searchText*" -or $_.Desc -like "*$searchText*" -or $_.Category -like "*$searchText*" -or ($_.Tags | Where-Object { $_ -like "*$searchText*" }).Count -gt 0 } } # Header $countPanel = New-Object System.Windows.Forms.Panel $countPanel.Height = 40 $countPanel.Width = $script:utilitiesPanel.Width - 50 $countPanel.BackColor = [System.Drawing.Color]::Transparent $countPanel.Anchor = "Top,Left,Right" $countLabel = New-Object System.Windows.Forms.Label $countLabel.Text = "Showing $($filtered.Count) utilities" $countLabel.Location = New-Object System.Drawing.Point(10, 10) $countLabel.AutoSize = $true $countLabel.Font = New-Object System.Drawing.Font("Segoe UI", 10, [System.Drawing.FontStyle]::Bold) $countLabel.ForeColor = $script:Colors.Text $countPanel.Controls.Add($countLabel) $script:utilitiesPanel.Controls.Add($countPanel) $yPos = 50 $cardSpacing = 15 foreach ($util in $filtered) { $card = Create-UtilityCard -util $util -containerWidth $script:utilitiesPanel.ClientSize.Width if ($null -ne $card) { $card.Location = New-Object System.Drawing.Point(15, $yPos) $script:utilitiesPanel.Controls.Add($card) $yPos += $card.Height + $cardSpacing } } if ($filtered.Count -eq 0) { $noResultsPanel = New-Object System.Windows.Forms.Panel $noResultsPanel.Size = New-Object System.Drawing.Size(($script:utilitiesPanel.Width - 50), 180) $noResultsPanel.Location = New-Object System.Drawing.Point(25, 60) $noResultsPanel.BackColor = $script:Colors.Surface $noResultsPanel.Anchor = "Top,Left,Right" $noResultsLabel = New-Object System.Windows.Forms.Label $noResultsLabel.Text = "No utilities found" $noResultsLabel.Size = New-Object System.Drawing.Size($noResultsPanel.Width, 35) $noResultsLabel.Location = New-Object System.Drawing.Point(0, 60) $noResultsLabel.Font = New-Object System.Drawing.Font("Segoe UI", 14, [System.Drawing.FontStyle]::Bold) $noResultsLabel.ForeColor = $script:Colors.Text $noResultsLabel.TextAlign = "MiddleCenter" $noResultsDesc = New-Object System.Windows.Forms.Label $noResultsDesc.Text = "Try different search terms" $noResultsDesc.Size = New-Object System.Drawing.Size($noResultsPanel.Width, 25) $noResultsDesc.Location = New-Object System.Drawing.Point(0, 100) $noResultsDesc.Font = New-Object System.Drawing.Font("Segoe UI", 10) $noResultsDesc.ForeColor = $script:Colors.TextSecondary $noResultsDesc.TextAlign = "MiddleCenter" $noResultsPanel.Controls.AddRange(@($noResultsLabel, $noResultsDesc)) $script:utilitiesPanel.Controls.Add($noResultsPanel) } Update-StatusBar "Showing $($filtered.Count) of $($script:ValidatedUtilities.Count) utilities" } catch { Write-Error "Display update error: $_" } } # ============================= # EVENT HANDLERS # ============================= $script:mainForm.Add_Resize({ try { Update-UtilityDisplay $searchContainer.Width = $headerPanel.Width - 250 $script:searchBox.Width = $searchContainer.Width - 70 $themeBtn.Left = $headerPanel.Width - 210 $clearBtn.Left = $headerPanel.Width - 140 $refreshBtn.Left = $headerPanel.Width - 70 } catch { Write-Warning "Resize error: $_" } }) $script:searchBox.Add_TextChanged({ try { Update-UtilityDisplay } catch { Write-Warning "Search error: $_" } }) # Global keyboard shortcuts $script:mainForm.Add_KeyDown({ param($sender, $e) # / = Focus search if ($e.KeyCode -eq "OemQuestion" -or $e.KeyCode -eq "Divide") { $script:searchBox.Focus() $script:searchBox.SelectAll() $e.Handled = $true } # Ctrl+F = Focus search if ($e.Control -and $e.KeyCode -eq "F") { $script:searchBox.Focus() $script:searchBox.SelectAll() $e.Handled = $true } # Escape = Clear search if ($e.KeyCode -eq "Escape") { if ($script:searchBox.Text -ne "") { $script:searchBox.Text = "" } $e.Handled = $true } # F5 = Refresh if ($e.KeyCode -eq "F5") { Update-UtilityDisplay Update-StatusBar "Refreshed" $e.Handled = $true } # Ctrl+T = Toggle theme if ($e.Control -and $e.KeyCode -eq "T") { Toggle-Theme $e.Handled = $true } }) # ============================= # ASSEMBLE & SHOW # ============================= $script:mainForm.Controls.AddRange(@($statusBar, $script:utilitiesPanel, $headerPanel)) Update-UtilityDisplay Write-Host "" Write-Host "================================================" -ForegroundColor Cyan Write-Host " Nahid Power Utilities Dashboard v3.0 " -ForegroundColor Cyan Write-Host "================================================" -ForegroundColor Cyan Write-Host "" Write-Host "Loaded: $($script:ValidatedUtilities.Count) utilities" -ForegroundColor Green Write-Host "" Write-Host "Features:" -ForegroundColor Yellow Write-Host " - Maximized window for better view" -ForegroundColor Gray Write-Host " - Simplified interface (no category filters)" -ForegroundColor Gray Write-Host " - Search-focused workflow" -ForegroundColor Gray Write-Host " - Dark/Light theme toggle" -ForegroundColor Gray Write-Host " - Keyboard shortcuts" -ForegroundColor Gray Write-Host "" Write-Host "Shortcuts:" -ForegroundColor Yellow Write-Host " / or Ctrl+F : Focus search" -ForegroundColor Gray Write-Host " Esc : Clear search" -ForegroundColor Gray Write-Host " F5 : Refresh" -ForegroundColor Gray Write-Host " Ctrl+T : Toggle theme" -ForegroundColor Gray Write-Host "" try { [void]$script:mainForm.ShowDialog() } catch { Write-Error "Application error: $_" } |