TUI IDE multiplexer?!
golang tui ide
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Use dbus for quit/restart/focus change

kettek 664d67cb defbf30c

+74 -15
+74 -15
app.go
··· 28 28 shellLastFocused bool 29 29 } 30 30 31 + const uiIntro = ` 32 + <node> 33 + <interface name="net.kettek.Aight.UI"> 34 + <method name="ToggleShellFocus"></method> 35 + </interface>` + introspect.IntrospectDataString + ` 36 + </node> 37 + ` 38 + 39 + const appIntro = ` 40 + <node> 41 + <interface name="net.kettek.Aight.App"> 42 + <method name="Quit"></method> 43 + <method name="Restart"></method> 44 + </interface>` + introspect.IntrospectDataString + ` 45 + </node> 46 + ` 47 + 31 48 func NewApp() *App { 32 49 app := &App{ 33 50 Application: *tview.NewApplication(), ··· 40 57 Command: CMD_QUIT, 41 58 }) 42 59 bus.Subscribe(CMD_QUIT, func(v ...any) { 43 - app.Stop() 60 + if err := app.Conn.Object(app.dbusID, dbus.ObjectPath("/app")).Call("Quit", dbus.FlagNoAutoStart, v...).Store(); err != nil { 61 + panic(err) 62 + } 44 63 }) 45 64 46 65 // Hotkey and bus handling for restarting. ··· 50 69 Command: CMD_RESTART, 51 70 }) 52 71 bus.Subscribe(CMD_RESTART, func(v ...any) { 53 - app.Stop() 54 - if err := restartProcess(); err != nil { 72 + if err := app.Conn.Object(app.dbusID, dbus.ObjectPath("/app")).Call("Restart", dbus.FlagNoAutoStart, v...).Store(); err != nil { 55 73 panic(err) 56 74 } 57 75 }) ··· 105 123 Command: CMD_TOGGLE_SHELL_FOCUS, 106 124 }) 107 125 bus.Subscribe(CMD_TOGGLE_SHELL_FOCUS, func(v ...any) { 108 - if app.shellLastFocused { 109 - if err := app.Conn.Object(app.dbusID, dbus.ObjectPath("/panels/editor/active")).Call("SetFocus", dbus.FlagNoAutoStart).Store(); err != nil { 110 - panic(err) 111 - } 112 - } else { 113 - if err := app.Conn.Object(app.dbusID, dbus.ObjectPath("/panels/shell/active")).Call("SetFocus", dbus.FlagNoAutoStart).Store(); err != nil { 114 - panic(err) 115 - } 126 + if err := app.Conn.Object(app.dbusID, dbus.ObjectPath("/ui")).Call("ToggleShellFocus", dbus.FlagNoAutoStart).Store(); err != nil { 127 + panic(err) 116 128 } 117 129 }) 118 130 ··· 174 186 a.env = append(a.env, fmt.Sprintf("EDITOR=%s %s", os.Args[0], "--dbus-send --with-newline --with-focus editor/active :open ")) 175 187 176 188 // Create/run our various components. 177 - if err := a.RunStatus(); err != nil { 189 + if err := a.runStatus(); err != nil { 178 190 return err 179 191 } 180 - if err := a.RunFM(); err != nil { 192 + if err := a.runFM(); err != nil { 181 193 return err 182 194 } 183 195 ··· 198 210 return err 199 211 } 200 212 if err := a.setupMenu(); err != nil { 213 + return err 214 + } 215 + if err := a.exportDBus(); err != nil { 201 216 return err 202 217 } 203 218 ··· 246 261 return nil 247 262 } 248 263 249 - func (a *App) RunStatus() error { 264 + func (a *App) runStatus() error { 250 265 a.status = NewStatus() 251 266 return a.status.AddToConn(a.Conn) 252 267 } 253 268 254 - func (a *App) RunFM() error { 269 + func (a *App) runFM() error { 255 270 a.fm = NewTerm("fm/0", cfg.FileManager) 256 271 257 272 if err := app.Conn.ExportMethodTable(map[string]any{ ··· 279 294 } 280 295 return a.fm.AddToConn(a.Conn) 281 296 } 297 + 298 + func (a *App) exportDBus() error { 299 + // App export 300 + if err := app.Conn.ExportMethodTable(map[string]any{ 301 + "Quit": func() *dbus.Error { 302 + app.Stop() 303 + return nil 304 + }, 305 + "Restart": func() *dbus.Error { 306 + app.Stop() 307 + if err := restartProcess(); err != nil { 308 + panic(err) 309 + } 310 + return nil 311 + }, 312 + }, dbus.ObjectPath("/app"), "net.kettek.Aight.App"); err != nil { 313 + return err 314 + } 315 + if err := app.Conn.Export(introspect.Introspectable(appIntro), dbus.ObjectPath("/app"), "org.freedesktop.DBus.Introspectable"); err != nil { 316 + return err 317 + } 318 + 319 + // UI export 320 + if err := app.Conn.ExportMethodTable(map[string]any{ 321 + "ToggleShellFocus": func() *dbus.Error { 322 + if app.shellLastFocused { 323 + if err := app.Conn.Object(app.dbusID, dbus.ObjectPath("/panels/editor/active")).Call("SetFocus", dbus.FlagNoAutoStart).Store(); err != nil { 324 + return nil 325 + } 326 + } else { 327 + if err := app.Conn.Object(app.dbusID, dbus.ObjectPath("/panels/shell/active")).Call("SetFocus", dbus.FlagNoAutoStart).Store(); err != nil { 328 + return nil 329 + } 330 + } 331 + return nil 332 + }, 333 + }, dbus.ObjectPath("/ui"), "net.kettek.Aight.UI"); err != nil { 334 + return err 335 + } 336 + if err := app.Conn.Export(introspect.Introspectable(uiIntro), dbus.ObjectPath("/ui"), "org.freedesktop.DBus.Introspectable"); err != nil { 337 + return err 338 + } 339 + return nil 340 + }