summary refs log tree commit diff stats
path: root/aerc.go
diff options
context:
space:
mode:
Diffstat (limited to 'aerc.go')
-rw-r--r--aerc.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/aerc.go b/aerc.go
index 1a32126..e8944d7 100644
--- a/aerc.go
+++ b/aerc.go
@@ -105,13 +105,26 @@ func main() {
 			return
 		}
 	}
+	initDone := make(chan struct{})
 	args := os.Args[optind:]
 	if len(args) > 1 {
 		usage()
 		return
 	} else if len(args) == 1 {
-		lib.ConnectAndExec(args[0])
-		return
+		arg := args[0]
+		err := lib.ConnectAndExec(arg)
+		if err == nil {
+			return // other aerc instance takes over
+		}
+		fmt.Fprintf(os.Stderr, "Failed to communicate to aerc: %v", err)
+		// continue with setting up a new aerc instance and retry after init
+		go func(msg string) {
+			<-initDone
+			err := lib.ConnectAndExec(msg)
+			if err != nil {
+				fmt.Fprintf(os.Stderr, "Failed to communicate to aerc: %v", err)
+			}
+		}(arg)
 	}
 
 	var (
@@ -163,6 +176,8 @@ func main() {
 		as.OnMailto = aerc.Mailto
 	}
 
+	close(initDone)
+
 	for !ui.ShouldExit() {
 		for aerc.Tick() {
 			// Continue updating our internal state