Skip to content

Commit 9626a99

Browse files
Right click menu to create desktop shortcuts
Closes: #170
1 parent 3dd148d commit 9626a99

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ nix = "0.28"
4646
clap = { version = "4.4.8", features = ["derive"] }
4747
switcheroo-control = { git = "https://github.com/pop-os/dbus-settings-bindings" }
4848
cosmic-app-list-config = { git = "https://github.com/pop-os/cosmic-applets" }
49+
dirs = "5"
4950

5051
[profile.release]
5152
lto = "thin"

i18n/en/cosmic_app_library.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ run-on = Run on {$gpu}
1616
run-on-default = (Default)
1717
remove = Move to library home
1818
create-new = Create new folder
19+
add-desktop-shortcut = Add desktop shortcut
1920
add-group = Add group
2021
delete = Delete
2122
rename = Rename

src/app.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ enum Message {
312312
GpuUpdate(Option<Vec<Gpu>>),
313313
PinToAppTray(usize),
314314
UnPinFromAppTray(usize),
315+
DesktopShortcut(usize),
315316
AppListConfig(AppListConfig),
316317
}
317318

@@ -760,6 +761,20 @@ impl cosmic::Application for CosmicAppLibrary {
760761
.remove_pinned(&pinned_id, &app_list_helper);
761762
}
762763
}
764+
Message::DesktopShortcut(i) => {
765+
if let Some(entry) = self.entry_path_input.get(i) {
766+
let entry = Arc::clone(entry);
767+
return Task::perform(
768+
async move {
769+
if let Err(e) = desktop_shortcut(entry).await {
770+
error!("Failed copying desktop entry to desktop: {e:?}");
771+
}
772+
cosmic::app::Message::None
773+
},
774+
|x| x,
775+
);
776+
}
777+
}
763778
Message::AppListConfig(config) => {
764779
self.app_list_config = config;
765780
}
@@ -847,6 +862,14 @@ impl cosmic::Application for CosmicAppLibrary {
847862
}
848863
}
849864

865+
// Desktop shortcut
866+
list_column.push(divider::horizontal::light().into());
867+
list_column.push(
868+
menu_button(body(fl!("add-desktop-shortcut")))
869+
.on_press(Message::DesktopShortcut(*i))
870+
.into(),
871+
);
872+
850873
// add to pinned
851874
let svg_accent = Rc::new(|theme: &cosmic::Theme| {
852875
let color = theme.cosmic().accent_color().into();
@@ -870,7 +893,6 @@ impl cosmic::Application for CosmicAppLibrary {
870893
} else {
871894
Message::PinToAppTray(*i)
872895
});
873-
list_column.push(divider::horizontal::light().into());
874896
list_column.push(pin_to_app_tray.into());
875897

876898
if self.cur_group > 0 {
@@ -1448,3 +1470,15 @@ impl cosmic::Application for CosmicAppLibrary {
14481470
(self_, Task::none())
14491471
}
14501472
}
1473+
1474+
/// Copy application desktop entry to the user's desktop
1475+
async fn desktop_shortcut(entry: Arc<DesktopEntryData>) -> tokio::io::Result<u64> {
1476+
let source = entry
1477+
.path
1478+
.as_deref()
1479+
.ok_or(tokio::io::Error::other("Desktop entry doesn't have a path"))?;
1480+
let dest = dirs::desktop_dir()
1481+
.ok_or(tokio::io::Error::other("User doesn't have a desktop dir"))?
1482+
.join(format!("{}.desktop", &*entry.name));
1483+
tokio::fs::copy(source, dest).await
1484+
}

0 commit comments

Comments
 (0)