Skip to content

Commit

Permalink
Right click menu to create desktop shortcuts
Browse files Browse the repository at this point in the history
Closes: pop-os#170
  • Loading branch information
joshuamegnauth54 committed Oct 25, 2024
1 parent 3dd148d commit 9626a99
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ nix = "0.28"
clap = { version = "4.4.8", features = ["derive"] }
switcheroo-control = { git = "https://github.com/pop-os/dbus-settings-bindings" }
cosmic-app-list-config = { git = "https://github.com/pop-os/cosmic-applets" }
dirs = "5"

[profile.release]
lto = "thin"
Expand Down
1 change: 1 addition & 0 deletions i18n/en/cosmic_app_library.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ run-on = Run on {$gpu}
run-on-default = (Default)
remove = Move to library home
create-new = Create new folder
add-desktop-shortcut = Add desktop shortcut
add-group = Add group
delete = Delete
rename = Rename
Expand Down
36 changes: 35 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ enum Message {
GpuUpdate(Option<Vec<Gpu>>),
PinToAppTray(usize),
UnPinFromAppTray(usize),
DesktopShortcut(usize),
AppListConfig(AppListConfig),
}

Expand Down Expand Up @@ -760,6 +761,20 @@ impl cosmic::Application for CosmicAppLibrary {
.remove_pinned(&pinned_id, &app_list_helper);
}
}
Message::DesktopShortcut(i) => {
if let Some(entry) = self.entry_path_input.get(i) {
let entry = Arc::clone(entry);
return Task::perform(
async move {
if let Err(e) = desktop_shortcut(entry).await {
error!("Failed copying desktop entry to desktop: {e:?}");
}
cosmic::app::Message::None
},
|x| x,
);
}
}
Message::AppListConfig(config) => {
self.app_list_config = config;
}
Expand Down Expand Up @@ -847,6 +862,14 @@ impl cosmic::Application for CosmicAppLibrary {
}
}

// Desktop shortcut
list_column.push(divider::horizontal::light().into());
list_column.push(
menu_button(body(fl!("add-desktop-shortcut")))
.on_press(Message::DesktopShortcut(*i))
.into(),
);

// add to pinned
let svg_accent = Rc::new(|theme: &cosmic::Theme| {
let color = theme.cosmic().accent_color().into();
Expand All @@ -870,7 +893,6 @@ impl cosmic::Application for CosmicAppLibrary {
} else {
Message::PinToAppTray(*i)
});
list_column.push(divider::horizontal::light().into());
list_column.push(pin_to_app_tray.into());

if self.cur_group > 0 {
Expand Down Expand Up @@ -1448,3 +1470,15 @@ impl cosmic::Application for CosmicAppLibrary {
(self_, Task::none())
}
}

/// Copy application desktop entry to the user's desktop
async fn desktop_shortcut(entry: Arc<DesktopEntryData>) -> tokio::io::Result<u64> {
let source = entry
.path
.as_deref()
.ok_or(tokio::io::Error::other("Desktop entry doesn't have a path"))?;
let dest = dirs::desktop_dir()
.ok_or(tokio::io::Error::other("User doesn't have a desktop dir"))?
.join(format!("{}.desktop", &*entry.name));
tokio::fs::copy(source, dest).await
}

0 comments on commit 9626a99

Please sign in to comment.