Update registrar
This commit is contained in:
parent
a8bc074aad
commit
3a4038dad9
@ -128,8 +128,9 @@ func (role ApplicationRole) Icon () tomo.Icon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunApplication is like tomo.Run, but runs an application. If something fails
|
// RunApplication is like tomo.Run, but runs an application. It automatically
|
||||||
// to initialize, an error is written to the standard logger.
|
// sets up a backend. If something fails to initialize, an error is written to
|
||||||
|
// the standard logger.
|
||||||
func RunApplication (application Application) {
|
func RunApplication (application Application) {
|
||||||
// TODO: see #4
|
// TODO: see #4
|
||||||
|
|
||||||
@ -138,20 +139,20 @@ func RunApplication (application Application) {
|
|||||||
}
|
}
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
err := registrar.RegisterBackend()
|
reg := new(registrar.Registrar)
|
||||||
|
backend, err := reg.SetBackend()
|
||||||
if err != nil { log.Fatalln("nasin: could not register backend:", err) }
|
if err != nil { log.Fatalln("nasin: could not register backend:", err) }
|
||||||
err = tomo.Run(func () {
|
err = reg.SetTheme()
|
||||||
err := registrar.SetTheme()
|
if err != nil { log.Fatalln("nasin: could not set theme:", err) }
|
||||||
if err != nil { log.Fatalln("nasin: could not set theme:", err) }
|
err = reg.SetIconSet()
|
||||||
err = registrar.SetIconSet()
|
if err != nil { log.Fatalln("nasin: could not set icon set:", err) }
|
||||||
if err != nil { log.Fatalln("nasin: could not set icon set:", err) }
|
err = application.Init()
|
||||||
err = application.Init()
|
if err != nil { log.Fatalln("nasin: could not run application:", err) }
|
||||||
if err != nil { log.Fatalln("nasin: could not run application:", err) }
|
|
||||||
|
|
||||||
// open URLs
|
// open URLs
|
||||||
args := flag.Args()
|
args := flag.Args()
|
||||||
applicationOpenUrls(application, args...)
|
applicationOpenUrls(application, args...)
|
||||||
})
|
err = backend.Run()
|
||||||
if err != nil { log.Fatalln("nasin: could not run application:", err) }
|
if err != nil { log.Fatalln("nasin: could not run application:", err) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,19 +11,26 @@ import "git.tebibyte.media/tomo/nasin/internal/style/tss"
|
|||||||
import "git.tebibyte.media/tomo/nasin/internal/icons/fallback"
|
import "git.tebibyte.media/tomo/nasin/internal/icons/fallback"
|
||||||
import "git.tebibyte.media/tomo/nasin/internal/style/fallback"
|
import "git.tebibyte.media/tomo/nasin/internal/style/fallback"
|
||||||
|
|
||||||
func RegisterBackend () error {
|
type Registrar struct {
|
||||||
tomo.Register(1, x.New)
|
backend *x.Backend
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetTheme () error {
|
func (this *Registrar) SetBackend () (tomo.Backend, error) {
|
||||||
|
backend, err := x.New()
|
||||||
|
if err != nil { return nil, err }
|
||||||
|
this.backend = backend.(*x.Backend)
|
||||||
|
tomo.SetBackend(backend)
|
||||||
|
return backend, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Registrar) SetTheme () error {
|
||||||
// TODO eventually get rid of this when we make a file format for
|
// TODO eventually get rid of this when we make a file format for
|
||||||
// storing visual styles
|
// storing visual styles
|
||||||
styleSheetName := os.Getenv("TOMO_STYLE_SHEET")
|
styleSheetName := os.Getenv("TOMO_STYLE_SHEET")
|
||||||
if styleSheetName != "" {
|
if styleSheetName != "" {
|
||||||
styl, _, err := tss.LoadFile(styleSheetName)
|
styl, _, err := tss.LoadFile(styleSheetName)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
tomo.SetStyle(styl)
|
this.backend.SetStyle(styl)
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
log.Printf (
|
log.Printf (
|
||||||
@ -33,11 +40,11 @@ func SetTheme () error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
styl, _ := fallbackStyle.New()
|
styl, _ := fallbackStyle.New()
|
||||||
tomo.SetStyle(styl)
|
this.backend.SetStyle(styl)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetIconSet () error {
|
func (this *Registrar) SetIconSet () error {
|
||||||
iconSet := fallbackIcons.New()
|
iconSet := fallbackIcons.New()
|
||||||
iconSetName := os.Getenv("TOMO_XDG_ICON_THEME")
|
iconSetName := os.Getenv("TOMO_XDG_ICON_THEME")
|
||||||
if iconSetName != "" {
|
if iconSetName != "" {
|
||||||
@ -49,6 +56,6 @@ func SetIconSet () error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tomo.SetIconSet(iconSet)
|
this.backend.SetIconSet(iconSet)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user