// NewApplet creates a new applet instance. // func NewApplet(base cdtype.AppBase, events *cdtype.Events) cdtype.AppInstance { app := &Applet{AppBase: base, weather: weather.New()} app.SetConfig(&app.conf, app.actions()...) // Events. events.OnClick = app.DialogWeatherCurrent events.OnMiddleClick = app.DialogWeatherCurrent events.OnSubClick = app.DialogWeatherForecast events.OnBuildMenu = func(menu cdtype.Menuer) { var items []int if app.weather.Current() != nil || app.weather.Forecast() != nil { if app.weather.Current() != nil { items = append(items, ActionShowCurrent) } items = append(items, ActionOpenWebpage, ActionRecheckNow) } items = append(items, ActionSetLocation) app.Action().BuildMenu(menu, items) } // Weather polling. app.Poller().Add(app.Check) app.Poller().SetPreCheck(func() { app.SetEmblem(app.FileLocation("img", IconWork), EmblemWork) }) app.Poller().SetPostCheck(func() { app.SetEmblem("none", EmblemWork) }) return app }