*
This commit is contained in:
parent
4990c6d26a
commit
9830065f5c
4 changed files with 50 additions and 21 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,2 +1,4 @@
|
||||||
/nanite
|
/nanite
|
||||||
/exp/
|
/exp/
|
||||||
|
/.envrc
|
||||||
|
/result
|
||||||
|
|
|
||||||
2
event.go
2
event.go
|
|
@ -96,8 +96,10 @@ func (_ HangupEvent) HandleOutgoing(app *App) error {
|
||||||
app.conn.stop()
|
app.conn.stop()
|
||||||
app.conn.Write([]byte("QUIT\n"))
|
app.conn.Write([]byte("QUIT\n"))
|
||||||
app.conn.Close()
|
app.conn.Close()
|
||||||
|
if app.conn.ticker != nil {
|
||||||
app.conn.ticker.Stop()
|
app.conn.ticker.Stop()
|
||||||
app.conn.ticker = nil
|
app.conn.ticker = nil
|
||||||
|
}
|
||||||
app.conn = nil
|
app.conn = nil
|
||||||
app.incoming <- HangupEvent{host, port}
|
app.incoming <- HangupEvent{host, port}
|
||||||
|
|
||||||
|
|
|
||||||
55
main.go
55
main.go
|
|
@ -102,6 +102,41 @@ func (app *App) EnsureConfigDir() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *App) Error(err error) {
|
||||||
|
if app.conn != nil {
|
||||||
|
host := app.conn.host
|
||||||
|
port := app.conn.port
|
||||||
|
app.conn.stop()
|
||||||
|
app.conn.Close()
|
||||||
|
if app.conn.ticker != nil {
|
||||||
|
app.conn.ticker.Stop()
|
||||||
|
}
|
||||||
|
app.conn = nil
|
||||||
|
app.incoming <- SystemMessageEvent(fmt.Sprintf("disconnected from %s:%s: %v", host, port, err))
|
||||||
|
} else {
|
||||||
|
app.incoming <- SystemMessageEvent(fmt.Sprintf("error: %v", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) Run() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case ev := <-app.outgoing:
|
||||||
|
_, dial := ev.(DialEvent)
|
||||||
|
if dial || app.conn != nil {
|
||||||
|
if err := ev.HandleOutgoing(app); err != nil {
|
||||||
|
app.Error(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
app.incoming <- SystemMessageEvent("not connected to any server")
|
||||||
|
}
|
||||||
|
case <-app.ctx.Done():
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NewApp() *App {
|
func NewApp() *App {
|
||||||
app := &App{}
|
app := &App{}
|
||||||
app.ctx, app.stop = context.WithCancel(context.Background())
|
app.ctx, app.stop = context.WithCancel(context.Background())
|
||||||
|
|
@ -117,25 +152,7 @@ func NewApp() *App {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go app.Run()
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case ev := <-app.outgoing:
|
|
||||||
_, dial := ev.(DialEvent)
|
|
||||||
if dial || app.conn != nil {
|
|
||||||
if err := ev.HandleOutgoing(app); err != nil {
|
|
||||||
app.error <- err
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
app.incoming <- SystemMessageEvent("not connected to any server")
|
|
||||||
}
|
|
||||||
case <-app.ctx.Done():
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
app.InitUI()
|
app.InitUI()
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
|
||||||
8
shell.nix
Normal file
8
shell.nix
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
{ pkgs ? import <nixpkgs> {} }:
|
||||||
|
|
||||||
|
pkgs.mkShell {
|
||||||
|
buildInputs = [
|
||||||
|
pkgs.go
|
||||||
|
pkgs.gopls
|
||||||
|
];
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue