v0.7.8 - Bouton Arreter pour annuler les telechargements
Changements : - Bouton Arreter dans la barre de boutons (actif pendant les operations) - Annulation des operations git en cours via context.Context - Detection et affichage du message Annule dans le journal Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
49
gui.go
49
gui.go
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"image"
|
||||
@@ -222,10 +223,13 @@ type App struct {
|
||||
btnRefresh *walk.PushButton
|
||||
btnUpdateAll *walk.PushButton
|
||||
btnAction *walk.PushButton
|
||||
btnStop *walk.PushButton
|
||||
|
||||
reposConfig []RepoConfig
|
||||
suConfig SelfUpdateConfig
|
||||
checking atomic.Bool
|
||||
cancelMu sync.Mutex
|
||||
cancelFunc context.CancelFunc
|
||||
}
|
||||
|
||||
func runApp() error {
|
||||
@@ -327,6 +331,12 @@ func (a *App) buildAndRun() error {
|
||||
Enabled: false,
|
||||
OnClicked: a.doAction,
|
||||
},
|
||||
PushButton{
|
||||
AssignTo: &a.btnStop,
|
||||
Text: "Arrêter",
|
||||
Enabled: false,
|
||||
OnClicked: a.stopOperations,
|
||||
},
|
||||
HSpacer{},
|
||||
PushButton{Text: "config.ini", OnClicked: a.openConfig},
|
||||
PushButton{Text: "Logs", OnClicked: a.openLogs},
|
||||
@@ -540,6 +550,30 @@ func (a *App) makeProgressCB(row int) ProgressCallback {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Annulation ────────────────────────────────────────────────────────────────
|
||||
|
||||
// newCancelCtx crée un nouveau contexte annulable et stocke la fonction cancel.
|
||||
func (a *App) newCancelCtx() context.Context {
|
||||
a.cancelMu.Lock()
|
||||
defer a.cancelMu.Unlock()
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
a.cancelFunc = cancel
|
||||
return ctx
|
||||
}
|
||||
|
||||
// stopOperations annule toutes les opérations git en cours.
|
||||
func (a *App) stopOperations() {
|
||||
a.cancelMu.Lock()
|
||||
fn := a.cancelFunc
|
||||
a.cancelFunc = nil
|
||||
a.cancelMu.Unlock()
|
||||
if fn != nil {
|
||||
fn()
|
||||
a.appendLog("Opérations annulées par l'utilisateur")
|
||||
logInfo("Opérations annulées par l'utilisateur")
|
||||
}
|
||||
}
|
||||
|
||||
// ── Actions dépôt ─────────────────────────────────────────────────────────────
|
||||
|
||||
func (a *App) onSelectionChanged() {
|
||||
@@ -575,22 +609,25 @@ func (a *App) doAction() {
|
||||
}
|
||||
|
||||
a.btnAction.SetEnabled(false)
|
||||
a.btnStop.SetEnabled(true)
|
||||
a.appendLog(fmt.Sprintf("[%s] Mise à jour en cours...", res.Name))
|
||||
|
||||
ctx := a.newCancelCtx()
|
||||
cb := a.makeProgressCB(idx)
|
||||
go func() {
|
||||
var err error
|
||||
if res.NeedsClone {
|
||||
err = doCloneWithProgress(cfg, cb)
|
||||
err = doCloneWithProgress(ctx, cfg, cb)
|
||||
} else {
|
||||
if res.LocalChanges > 0 {
|
||||
err = doCheckout(res)
|
||||
}
|
||||
if err == nil && res.HasUpdate {
|
||||
err = doPullWithProgress(res, cb)
|
||||
err = doPullWithProgress(ctx, res, cb)
|
||||
}
|
||||
}
|
||||
a.mw.Synchronize(func() {
|
||||
a.btnStop.SetEnabled(false)
|
||||
if err != nil {
|
||||
a.model.setProgress(idx, 0, "Erreur")
|
||||
a.appendLog(fmt.Sprintf("[%s] Erreur: %v", res.Name, err))
|
||||
@@ -614,7 +651,9 @@ func (a *App) doAction() {
|
||||
func (a *App) updateAll() {
|
||||
a.btnUpdateAll.SetEnabled(false)
|
||||
a.btnRefresh.SetEnabled(false)
|
||||
a.btnStop.SetEnabled(true)
|
||||
pending := atomic.Int32{}
|
||||
ctx := a.newCancelCtx()
|
||||
|
||||
for i, cfg := range a.reposConfig {
|
||||
res, ok := a.model.getResult(i)
|
||||
@@ -627,13 +666,13 @@ func (a *App) updateAll() {
|
||||
go func() {
|
||||
var err error
|
||||
if res.NeedsClone {
|
||||
err = doCloneWithProgress(cfg, cb)
|
||||
err = doCloneWithProgress(ctx, cfg, cb)
|
||||
} else {
|
||||
if res.LocalChanges > 0 {
|
||||
err = doCheckout(res)
|
||||
}
|
||||
if err == nil && res.HasUpdate {
|
||||
err = doPullWithProgress(res, cb)
|
||||
err = doPullWithProgress(ctx, res, cb)
|
||||
}
|
||||
if err == nil && res.UntrackedFiles > 0 {
|
||||
err = doClean(res)
|
||||
@@ -650,12 +689,14 @@ func (a *App) updateAll() {
|
||||
a.appendLog(fmt.Sprintf("[%s] Mise à jour OK", res.Name))
|
||||
}
|
||||
if pending.Add(-1) == 0 {
|
||||
a.btnStop.SetEnabled(false)
|
||||
a.startCheck()
|
||||
}
|
||||
})
|
||||
}()
|
||||
}
|
||||
if pending.Load() == 0 {
|
||||
a.btnStop.SetEnabled(false)
|
||||
a.startCheck()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user