Properly handle SIGHUP and SIGTERM (#305)

* Properly handle SIGHUP, SIGINT and SIGTERM

* Do not handle SIGINT

* Cancel current copy/move/delete operation

* Better cancel current operation
This commit is contained in:
Provessor 2020-04-14 02:32:42 +10:00 committed by GitHub
parent 933b49d095
commit c49140ab36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

17
app.go
View File

@ -7,6 +7,8 @@ import (
"log"
"os"
"os/exec"
"os/signal"
"syscall"
"path/filepath"
"strings"
"time"
@ -34,11 +36,24 @@ func newApp() *app {
ui := newUI()
nav := newNav(ui.wins[0].h)
quitChan := make(chan bool, 1)
osChan := make(chan os.Signal, 1)
signal.Notify(osChan, os.Interrupt, syscall.SIGHUP, syscall.SIGTERM)
go func() {
<-osChan
nav.copyTotalChan <- -nav.copyTotal
nav.moveTotalChan <- -nav.moveTotal
nav.deleteTotalChan <- -nav.deleteTotal
quitChan <- true
return
}()
return &app{
ui: ui,
nav: nav,
ticker: new(time.Ticker),
quitChan: make(chan bool, 1),
quitChan: quitChan,
}
}