feat(default_apps): set default terminal in system_actions config
This commit is contained in:
parent
8f9f287db0
commit
777cbae425
2 changed files with 71 additions and 19 deletions
36
Cargo.lock
generated
36
Cargo.lock
generated
|
|
@ -1082,9 +1082,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.13"
|
||||
version = "1.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7777341816418c02e033934a09f20dc0ccaf65a5201ef8a450ae0105a573fda"
|
||||
checksum = "0c3d1b2e905a3a7b00a6141adb0e4c0bb941d11caf55349d863942a1cc44e3c9"
|
||||
dependencies = [
|
||||
"jobserver",
|
||||
"libc",
|
||||
|
|
@ -1509,7 +1509,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "cosmic-comp-config"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/pop-os/cosmic-comp#2678cf41b2550d4959ac74b3da14761d93a74f3d"
|
||||
source = "git+https://github.com/pop-os/cosmic-comp#2bf74951ea2d8f41dbc468506bca367663a88fab"
|
||||
dependencies = [
|
||||
"cosmic-config",
|
||||
"input",
|
||||
|
|
@ -1519,7 +1519,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "cosmic-config"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
|
||||
source = "git+https://github.com/pop-os/libcosmic#ccc1068d9fd894334feef7d50a7a2b6930c7a34f"
|
||||
dependencies = [
|
||||
"atomicwrites",
|
||||
"cosmic-config-derive",
|
||||
|
|
@ -1541,7 +1541,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "cosmic-config-derive"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
|
||||
source = "git+https://github.com/pop-os/libcosmic#ccc1068d9fd894334feef7d50a7a2b6930c7a34f"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
|
|
@ -1842,7 +1842,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "cosmic-theme"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
|
||||
source = "git+https://github.com/pop-os/libcosmic#ccc1068d9fd894334feef7d50a7a2b6930c7a34f"
|
||||
dependencies = [
|
||||
"almost",
|
||||
"cosmic-config",
|
||||
|
|
@ -3215,7 +3215,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced"
|
||||
version = "0.14.0-dev"
|
||||
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
|
||||
source = "git+https://github.com/pop-os/libcosmic#ccc1068d9fd894334feef7d50a7a2b6930c7a34f"
|
||||
dependencies = [
|
||||
"dnd",
|
||||
"iced_accessibility",
|
||||
|
|
@ -3233,7 +3233,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_accessibility"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
|
||||
source = "git+https://github.com/pop-os/libcosmic#ccc1068d9fd894334feef7d50a7a2b6930c7a34f"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"accesskit_winit",
|
||||
|
|
@ -3242,7 +3242,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_core"
|
||||
version = "0.14.0-dev"
|
||||
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
|
||||
source = "git+https://github.com/pop-os/libcosmic#ccc1068d9fd894334feef7d50a7a2b6930c7a34f"
|
||||
dependencies = [
|
||||
"bitflags 2.8.0",
|
||||
"bytes",
|
||||
|
|
@ -3267,7 +3267,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_futures"
|
||||
version = "0.14.0-dev"
|
||||
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
|
||||
source = "git+https://github.com/pop-os/libcosmic#ccc1068d9fd894334feef7d50a7a2b6930c7a34f"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"iced_core",
|
||||
|
|
@ -3293,7 +3293,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_graphics"
|
||||
version = "0.14.0-dev"
|
||||
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
|
||||
source = "git+https://github.com/pop-os/libcosmic#ccc1068d9fd894334feef7d50a7a2b6930c7a34f"
|
||||
dependencies = [
|
||||
"bitflags 2.8.0",
|
||||
"bytemuck",
|
||||
|
|
@ -3315,7 +3315,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_renderer"
|
||||
version = "0.14.0-dev"
|
||||
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
|
||||
source = "git+https://github.com/pop-os/libcosmic#ccc1068d9fd894334feef7d50a7a2b6930c7a34f"
|
||||
dependencies = [
|
||||
"iced_graphics",
|
||||
"iced_tiny_skia",
|
||||
|
|
@ -3327,7 +3327,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_runtime"
|
||||
version = "0.14.0-dev"
|
||||
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
|
||||
source = "git+https://github.com/pop-os/libcosmic#ccc1068d9fd894334feef7d50a7a2b6930c7a34f"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"cosmic-client-toolkit",
|
||||
|
|
@ -3343,7 +3343,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_tiny_skia"
|
||||
version = "0.14.0-dev"
|
||||
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
|
||||
source = "git+https://github.com/pop-os/libcosmic#ccc1068d9fd894334feef7d50a7a2b6930c7a34f"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"cosmic-text",
|
||||
|
|
@ -3359,7 +3359,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_wgpu"
|
||||
version = "0.14.0-dev"
|
||||
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
|
||||
source = "git+https://github.com/pop-os/libcosmic#ccc1068d9fd894334feef7d50a7a2b6930c7a34f"
|
||||
dependencies = [
|
||||
"as-raw-xcb-connection",
|
||||
"bitflags 2.8.0",
|
||||
|
|
@ -3390,7 +3390,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_widget"
|
||||
version = "0.14.0-dev"
|
||||
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
|
||||
source = "git+https://github.com/pop-os/libcosmic#ccc1068d9fd894334feef7d50a7a2b6930c7a34f"
|
||||
dependencies = [
|
||||
"cosmic-client-toolkit",
|
||||
"dnd",
|
||||
|
|
@ -3409,7 +3409,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_winit"
|
||||
version = "0.14.0-dev"
|
||||
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
|
||||
source = "git+https://github.com/pop-os/libcosmic#ccc1068d9fd894334feef7d50a7a2b6930c7a34f"
|
||||
dependencies = [
|
||||
"cosmic-client-toolkit",
|
||||
"dnd",
|
||||
|
|
@ -4414,7 +4414,7 @@ checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
|||
[[package]]
|
||||
name = "libcosmic"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
|
||||
source = "git+https://github.com/pop-os/libcosmic#ccc1068d9fd894334feef7d50a7a2b6930c7a34f"
|
||||
dependencies = [
|
||||
"apply",
|
||||
"ashpd 0.9.2",
|
||||
|
|
|
|||
|
|
@ -12,8 +12,13 @@ use cosmic::{
|
|||
widget::{self, dropdown, icon, settings},
|
||||
Apply, Element, Task,
|
||||
};
|
||||
use cosmic_config::{ConfigGet, ConfigSet};
|
||||
use cosmic_settings_config::shortcuts::action::System;
|
||||
use cosmic_settings_config::shortcuts::SystemActions;
|
||||
use cosmic_settings_page::{self as page, section, Section};
|
||||
use freedesktop_desktop_entry::{default_paths, DesktopEntry, Iter as DesktopEntryIter};
|
||||
use freedesktop_desktop_entry::{
|
||||
default_paths, get_languages_from_env, DesktopEntry, Iter as DesktopEntryIter,
|
||||
};
|
||||
use mime_apps::App;
|
||||
use slotmap::SlotMap;
|
||||
use tokio::sync::mpsc;
|
||||
|
|
@ -81,6 +86,7 @@ pub struct AppMeta {
|
|||
pub struct Page {
|
||||
on_enter_handle: Option<cosmic::iced::task::Handle>,
|
||||
mime_apps: Option<CachedMimeApps>,
|
||||
shortcuts_config: Option<cosmic_config::Config>,
|
||||
}
|
||||
|
||||
impl page::AutoBind<crate::pages::Message> for Page {}
|
||||
|
|
@ -107,6 +113,10 @@ impl page::Page<crate::pages::Message> for Page {
|
|||
handle.abort();
|
||||
}
|
||||
|
||||
if self.shortcuts_config.is_none() {
|
||||
self.shortcuts_config = cosmic_settings_config::shortcuts::context().ok();
|
||||
}
|
||||
|
||||
let (task, on_enter_handle) = Task::future(async move {
|
||||
let mut list = mime_apps::List::default();
|
||||
list.load_from_paths(&mime_apps::list_paths());
|
||||
|
|
@ -239,6 +249,13 @@ impl Page {
|
|||
if meta.selected != Some(id) {
|
||||
meta.selected = Some(id);
|
||||
let appid = &meta.app_ids[id];
|
||||
|
||||
if category == Category::Terminal && self.shortcuts_config.is_some() {
|
||||
if let Some(config) = self.shortcuts_config.as_ref() {
|
||||
assign_default_terminal(config, appid);
|
||||
}
|
||||
}
|
||||
|
||||
for mime in mime_types {
|
||||
if let Ok(mime) = mime.parse() {
|
||||
mime_apps
|
||||
|
|
@ -368,6 +385,41 @@ fn apps() -> Section<crate::pages::Message> {
|
|||
})
|
||||
}
|
||||
|
||||
fn assign_default_terminal(config: &cosmic_config::Config, appid: &str) {
|
||||
let mut actions = config
|
||||
.get_local::<SystemActions>("system_actions")
|
||||
.unwrap_or_default();
|
||||
|
||||
let default_paths = default_paths();
|
||||
let mut resolved_path = None;
|
||||
|
||||
// loop through all FDE paths to try and find a valid .desktop file
|
||||
for path in default_paths {
|
||||
if let Ok(mut full_path) = path.canonicalize() {
|
||||
full_path = full_path.join([appid, ".desktop"].concat());
|
||||
if full_path.exists() && full_path.is_file() {
|
||||
resolved_path = Some(full_path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if we find a valid .desktop file, we can grab its exec
|
||||
if let Some(resolved_path) = resolved_path {
|
||||
let desktop_entry = DesktopEntry::from_path(resolved_path, Some(&get_languages_from_env()));
|
||||
|
||||
if let Ok(desktop_entry) = desktop_entry {
|
||||
if let Some(exec) = desktop_entry.exec() {
|
||||
actions.insert(System::Terminal, String::from(exec));
|
||||
|
||||
if let Err(why) = config.set("system_actions", actions) {
|
||||
tracing::error!(?why, "Unable to set system_actions shortcuts config");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn load_defaults(assocs: &BTreeMap<Arc<str>, Arc<App>>, for_mimes: &[&str]) -> AppMeta {
|
||||
let mut unsorted = Vec::new();
|
||||
let mut current_app = None;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue