Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use xdg-activation #61

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 82 additions & 25 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 @@ -29,6 +29,7 @@ itertools = "0.11"
freedesktop-icons = "0.2.4"
current_locale = "0.1.1"
url = "2.4"
nix = "0.26"

[profile.release]
lto = "thin"
43 changes: 30 additions & 13 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use cosmic::iced_runtime::core::event::{wayland, PlatformSpecific};
use cosmic::iced_runtime::core::keyboard::KeyCode;
use cosmic::iced_runtime::core::window::Id as SurfaceId;
use cosmic::iced_sctk::commands;
use cosmic::iced_sctk::commands::activation::request_token;
use cosmic::iced_sctk::commands::data_device::cancel_dnd;
use cosmic::iced_style::application::{self, Appearance};
use cosmic::iced_widget::text_input::focus;
Expand All @@ -38,7 +39,6 @@ use log::error;
use once_cell::sync::Lazy;

use crate::app_group::{AppLibraryConfig, DesktopEntryData};
use crate::config::APP_ID;
use crate::fl;
use crate::subscriptions::desktop_files::desktop_files;
use crate::subscriptions::toggle_dbus::dbus_toggle;
Expand Down Expand Up @@ -110,6 +110,7 @@ enum Message {
Hide,
Clear,
ActivateApp(usize),
ActivationToken(Option<String>, String),
SelectGroup(usize),
Delete(usize),
ConfirmDelete,
Expand Down Expand Up @@ -225,20 +226,36 @@ impl cosmic::Application for CosmicAppLibrary {
Message::ActivateApp(i) => {
self.edit_name = None;
if let Some(de) = self.entry_path_input.get(i) {
let mut exec = shlex::Shlex::new(&de.exec);
let mut cmd = match exec.next() {
Some(cmd) if !cmd.contains("=") => tokio::process::Command::new(cmd),
_ => return Command::none(),
};
for arg in exec {
// TODO handle "%" args here if necessary?
if !arg.starts_with("%") {
cmd.arg(arg);
}
let exec = de.exec.clone();
return request_token(
Some(String::from(Self::APP_ID)),
Some(WINDOW_ID),
move |token| {
cosmic::app::Message::App(Message::ActivationToken(token, exec))
},
);
}
}
Message::ActivationToken(token, exec) => {
let mut exec = shlex::Shlex::new(&exec);
let mut cmd = match exec.next() {
Some(cmd) if !cmd.contains("=") => std::process::Command::new(cmd),
_ => return Command::none(),
};
for arg in exec {
// TODO handle "%" args here if necessary?
if !arg.starts_with("%") {
cmd.arg(arg);
}
let _ = cmd.spawn();
return self.update(Message::Hide);
}
if let Some(token) = token {
cmd.env("XDG_ACTIVATION_TOKEN", token.clone());
cmd.env("DESKTOP_STARTUP_ID", token);
}
tokio::task::spawn_blocking(|| {
crate::process::spawn(cmd);
});
return self.update(Message::Hide);
}
Message::SelectGroup(i) => {
self.edit_name = None;
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod config;
mod app;
mod app_group;
mod localize;
pub mod process;
mod subscriptions;
mod widgets;

Expand Down
Loading
Loading