Skip to content

Commit 57c6e58

Browse files
committed
fix: clean up context menu popup
1 parent 279c614 commit 57c6e58

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/app.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,8 @@ impl cosmic::Application for CosmicAppLibrary {
677677
return commands::popup::destroy_popup(MENU_ID.clone());
678678
}
679679
Message::SelectAction(action) => {
680+
self.menu = None;
681+
let mut tasks = vec![commands::popup::destroy_popup(MENU_ID.clone())];
680682
if let Some(info) = self.menu.take().and_then(|i| self.entry_path_input.get(i)) {
681683
match action {
682684
MenuAction::Remove => {
@@ -686,7 +688,7 @@ impl cosmic::Application for CosmicAppLibrary {
686688
error!("{:?}", err);
687689
}
688690
}
689-
return self.filter_apps();
691+
tasks.push(self.filter_apps());
690692
}
691693
MenuAction::DesktopAction(exec) => {
692694
let mut exec = shlex::Shlex::new(&exec);
@@ -708,6 +710,7 @@ impl cosmic::Application for CosmicAppLibrary {
708710
}
709711
}
710712
}
713+
return cosmic::Task::batch(tasks);
711714
}
712715
Message::StartDrag(i) => {
713716
self.dnd_icon = Some(i);
@@ -788,6 +791,8 @@ impl cosmic::Application for CosmicAppLibrary {
788791
{
789792
self.app_list_config.add_pinned(pinned_id, &app_list_helper);
790793
}
794+
self.menu = None;
795+
return commands::popup::destroy_popup(MENU_ID.clone());
791796
}
792797
Message::UnPinFromAppTray(usize) => {
793798
let pinned_id = self.entry_path_input.get(usize).map(|e| e.id.clone());
@@ -797,6 +802,8 @@ impl cosmic::Application for CosmicAppLibrary {
797802
self.app_list_config
798803
.remove_pinned(&pinned_id, &app_list_helper);
799804
}
805+
self.menu = None;
806+
return commands::popup::destroy_popup(MENU_ID.clone());
800807
}
801808
Message::AppListConfig(config) => {
802809
self.app_list_config = config;

src/app_group.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,27 @@ impl AppLibraryConfig {
177177
}
178178

179179
pub fn remove(&mut self, i: usize) {
180+
if i == 0 {
181+
return;
182+
}
180183
if i - 1 < self.groups.len() {
181184
self.groups.remove(i - 1);
182185
}
183186
}
184187

185188
pub fn set_name(&mut self, i: usize, name: String) {
189+
if i == 0 {
190+
return;
191+
}
186192
if i - 1 < self.groups.len() {
187193
self.groups[i - 1].name = name;
188194
}
189195
}
190196

191197
pub fn remove_entry(&mut self, i: usize, id: &str) {
198+
if i == 0 {
199+
return;
200+
}
192201
if let Some(group) = self.groups.get_mut(i - 1) {
193202
match &mut group.filter {
194203
FilterType::AppIds(ids) => ids.retain(|conf_id| conf_id != id),
@@ -210,7 +219,7 @@ impl AppLibraryConfig {
210219
}
211220

212221
pub fn add_entry(&mut self, i: usize, id: &str) {
213-
if i - 1 < self.groups.len() {
222+
if i > 0 && i - 1 < self.groups.len() {
214223
if let FilterType::AppIds(ids) = &mut self.groups[i - 1].filter {
215224
if ids.iter().all(|s| s != id) {
216225
ids.push(id.to_string());

0 commit comments

Comments
 (0)