Skip to content

Commit

Permalink
Auto-open configured group windows at startup
Browse files Browse the repository at this point in the history
A [groups] section is added to the zkclient config file and must
specify 'index = name' pairs for each group name and the window index.

This is handy to keep groupchat windows in a common location across
client restarts.
  • Loading branch information
jrick committed Feb 21, 2021
1 parent f7c967e commit 0debbba
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
22 changes: 22 additions & 0 deletions zkclient/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"path/filepath"
"runtime"
"strconv"
"strings"

"github.com/companyzero/ttk"
Expand Down Expand Up @@ -46,6 +47,9 @@ type Settings struct {
NickColor string
GcColor string
PmColor string

// auto-open groups
OpenGroups []string
}

func textToColor(in string) (int, error) {
Expand Down Expand Up @@ -287,6 +291,24 @@ func ObtainSettings() (*Settings, error) {
s.PmColor = color
}

groups := cfg.Section("groups")
openGroups := make([]string, len(groups))
for window, group := range groups {
n, err := strconv.Atoi(window)
if err != nil {
return nil, fmt.Errorf("groups: %q: %v", group, err)
}
if n <= 0 || n > len(groups)+1 {
return nil, fmt.Errorf("groups: %q: window %d unusable", group, n)
}
g := &openGroups[n-1]
if *g != "" {
return nil, fmt.Errorf("groups: %q: window %d in-use by %q", group, n, *g)
}
*g = group
}
s.OpenGroups = openGroups

return &s, nil
}

Expand Down
7 changes: 7 additions & 0 deletions zkclient/zkclient.conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,12 @@ profiler = 127.0.0.1:6061
nickcolor = bold:na:na
gcothercolor = bold:green:na
pmothercolor = bold:cyan:na
# Joined groups can be auto-opened in a specified order.
# Each key describes the window index, and the value must be the group name.
# Indexes begin at 1 due to index 0 being reserved for the console window.
[groups]
# 1 = firstgroup
# 2 = secondgroup
`
)
18 changes: 10 additions & 8 deletions zkclient/zkclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -975,14 +975,7 @@ func (z *ZKC) goOnline() (*rpc.Welcome, error) {
return nil, err
}

welcome, err := z.welcomePhase(kx)
if err != nil {
return nil, err
}

go z.handleRPC()

return welcome, nil
return z.welcomePhase(kx)
}

//
Expand All @@ -1002,6 +995,15 @@ func (z *ZKC) goOnlineAndPrint() error {
err = z.welcomeUser(welcome)
}

for _, group := range z.settings.OpenGroups {
_, _, err = z.groupConversation(group)
if err != nil {
z.PrintfT(0, "Failed to open group window %q", group)
}
}

go z.handleRPC()

return err
}

Expand Down

0 comments on commit 0debbba

Please sign in to comment.