Public/Show-BudgetGUI.ps1
|
function Show-BudgetGUI { <# .SYNOPSIS Launches the graphical user interface for MyBudgetPowerShellModule. .DESCRIPTION The Show-BudgetGUI cmdlet launches a Windows Presentation Foundation (WPF) application that provides a modern Fluent UI interface for managing budgets, billers, earnings, accounts, and transfers. The GUI application uses the MyBudgetPowerShellModule cmdlets to perform all operations, ensuring consistency between command-line and graphical interfaces. .PARAMETER Budget Specifies the budget to open in the GUI. If not specified, the active budget will be used. .PARAMETER DataPath Specifies the path to the budget data directory. If not specified, the default path (~/.mybudget) will be used. .EXAMPLE Show-BudgetGUI Launches the GUI with the currently active budget using the default data path. .EXAMPLE Show-BudgetGUI -Budget "MyPersonalBudget" Launches the GUI and opens the "MyPersonalBudget" budget. .EXAMPLE Show-BudgetGUI -DataPath "C:\CustomBudgetData" Launches the GUI using a custom data path. .NOTES Requires PowerShell 7.2 or later for $PSStyle support. The application is self-contained and bundles all required .NET runtimes. The application will automatically follow the Windows system theme (light/dark mode). .LINK https://github.com/NumidiaLive/MyBudgetPowerShellModule.GUI #> [CmdletBinding()] param( [Parameter()] [string]$Budget, [Parameter()] [string]$DataPath ) begin { Write-Verbose "Starting Budget GUI..." # Verify core module is imported if (-not (Get-Module -Name MyBudgetPowerShellModule)) { try { Import-Module MyBudgetPowerShellModule -ErrorAction Stop Write-Verbose "Core module imported successfully" } catch { throw "Failed to import MyBudgetPowerShellModule. Please ensure it is installed: $_" } } # Get the path to the WPF executable $wpfBinariesPath = Join-Path -Path $PSScriptRoot -ChildPath '..\Private\WPFBinaries' $exePath = Join-Path -Path $wpfBinariesPath -ChildPath 'MyBudget.WPF.exe' # Check if GUI binaries exist if (-not (Test-Path $exePath)) { throw @" GUI application not found at: $exePath The WPF binaries are not installed. This can happen if: 1. The module was not built correctly 2. The binaries were not included during installation Please reinstall the module or build from source using the build.ps1 script. "@ } } process { try { # Get the core module path if loaded $coreModule = Get-Module MyBudgetPowerShellModule # Build arguments for the WPF application $arguments = @() # Pass module path if we have it loaded (for development scenarios) if ($coreModule) { $coreModulePath = $coreModule.ModuleBase Write-Verbose "Core module loaded at: $coreModulePath" $arguments += "--modulepath" $arguments += $coreModulePath } else { Write-Verbose "Core module not pre-loaded - GUI will search standard locations" } if ($Budget) { $arguments += "--budget" $arguments += $Budget } if ($DataPath) { $arguments += "--datapath" $arguments += $DataPath } Write-Verbose "Launching WPF application: $exePath" if ($arguments.Count -gt 0) { Write-Verbose "Arguments: $($arguments -join ' ')" & $exePath $arguments } else { & $exePath } } catch { Write-Error "Failed to launch GUI application: $_" } } end { Write-Verbose "GUI launch completed" } } |