From c49140ab364cdb2773e3593dea6cfc72da4f1bb2 Mon Sep 17 00:00:00 2001 From: Provessor Date: Tue, 14 Apr 2020 02:32:42 +1000 Subject: [PATCH] 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 --- app.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app.go b/app.go index 7f79796..06fb18d 100644 --- a/app.go +++ b/app.go @@ -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, } }