mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Add full support for multiple app instances via the AppManager.
Still to do: * Config support for multiple apps/multiple config files * The ability to switch between apps Signed-off-by: Chris Cummer <chriscummer@me.com>
This commit is contained in:
parent
23dc1c5058
commit
cf6d2fc061
@ -1,6 +1,11 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import "errors"
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/olebedev/config"
|
||||||
|
"github.com/rivo/tview"
|
||||||
|
)
|
||||||
|
|
||||||
// WtfAppManager handles the instances of WtfApp, ensuring that they're displayed as requested
|
// WtfAppManager handles the instances of WtfApp, ensuring that they're displayed as requested
|
||||||
type WtfAppManager struct {
|
type WtfAppManager struct {
|
||||||
@ -13,13 +18,19 @@ type WtfAppManager struct {
|
|||||||
func NewAppManager() WtfAppManager {
|
func NewAppManager() WtfAppManager {
|
||||||
appMan := WtfAppManager{
|
appMan := WtfAppManager{
|
||||||
WtfApps: []*WtfApp{},
|
WtfApps: []*WtfApp{},
|
||||||
|
|
||||||
selected: 0,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return appMan
|
return appMan
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MakeNewWtfApp creates and starts a new instance of WtfApp from a set of configuration params
|
||||||
|
func (appMan *WtfAppManager) MakeNewWtfApp(config *config.Config, configFilePath string) {
|
||||||
|
wtfApp := NewWtfApp(tview.NewApplication(), config, configFilePath)
|
||||||
|
appMan.Add(wtfApp)
|
||||||
|
|
||||||
|
wtfApp.Start()
|
||||||
|
}
|
||||||
|
|
||||||
// Add adds a WtfApp to the collection of apps that the AppManager manages.
|
// Add adds a WtfApp to the collection of apps that the AppManager manages.
|
||||||
// This app is then available for display onscreen.
|
// This app is then available for display onscreen.
|
||||||
func (appMan *WtfAppManager) Add(wtfApp *WtfApp) {
|
func (appMan *WtfAppManager) Add(wtfApp *WtfApp) {
|
||||||
@ -28,7 +39,7 @@ func (appMan *WtfAppManager) Add(wtfApp *WtfApp) {
|
|||||||
|
|
||||||
// Current returns the currently-displaying instance of WtfApp
|
// Current returns the currently-displaying instance of WtfApp
|
||||||
func (appMan *WtfAppManager) Current() (*WtfApp, error) {
|
func (appMan *WtfAppManager) Current() (*WtfApp, error) {
|
||||||
if appMan.selected < 0 || appMan.selected > (len(appMan.WtfApps)-1) {
|
if appMan.selected < 0 || appMan.selected >= len(appMan.WtfApps) {
|
||||||
return nil, errors.New("invalid app index selected")
|
return nil, errors.New("invalid app index selected")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,6 +50,7 @@ func (appMan *WtfAppManager) Current() (*WtfApp, error) {
|
|||||||
// the current one. If there are none after the current one, it wraps around.
|
// the current one. If there are none after the current one, it wraps around.
|
||||||
func (appMan *WtfAppManager) Next() (*WtfApp, error) {
|
func (appMan *WtfAppManager) Next() (*WtfApp, error) {
|
||||||
appMan.selected++
|
appMan.selected++
|
||||||
|
|
||||||
if appMan.selected >= len(appMan.WtfApps) {
|
if appMan.selected >= len(appMan.WtfApps) {
|
||||||
appMan.selected = 0
|
appMan.selected = 0
|
||||||
}
|
}
|
||||||
@ -50,6 +62,7 @@ func (appMan *WtfAppManager) Next() (*WtfApp, error) {
|
|||||||
// list the current one. If there are none before the current one, it wraps around.
|
// list the current one. If there are none before the current one, it wraps around.
|
||||||
func (appMan *WtfAppManager) Prev() (*WtfApp, error) {
|
func (appMan *WtfAppManager) Prev() (*WtfApp, error) {
|
||||||
appMan.selected--
|
appMan.selected--
|
||||||
|
|
||||||
if appMan.selected < 0 {
|
if appMan.selected < 0 {
|
||||||
appMan.selected = len(appMan.WtfApps) - 1
|
appMan.selected = len(appMan.WtfApps) - 1
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,8 @@ type WtfApp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewWtfApp creates and returns an instance of WtfApp
|
// NewWtfApp creates and returns an instance of WtfApp
|
||||||
func NewWtfApp(tviewApp *tview.Application, config *config.Config, configFilePath string) WtfApp {
|
func NewWtfApp(tviewApp *tview.Application, config *config.Config, configFilePath string) *WtfApp {
|
||||||
wtfApp := WtfApp{
|
wtfApp := &WtfApp{
|
||||||
TViewApp: tviewApp,
|
TViewApp: tviewApp,
|
||||||
|
|
||||||
config: config,
|
config: config,
|
||||||
@ -86,9 +86,9 @@ func (wtfApp *WtfApp) Run() {
|
|||||||
// Start initializes the app
|
// Start initializes the app
|
||||||
func (wtfApp *WtfApp) Start() {
|
func (wtfApp *WtfApp) Start() {
|
||||||
go wtfApp.scheduleWidgets()
|
go wtfApp.scheduleWidgets()
|
||||||
|
|
||||||
go wtfApp.watchForConfigChanges()
|
go wtfApp.watchForConfigChanges()
|
||||||
|
|
||||||
|
// FIXME: This should be moved to the AppManager
|
||||||
go func() { _ = wtfApp.ghUser.Load() }()
|
go func() { _ = wtfApp.ghUser.Load() }()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
19
main.go
19
main.go
@ -40,13 +40,15 @@ func setTerm(config *config.Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeWtfApp(config *config.Config, flagConfig string) app.WtfApp {
|
// // FIXME: Move this into the AppManager
|
||||||
tviewApp = tview.NewApplication()
|
// panic("BOO")
|
||||||
wtfApp := app.NewWtfApp(tviewApp, config, flagConfig)
|
// func makeWtfApp(config *config.Config, flagConfig string) app.WtfApp {
|
||||||
wtfApp.Start()
|
// tviewApp = tview.NewApplication()
|
||||||
|
// wtfApp := app.NewWtfApp(tviewApp, config, flagConfig)
|
||||||
|
// wtfApp.Start()
|
||||||
|
|
||||||
return wtfApp
|
// return wtfApp
|
||||||
}
|
// }
|
||||||
|
|
||||||
/* -------------------- Main -------------------- */
|
/* -------------------- Main -------------------- */
|
||||||
|
|
||||||
@ -73,11 +75,8 @@ func main() {
|
|||||||
utils.Init(openFileUtil, openURLUtil)
|
utils.Init(openFileUtil, openURLUtil)
|
||||||
|
|
||||||
/* Initialize the App Manager */
|
/* Initialize the App Manager */
|
||||||
|
|
||||||
wtfApp := makeWtfApp(config, flags.Config)
|
|
||||||
|
|
||||||
appMan := app.NewAppManager()
|
appMan := app.NewAppManager()
|
||||||
appMan.Add(&wtfApp)
|
appMan.MakeNewWtfApp(config, flags.Config)
|
||||||
|
|
||||||
currentApp, err := appMan.Current()
|
currentApp, err := appMan.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user