@@ -79,7 +79,8 @@ impl Plugins {
7979 match self {
8080 Plugins :: Loaded ( state) => match message {
8181 PluginMessage :: Plugin ( index, msg) => {
82- if let Event :: Synchronize = state. plugins [ index] . update ( msg) {
82+ let update_event = state. plugins [ index] . update ( msg) ;
83+ if let Event :: Synchronize = update_event. 0 {
8384 let mut plugins: Vec < PluginRow > = Vec :: new ( ) ;
8485 let mut all_plugins: Vec < InstalledPlugin > =
8586 Synchronizer :: get_plugins ( ) . values ( ) . cloned ( ) . collect ( ) ;
@@ -98,7 +99,9 @@ impl Plugins {
9899 }
99100 state. plugins = plugins;
100101 }
101- Command :: none ( )
102+ update_event
103+ . 1
104+ . map ( move |msg| PluginMessage :: Plugin ( index, msg) )
102105 }
103106
104107 PluginMessage :: RefreshPressed => {
@@ -127,6 +130,7 @@ impl Plugins {
127130 & plugin. latest_version ,
128131 & plugin. folder ,
129132 ) ) ;
133+ plugins. sort_by ( |a, b| a. title . to_lowercase ( ) . cmp ( & b. title . to_lowercase ( ) ) ) ;
130134 }
131135 state. plugins = plugins;
132136 Command :: none ( )
@@ -347,66 +351,61 @@ impl PluginRow {
347351 }
348352 }
349353
350- pub fn update ( & mut self , message : RowMessage ) -> Event {
354+ pub fn update ( & mut self , message : RowMessage ) -> ( Event , Command < RowMessage > ) {
351355 match message {
352356 RowMessage :: ToggleView => {
353357 self . opened = !self . opened ;
354- Event :: Nothing
355- }
356- RowMessage :: UpdatePressed ( plugin) => {
357- Command :: perform (
358- APIConnector :: fetch_details ( plugin. title ) ,
359- RowMessage :: Updating ,
360- ) ;
361- Event :: Nothing
362- }
363- RowMessage :: DeletePressed ( row) => {
364- Command :: perform ( APIConnector :: fetch_details ( row. title ) , RowMessage :: Deleting ) ;
365- Event :: Nothing
358+ ( Event :: Nothing , Command :: none ( ) )
366359 }
360+ RowMessage :: UpdatePressed ( plugin) => (
361+ Event :: Nothing ,
362+ Command :: perform ( APIConnector :: fetch_details ( plugin. id ) , RowMessage :: Updating ) ,
363+ ) ,
364+ RowMessage :: DeletePressed ( row) => (
365+ Event :: Nothing ,
366+ Command :: perform ( APIConnector :: fetch_details ( row. id ) , RowMessage :: Deleting ) ,
367+ ) ,
367368 RowMessage :: WebsitePressed ( id, title) => {
368369 webbrowser:: open ( & format ! (
369370 "https://www.lotrointerface.com/downloads/info{}-{}.html" ,
370371 id, title,
371372 ) )
372373 . unwrap ( ) ;
373- Event :: Nothing
374+ ( Event :: Nothing , Command :: none ( ) )
374375 }
375376 RowMessage :: Updating ( fetched_plugin) => {
376377 if let Ok ( fetched_plugin) = fetched_plugin {
377378 if Installer :: download ( & fetched_plugin) . is_ok ( ) {
378- self . status = "Downloaded" . to_string ( ) ;
379379 if Installer :: delete (
380380 & fetched_plugin. base_plugin . folder ,
381381 & fetched_plugin. files ,
382382 )
383383 . is_ok ( )
384384 {
385385 if Installer :: extract ( & fetched_plugin) . is_ok ( ) {
386- self . status = "Unpacked" . to_string ( ) ;
387386 Installer :: delete_cache_folder ( & fetched_plugin) ;
388387 if Synchronizer :: insert_plugin ( & fetched_plugin) . is_ok ( ) {
389- self . status = "Installed " . to_string ( ) ;
390- Event :: Synchronize
388+ self . status = "Updated " . to_string ( ) ;
389+ ( Event :: Synchronize , Command :: none ( ) )
391390 } else {
392- self . status = "Install failed" . to_string ( ) ;
393- Event :: Nothing
391+ self . status = "Update failed" . to_string ( ) ;
392+ ( Event :: Nothing , Command :: none ( ) )
394393 }
395394 } else {
396395 self . status = "Unpacking failed" . to_string ( ) ;
397- Event :: Nothing
396+ ( Event :: Nothing , Command :: none ( ) )
398397 }
399398 } else {
400399 self . status = "Installation failed" . to_string ( ) ;
401- Event :: Nothing
400+ ( Event :: Nothing , Command :: none ( ) )
402401 }
403402 } else {
404403 self . status = "Download failed" . to_string ( ) ;
405- Event :: Nothing
404+ ( Event :: Nothing , Command :: none ( ) )
406405 }
407406 } else {
408- self . status = "Download failed" . to_string ( ) ;
409- Event :: Nothing
407+ self . status = "Update failed" . to_string ( ) ;
408+ ( Event :: Nothing , Command :: none ( ) )
410409 }
411410 }
412411 RowMessage :: Deleting ( fetched_plugin) => {
@@ -416,18 +415,18 @@ impl PluginRow {
416415 {
417416 if Synchronizer :: delete_plugin ( & fetched_plugin. base_plugin . title ) . is_ok ( ) {
418417 self . status = "Deleted" . to_string ( ) ;
419- Event :: Synchronize
418+ ( Event :: Synchronize , Command :: none ( ) )
420419 } else {
421420 self . status = "Delete failed" . to_string ( ) ;
422- Event :: Nothing
421+ ( Event :: Nothing , Command :: none ( ) )
423422 }
424423 } else {
425424 self . status = "Delete failed" . to_string ( ) ;
426- Event :: Nothing
425+ ( Event :: Nothing , Command :: none ( ) )
427426 }
428427 } else {
429428 self . status = "Delete failed" . to_string ( ) ;
430- Event :: Nothing
429+ ( Event :: Nothing , Command :: none ( ) )
431430 }
432431 }
433432 }
0 commit comments