Skip to content

Commit

Permalink
create appsdir; add simple "test"; protect unexpected client close
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrf committed Jul 4, 2022
1 parent 24e1276 commit 572763b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ VERSION = $(strip $(shell git describe --tags --abbrev=0 --dirty --always))
COMMITHASH = $(strip $(shell git rev-parse --short HEAD))
BUILDTIME = $(strip $(shell date -u +%Y-%m-%dT%H:%M:%SZ))

test: build
./$(APPNAME) set list >/dev/null

build: $(CNAMESFN) $(APPNAME)

$(APPNAME): $(shell find -name '*.go')
Expand Down
4 changes: 3 additions & 1 deletion cmd/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ func ensureWaitRunning(cmd *cobra.Command) error {
return nil
}

sockPath := waitSockPath()
os.Remove(sockPath)

delay := viper.GetDuration("menu.delay")
if delay > time.Second {
log.Debug().Dur("delay", delay).Msg("waiting")
Expand Down Expand Up @@ -187,7 +190,6 @@ func ensureWaitRunning(cmd *cobra.Command) error {

// wait for user to grant permission to run...
const wait = 50 * time.Millisecond
sockPath := waitSockPath()
for timeout := time.Minute; timeout > 0; timeout -= wait {
if subCmdErr != nil {
return subCmdErr
Expand Down
8 changes: 7 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,14 @@ func extractFiles() error {
return err
}

appsDir := filepath.Join(localDataDir, "applications")
err = os.MkdirAll(appsDir, 0755)
if err != nil {
return fmt.Errorf("unable to create %s: %w", appsDir, err)
}

desktopName := buildinfo.App.Name + ".desktop"
desktopPath := filepath.Join(localDataDir, "applications", desktopName)
desktopPath := filepath.Join(appsDir, desktopName)

err = util.Extract(desktopPath, []byte(desktopTemplate), tmplData)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion internal/menu/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ func (m *Menu) Show(ctx context.Context, log *zerolog.Logger, sockPath string) e
m.quitItem = systray.AddMenuItem("Quit", "")

go m.watch()
defer func() { m.client.Close() }() // can't immediately defer m.client.Close since it's not set
// can't immediately defer m.client.Close since it's not set
defer func() {
if m.client != nil {
m.client.Close()
}
}()

if m.PatternName != "" {
_, err := ipc.Send(m.sockpath, "run "+m.PatternName)
Expand Down

0 comments on commit 572763b

Please sign in to comment.