Handle org.freedesktop.FileManager1 in cosmic-files-applet

This commit is contained in:
Jeremy Soller 2025-01-23 14:01:59 -07:00
parent d322017e09
commit b9f43cb53e
No known key found for this signature in database
GPG key ID: D02FD439211AF56F
4 changed files with 67 additions and 0 deletions

2
Cargo.lock generated
View file

@ -1282,6 +1282,8 @@ name = "cosmic-files-applet"
version = "0.1.0"
dependencies = [
"cosmic-files",
"log",
"zbus 4.4.0",
]
[[package]]

View file

@ -3,6 +3,10 @@ name = "cosmic-files-applet"
version = "0.1.0"
edition = "2021"
[dependencies]
log = "0.4"
zbus = "4"
[dependencies.cosmic-files]
path = ".."
default-features = false

View file

@ -0,0 +1,53 @@
// SPDX-License-Identifier: GPL-3.0-only
// Implementation of https://www.freedesktop.org/wiki/Specifications/file-manager-interface/
#![allow(dead_code, non_snake_case)]
use std::process;
pub struct FileManager;
impl FileManager {
//TODO: return error?
fn open(&self, uris: &[&str], _startup_id: &str) {
match process::Command::new("cosmic-files").args(uris).spawn() {
Ok(mut child) => {
log::info!("spawned cosmic-files with id {:?}", child.id());
match child.wait() {
Ok(status) => {
if status.success() {
log::info!("cosmic-files exited with {status}");
} else {
log::warn!("failed to run cosmic-files: exited with {status}");
}
}
Err(err) => {
log::warn!("failed to run cosmic-files: {err}");
}
}
}
Err(err) => {
log::warn!("failed to spawn cosmic-files: {err}");
}
}
}
}
//TODO: why does &[&str] not implement Deserialize?
#[zbus::interface(name = "org.freedesktop.FileManager1")]
impl FileManager {
fn ShowFolders(&self, URIs: Vec<&str>, StartupId: &str) {
log::warn!("ShowFolders {:?} {:?}", URIs, StartupId);
self.open(&URIs, StartupId)
}
fn ShowItems(&self, URIs: Vec<&str>, StartupId: &str) {
log::warn!("ShowItems {:?} {:?}", URIs, StartupId);
self.open(&URIs, StartupId)
}
fn ShowItemProperties(&self, URIs: Vec<&str>, StartupId: &str) {
log::warn!("ShowItemProperties {:?} {:?}", URIs, StartupId);
self.open(&URIs, StartupId)
}
}

View file

@ -1,3 +1,11 @@
mod file_manager;
fn main() -> Result<(), Box<dyn std::error::Error>> {
//TODO: move file manager service to its own daemon?
let _conn_res = zbus::blocking::connection::Builder::session()?
.name("org.freedesktop.FileManager1")?
.serve_at("/org/freedesktop/FileManager1", file_manager::FileManager)?
.build();
cosmic_files::desktop()
}