Skip to content

Commit 707de93

Browse files
Right click menu to create desktop shortcuts
Closes: #170
1 parent 3981b6a commit 707de93

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
@@ -45,6 +45,7 @@ nix = "0.28"
4545
clap = { version = "4.4.8", features = ["derive"] }
4646
switcheroo-control = { git = "https://github.com/pop-os/dbus-settings-bindings" }
4747
cosmic-app-list-config = { git = "https://github.com/pop-os/cosmic-applets" }
48+
dirs = "5"
4849

4950
[profile.release]
5051
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
@@ -284,6 +284,7 @@ enum Message {
284284
GpuUpdate(Option<Vec<Gpu>>),
285285
PinToAppTray(usize),
286286
UnPinFromAppTray(usize),
287+
DesktopShortcut(usize),
287288
AppListConfig(AppListConfig),
288289
}
289290

@@ -730,6 +731,20 @@ impl cosmic::Application for CosmicAppLibrary {
730731
.remove_pinned(&pinned_id, &app_list_helper);
731732
}
732733
}
734+
Message::DesktopShortcut(i) => {
735+
if let Some(entry) = self.entry_path_input.get(i) {
736+
let entry = Arc::clone(entry);
737+
return Command::perform(
738+
async move {
739+
if let Err(e) = desktop_shortcut(entry).await {
740+
error!("Failed copying desktop entry to desktop: {e:?}");
741+
}
742+
cosmic::app::Message::None
743+
},
744+
|x| x,
745+
);
746+
}
747+
}
733748
Message::AppListConfig(config) => {
734749
self.app_list_config = config;
735750
}
@@ -821,6 +836,14 @@ impl cosmic::Application for CosmicAppLibrary {
821836
}
822837
}
823838

839+
// Desktop shortcut
840+
list_column.push(menu_divider(spacing).into());
841+
list_column.push(
842+
menu_button(body(fl!("add-desktop-shortcut")))
843+
.on_press(Message::DesktopShortcut(*i))
844+
.into(),
845+
);
846+
824847
// add to pinned
825848
let spacing_xxs = cosmic.spacing.space_xxs;
826849
let svg_accent = Rc::new(|theme: &cosmic::Theme| {
@@ -846,7 +869,6 @@ impl cosmic::Application for CosmicAppLibrary {
846869
} else {
847870
Message::PinToAppTray(*i)
848871
});
849-
list_column.push(menu_divider(spacing).into());
850872
list_column.push(pin_to_app_tray.into());
851873

852874
if self.cur_group > 0 {
@@ -1437,3 +1459,15 @@ fn menu_divider<'a>(spacing: &Spacing) -> Container<'a, Message, cosmic::Theme,
14371459
.padding([spacing.space_none, spacing.space_xxs])
14381460
.width(Length::Fill)
14391461
}
1462+
1463+
/// Copy application desktop entry to the user's desktop
1464+
async fn desktop_shortcut(entry: Arc<DesktopEntryData>) -> tokio::io::Result<u64> {
1465+
let source = entry
1466+
.path
1467+
.as_deref()
1468+
.ok_or(tokio::io::Error::other("Desktop entry doesn't have a path"))?;
1469+
let dest = dirs::desktop_dir()
1470+
.ok_or(tokio::io::Error::other("User doesn't have a desktop dir"))?
1471+
.join(format!("{}.desktop", &*entry.name));
1472+
tokio::fs::copy(source, dest).await
1473+
}

0 commit comments

Comments
 (0)