diff --git a/cadMasterCLI.ps1 b/cadMasterCLI.ps1 index 9272428..7b83fb7 100644 --- a/cadMasterCLI.ps1 +++ b/cadMasterCLI.ps1 @@ -8,7 +8,7 @@ $GITEA_ORG = "ScriptPowerShell" # Nom de l'organisation Gitea $GITEA_BRANCH = "main" $LOCAL_CACHE_DIR = "$PSScriptRoot\scripts" -$CADMASTER_VERSION = "2.0.0" +$CADMASTER_VERSION = "2.0.1" $CADMASTER_UPDATE_ORG = "DistechControls" # Organisation Gitea hebergeant cadMasterCLI lui-meme $CADMASTER_UPDATE_REPO = "cadMasterCLI" $CADMASTER_CONFIG_PATH = "$PSScriptRoot\cadmastercli.config.json" @@ -43,6 +43,7 @@ $script:I18N = @{ "detail.switchEnable" = "Activer" "detail.noParams" = "Ce script ne necessite aucun parametre." "detail.noReadme" = "Aucune documentation disponible." + "detail.updateAvailable" = "Mise a jour disponible - cliquer pour installer" "log.header" = "Journal d'execution" "log.placeholder" = "En attente d'execution..." "log.starting" = "Demarrage du script..." @@ -82,6 +83,7 @@ $script:I18N = @{ "detail.switchEnable" = "Enable" "detail.noParams" = "This script does not require any parameters." "detail.noReadme" = "No documentation available." + "detail.updateAvailable" = "Update available - click to install" "log.header" = "Execution log" "log.placeholder" = "Waiting for execution..." "log.starting" = "Starting script..." @@ -570,11 +572,13 @@ function ConvertTo-SimpleHtml { "table{border-collapse:collapse;width:100%;margin:8px 0;font-size:12px}" + "th{background:#1565C0;color:#fff;padding:6px 10px;text-align:left}" + "td{padding:5px 10px;border-bottom:1px solid #eee}" + - "tr:nth-child(even) td{background:#f5f5f5}" + "tr:nth-child(even) td{background:#f5f5f5}" + + "a{color:#1565C0;text-decoration:underline;cursor:pointer}" # Formate gras, italique et code inline sur une chaine deja encodee HTML $applyInline = { param([string]$s) + $s = $s -replace "\[([^\]]+)\]\(([^)\s]+)\)", "`$1" $s = $s -replace "\*\*(.+?)\*\*", "`$1" $s = $s -replace "\*(.+?)\*", "`$1" $s = $s -replace "``(.+?)``", "`$1" @@ -1104,6 +1108,12 @@ function Show-MainWindow { $execState = $execState $grayBrush = $grayBrush $greenBrush = $greenBrush + # Auto-reference (pour le bouton de MAJ du README, qui doit rappeler + # cette meme fonction) : $MyInvocation.MyCommand.ScriptBlock pointe + # sur le scriptblock en cours d'execution, donc pas besoin de passer + # par la variable exterieure $ShowScriptDetail (qui, elle, subirait + # le meme probleme de capture que $lv/$execState ci-dessus). + $selfShowScriptDetail = $MyInvocation.MyCommand.ScriptBlock & $StopRunningExecution $detailHost.ColumnDefinitions.Clear() @@ -1116,6 +1126,8 @@ function Show-MainWindow { Select-Object -First 1 -ExpandProperty FullName $scriptBranch = $ScriptData.DefaultBranch + $justUpdated = $false + if (-not $localPs1) { Write-Log "Telechargement initial de $scriptName..." $ok = Invoke-ScriptDownload -ScriptName $scriptName -Branch $scriptBranch @@ -1125,12 +1137,20 @@ function Show-MainWindow { return } $ScriptData.MajDispo = $false + $justUpdated = $true } - elseif ($ScriptData.MajDispo) { + elseif ($ScriptData.MajDispo -and -not $ScriptData.UpdatePromptShown) { + $ScriptData.UpdatePromptShown = $true $rep = Show-MessageBox -Message "$(T 'msg.updateAvailableScript') '$scriptName'.`n$(T 'msg.updateConfirm')" ` -Title (T "msg.updateAvailableTitle") -Type "Question" - if ($rep -eq "Yes") { Invoke-ScriptDownload -ScriptName $scriptName -Branch $scriptBranch | Out-Null } - $ScriptData.MajDispo = $false + if ($rep -eq "Yes") { + Invoke-ScriptDownload -ScriptName $scriptName -Branch $scriptBranch | Out-Null + $justUpdated = $true + $ScriptData.MajDispo = $false + } + # Si "Non" : MajDispo reste $true (le badge "Nouveau" persiste tant + # que le script n'est pas reellement a jour), mais on ne repropose + # plus le popup pour ce script durant cette session de l'app. } Update-ScriptBadge -ScriptItem $ScriptData @@ -1139,11 +1159,20 @@ function Show-MainWindow { $cachedScriptPath = "$LOCAL_CACHE_DIR\$scriptName\$ps1FileName" # --- README : section langue courante (Feature 6) --- - $readmeContent = $ScriptData.ReadmeFull + # Si l'utilisateur a refuse la mise a jour (ou qu'elle etait deja a + # jour), on affiche le README LOCAL - celui qui correspond reellement + # au code qui sera execute - plutot que la version Gitea la plus + # recente, pour eviter toute confusion entre doc affichee et code lance. $localReadmePath = "$LOCAL_CACHE_DIR\$scriptName\README.md" - if (-not $readmeContent -and (Test-Path $localReadmePath)) { + if (-not $justUpdated -and (Test-Path $localReadmePath)) { $readmeContent = Get-Content $localReadmePath -Raw -Encoding UTF8 } + else { + $readmeContent = $ScriptData.ReadmeFull + if (-not $readmeContent -and (Test-Path $localReadmePath)) { + $readmeContent = Get-Content $localReadmePath -Raw -Encoding UTF8 + } + } $readmeSection = Get-ReadmeSection -Markdown $readmeContent -Lang (Get-CurrentLang) $htmlContent = ConvertTo-SimpleHtml -Markdown $readmeSection @@ -1195,8 +1224,47 @@ function Show-MainWindow { [System.Windows.Controls.Grid]::SetColumn($readmeBorder, 0) $detailHost.Children.Add($readmeBorder) | Out-Null + $readmeDock = New-Object System.Windows.Controls.DockPanel + $readmeBorder.Child = $readmeDock + + $btnScriptUpdate = New-Object System.Windows.Controls.Button + $btnScriptUpdate.Content = T "detail.updateAvailable" + $btnScriptUpdate.Margin = New-Object System.Windows.Thickness(10, 10, 10, 6) + $btnScriptUpdate.Padding = New-Object System.Windows.Thickness(10, 6, 10, 6) + $btnScriptUpdate.Background = New-Object System.Windows.Media.SolidColorBrush([System.Windows.Media.Color]::FromRgb(245, 124, 0)) + $btnScriptUpdate.Foreground = [System.Windows.Media.Brushes]::White + $btnScriptUpdate.FontWeight = [System.Windows.FontWeights]::Bold + $btnScriptUpdate.Cursor = [System.Windows.Input.Cursors]::Hand + $btnScriptUpdate.HorizontalContentAlignment = "Center" + $btnScriptUpdate.Visibility = if ($ScriptData.MajDispo) { [System.Windows.Visibility]::Visible } else { [System.Windows.Visibility]::Collapsed } + [System.Windows.Controls.DockPanel]::SetDock($btnScriptUpdate, [System.Windows.Controls.Dock]::Top) + $readmeDock.Children.Add($btnScriptUpdate) | Out-Null + + $btnScriptUpdate.Add_Click({ + $rep = Show-MessageBox -Message "$(T 'msg.updateAvailableScript') '$scriptName'.`n$(T 'msg.updateConfirm')" ` + -Title (T "msg.updateAvailableTitle") -Type "Question" + if ($rep -eq "Yes") { + Invoke-ScriptDownload -ScriptName $scriptName -Branch $scriptBranch | Out-Null + $ScriptData.MajDispo = $false + Update-ScriptBadge -ScriptItem $ScriptData + & $selfShowScriptDetail -ScriptData $ScriptData + } + }.GetNewClosure()) + $wb = New-Object System.Windows.Controls.WebBrowser - $readmeBorder.Child = $wb + $readmeDock.Children.Add($wb) | Out-Null + + # Un clic sur un lien du README ne doit pas naviguer DANS le petit + # panneau integre (qui perdrait la doc affichee), mais ouvrir le lien + # dans le navigateur par defaut de l'utilisateur. + $wb.Add_Navigating({ + param($sender, $e) + if ($e.Uri -and $e.Uri.IsAbsoluteUri -and ($e.Uri.Scheme -eq "http" -or $e.Uri.Scheme -eq "https")) { + $e.Cancel = $true + Start-Process -FilePath $e.Uri.AbsoluteUri + } + }.GetNewClosure()) + $wb.NavigateToString($htmlContent) $splitter2 = New-Object System.Windows.Controls.GridSplitter @@ -1732,11 +1800,12 @@ $scripts = @($rawList) | ForEach-Object { } [PSCustomObject]@{ - Nom = $name - ReadmeFull = $readme - DateGitea = $date - MajDispo = $majDispo - DefaultBranch = $branch + Nom = $name + ReadmeFull = $readme + DateGitea = $date + MajDispo = $majDispo + DefaultBranch = $branch + UpdatePromptShown = $false } } diff --git a/version.txt b/version.txt index 227cea2..38f77a6 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2.0.0 +2.0.1