Handle org.freedesktop.FileManager1 in cosmic-files-applet
This commit is contained in:
parent
d322017e09
commit
b9f43cb53e
4 changed files with 67 additions and 0 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -1282,6 +1282,8 @@ name = "cosmic-files-applet"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"cosmic-files",
|
||||
"log",
|
||||
"zbus 4.4.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
53
cosmic-files-applet/src/file_manager.rs
Normal file
53
cosmic-files-applet/src/file_manager.rs
Normal 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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue