@@ -80,25 +80,13 @@ func LoadInstanceHandler(m MainModel, basePath string, name string) (MainModel,
8080 if r != nil {
8181 ri := r .(RefreshableItem )
8282 cmd := m .List .SetItem (ri .index , item )
83- if ! item .State .Running || item .State .CCCStatus == adapters .CCCReady {
84- m .ItemsToRefresh = funk .Filter (m .ItemsToRefresh , func (e RefreshableItem ) bool {
85- return e .index != ri .index
86- }).([]RefreshableItem )
87- }
8883 if cmd != nil {
8984 return m , cmd
9085 }
9186 return m , nil
9287 }
9388
94- itemIndex := len (m .List .Items ())
95- if item .State .Running && item .State .CCCStatus != adapters .CCCReady {
96- m .ItemsToRefresh = append (m .ItemsToRefresh , RefreshableItem {
97- item : item ,
98- index : itemIndex ,
99- })
100- }
101- m .List .InsertItem (itemIndex , item )
89+ m .List .InsertItem (len (m .List .Items ()), item )
10290 return m , nil
10391}
10492
@@ -150,29 +138,25 @@ func OpenCCCHandler(m MainModel) (MainModel, tea.Cmd) {
150138type RefreshTickMsg time.Time
151139
152140func RefreshTick () tea.Cmd {
153- return tea .Tick (3 * time .Second , func (t time.Time ) tea.Msg {
141+ return tea .Tick (5 * time .Second , func (t time.Time ) tea.Msg {
154142 return RefreshTickMsg (t )
155143 })
156144}
157145
158- // The ReloadItemMsg places the given item in MainModel.ItemsToRefresh
159- type ReloadItemMsg struct {
160- item InstanceItem
161- }
162-
163- func ReloadItem (item InstanceItem ) tea.Msg {
164- return ReloadItemMsg {
165- item : item ,
166- }
167- }
168-
169146// The ReloadItemsMsg triggers reloading all instances
170147type ReloadItemsMsg struct {}
171148
172149func ReloadItems () tea.Msg {
173150 return ReloadItemsMsg {}
174151}
175152
153+ // RestartMsg triggers restarting an instance
154+ type RestartMsg struct {}
155+
156+ func Restart () tea.Msg {
157+ return RestartMsg {}
158+ }
159+
176160// The RunCloudControlMsg triggers running CloudControl
177161type RunCloudControlMsg struct {}
178162
@@ -259,31 +243,16 @@ func Start() tea.Msg {
259243// StartHandler uses adapters.BaseAdapter.StartCloudControl to start an instance
260244func StartHandler (m MainModel ) tea.Cmd {
261245 item := m .List .SelectedItem ().(InstanceItem )
262- return tea .Sequence (
263- DisableList ,
264- tea .ClearScreen ,
265- func () tea.Msg {
266- var cmds []tea.Cmd
267- if ! funk .Contains (m .ItemsToRefresh , func (e RefreshableItem ) bool {
268- return e .item .ID () == item .ID ()
269- }) {
270- cmds = append (cmds , func () tea.Cmd {
271- return func () tea.Msg {
272- return ReloadItem (item )
273- }
274- }())
275- }
276- if err := m .Adapter .StartCloudControl (item .Path , item .Name ); err != nil {
277- cmds = append (cmds , m .List .NewStatusMessage (internal .ErrorMessageStyle (fmt .Sprintf ("Can not start CloudControl: %s" , err .Error ()))))
278- }
279- if cmds != nil {
280- return tea .Batch (cmds ... )()
281- }
282- return nil
283- },
284- tea .ClearScreen ,
285- EnableList ,
286- )
246+ return func () tea.Msg {
247+ var cmds []tea.Cmd
248+ if err := m .Adapter .StartCloudControl (item .Path , item .Name ); err != nil {
249+ cmds = append (cmds , m .List .NewStatusMessage (internal .ErrorMessageStyle (fmt .Sprintf ("Can not start CloudControl: %s" , err .Error ()))))
250+ }
251+ if cmds != nil {
252+ return tea .Batch (cmds ... )()
253+ }
254+ return nil
255+ }
287256}
288257
289258// StopMsg is used to stop an instance.
@@ -296,31 +265,16 @@ func Stop() tea.Msg {
296265// StopHandler uses adapters.BaseAdapter.StopCloudControl to stop an instance.
297266func StopHandler (m MainModel ) tea.Cmd {
298267 item := m .List .SelectedItem ().(InstanceItem )
299- return tea .Sequence (
300- DisableList ,
301- tea .ClearScreen ,
302- func () tea.Msg {
303- var cmds []tea.Cmd
304- if ! funk .Contains (m .ItemsToRefresh , func (e RefreshableItem ) bool {
305- return e .index == m .List .Index ()
306- }) {
307- cmds = append (cmds , func (item InstanceItem ) tea.Cmd {
308- return func () tea.Msg {
309- return ReloadItem (item )
310- }
311- }(item ))
312- }
313- if err := m .Adapter .StopCloudControl (item .Path , item .Name , true ); err != nil {
314- cmds = append (cmds , m .List .NewStatusMessage (internal .ErrorMessageStyle (fmt .Sprintf ("Can not start CloudControl: %s" , err .Error ()))))
315- }
316- if cmds != nil {
317- return tea .Batch (cmds ... )()
318- }
319- return nil
320- },
321- tea .ClearScreen ,
322- EnableList ,
323- )
268+ return func () tea.Msg {
269+ var cmds []tea.Cmd
270+ if err := m .Adapter .StopCloudControl (item .Path , item .Name , true ); err != nil {
271+ cmds = append (cmds , m .List .NewStatusMessage (internal .ErrorMessageStyle (fmt .Sprintf ("Can not start CloudControl: %s" , err .Error ()))))
272+ }
273+ if cmds != nil {
274+ return tea .Batch (cmds ... )()
275+ }
276+ return nil
277+ }
324278}
325279
326280// getSubFolders walks through the given BasePath and returns a list of directory entries which are also directories.
0 commit comments