Add Print support
This commit is contained in:
parent
95bc64076d
commit
52a0ccee0d
3 changed files with 82 additions and 5 deletions
|
|
@ -182,6 +182,7 @@ async fn main() -> eyre::Result<()> {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let notification_imp = portal::notification::Notification::new(&host_session_conn).await?;
|
let notification_imp = portal::notification::Notification::new(&host_session_conn).await?;
|
||||||
|
let print_imp = portal::print::Print::new(&host_session_conn).await?;
|
||||||
let settings_imp = portal::settings::Settings::new(&host_session_conn).await?;
|
let settings_imp = portal::settings::Settings::new(&host_session_conn).await?;
|
||||||
|
|
||||||
async fn on_vm_bus_connected(
|
async fn on_vm_bus_connected(
|
||||||
|
|
@ -189,6 +190,7 @@ async fn main() -> eyre::Result<()> {
|
||||||
file_chooser: portal::file_chooser::FileChooser,
|
file_chooser: portal::file_chooser::FileChooser,
|
||||||
file_transfer: portal::file_transfer::FileTransfer,
|
file_transfer: portal::file_transfer::FileTransfer,
|
||||||
notification: portal::notification::Notification,
|
notification: portal::notification::Notification,
|
||||||
|
print: portal::print::Print,
|
||||||
settings: portal::settings::Settings,
|
settings: portal::settings::Settings,
|
||||||
) -> Result<(), eyre::Report> {
|
) -> Result<(), eyre::Report> {
|
||||||
if !vm_bus_conn
|
if !vm_bus_conn
|
||||||
|
|
@ -239,6 +241,14 @@ async fn main() -> eyre::Result<()> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if !vm_bus_conn
|
||||||
|
.object_server()
|
||||||
|
.at("/org/freedesktop/portal/desktop", print)
|
||||||
|
.await?
|
||||||
|
{
|
||||||
|
error!("org.freedesktop.portal.Print already provided");
|
||||||
|
};
|
||||||
|
|
||||||
if !vm_bus_conn
|
if !vm_bus_conn
|
||||||
.object_server()
|
.object_server()
|
||||||
.at("/org/freedesktop/portal/desktop", settings)
|
.at("/org/freedesktop/portal/desktop", settings)
|
||||||
|
|
@ -264,16 +274,16 @@ async fn main() -> eyre::Result<()> {
|
||||||
|
|
||||||
if let Some(path) = cli.unix_path {
|
if let Some(path) = cli.unix_path {
|
||||||
let vm_unix_listener = UnixListener::bind(path)?;
|
let vm_unix_listener = UnixListener::bind(path)?;
|
||||||
server_tasks.spawn(enclose!((file_chooser_imp, file_transfer_imp, notification_imp, settings_imp) async move {
|
server_tasks.spawn(enclose!((file_chooser_imp, file_transfer_imp, notification_imp, print_imp, settings_imp) async move {
|
||||||
while let Ok((socket, remote_addr)) = vm_unix_listener.accept().await {
|
while let Ok((socket, remote_addr)) = vm_unix_listener.accept().await {
|
||||||
let f = enclose!((file_chooser_imp, file_transfer_imp, notification_imp, settings_imp) async move {
|
let f = enclose!((file_chooser_imp, file_transfer_imp, notification_imp, print_imp, settings_imp) async move {
|
||||||
let client_conn = zbus::connection::Builder::unix_stream(socket)
|
let client_conn = zbus::connection::Builder::unix_stream(socket)
|
||||||
.auth_mechanism(zbus::AuthMechanism::Anonymous)
|
.auth_mechanism(zbus::AuthMechanism::Anonymous)
|
||||||
.name("org.freedesktop.portal.Desktop")?
|
.name("org.freedesktop.portal.Desktop")?
|
||||||
.name("org.freedesktop.portal.Documents")?
|
.name("org.freedesktop.portal.Documents")?
|
||||||
.build()
|
.build()
|
||||||
.await?;
|
.await?;
|
||||||
on_vm_bus_connected(client_conn, file_chooser_imp, file_transfer_imp, notification_imp, settings_imp).await
|
on_vm_bus_connected(client_conn, file_chooser_imp, file_transfer_imp, notification_imp, print_imp, settings_imp).await
|
||||||
});
|
});
|
||||||
tokio::spawn(
|
tokio::spawn(
|
||||||
async {
|
async {
|
||||||
|
|
@ -294,10 +304,10 @@ async fn main() -> eyre::Result<()> {
|
||||||
vsock::ListenerBuilder::new(vsock::VsockAddr::new(vsock::VMADDR_CID_HOST, port))
|
vsock::ListenerBuilder::new(vsock::VsockAddr::new(vsock::VMADDR_CID_HOST, port))
|
||||||
.with_label("VM Bus")
|
.with_label("VM Bus")
|
||||||
.listen(move |client| {
|
.listen(move |client| {
|
||||||
enclose!((file_chooser_imp, file_transfer_imp, notification_imp, settings_imp) async move {
|
enclose!((file_chooser_imp, file_transfer_imp, notification_imp, print_imp, settings_imp) async move {
|
||||||
// TODO: Not necessary to go through the channel, add vsock support to the Peer too?
|
// TODO: Not necessary to go through the channel, add vsock support to the Peer too?
|
||||||
let client_conn = client.build().await?;
|
let client_conn = client.build().await?;
|
||||||
on_vm_bus_connected(client_conn, file_chooser_imp, file_transfer_imp, notification_imp, settings_imp).await
|
on_vm_bus_connected(client_conn, file_chooser_imp, file_transfer_imp, notification_imp, print_imp, settings_imp).await
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.map_ok_or_else(
|
.map_ok_or_else(
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,6 @@ pub mod documents;
|
||||||
pub mod file_chooser;
|
pub mod file_chooser;
|
||||||
pub mod file_transfer;
|
pub mod file_transfer;
|
||||||
pub mod notification;
|
pub mod notification;
|
||||||
|
pub mod print;
|
||||||
pub mod request;
|
pub mod request;
|
||||||
pub mod settings;
|
pub mod settings;
|
||||||
|
|
|
||||||
66
sidebus-broker/src/portal/print.rs
Normal file
66
sidebus-broker/src/portal/print.rs
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use zbus::{Connection, ObjectServer, fdo::Result, zvariant};
|
||||||
|
|
||||||
|
use super::request::ReqHandler;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Print {
|
||||||
|
host: PrintProxy<'static>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus::interface(
|
||||||
|
name = "org.freedesktop.portal.Print",
|
||||||
|
proxy(
|
||||||
|
default_service = "org.freedesktop.portal.Desktop",
|
||||||
|
default_path = "/org/freedesktop/portal/desktop"
|
||||||
|
)
|
||||||
|
)]
|
||||||
|
impl Print {
|
||||||
|
async fn prepare_print(
|
||||||
|
&self,
|
||||||
|
#[zbus(header)] hdr: zbus::message::Header<'_>,
|
||||||
|
#[zbus(object_server)] server: &ObjectServer,
|
||||||
|
#[zbus(connection)] conn: &Connection,
|
||||||
|
parent_window: &str,
|
||||||
|
title: &str,
|
||||||
|
settings: HashMap<&str, zvariant::Value<'_>>,
|
||||||
|
page_setup: HashMap<&str, zvariant::Value<'_>>,
|
||||||
|
options: HashMap<&str, zvariant::Value<'_>>,
|
||||||
|
) -> Result<zvariant::OwnedObjectPath> {
|
||||||
|
ReqHandler::prepare(&self.host, hdr, server, conn, &options)
|
||||||
|
.perform(async || {
|
||||||
|
self.host
|
||||||
|
.prepare_print(parent_window, title, settings, page_setup, options)
|
||||||
|
.await
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn print(
|
||||||
|
&self,
|
||||||
|
#[zbus(header)] hdr: zbus::message::Header<'_>,
|
||||||
|
#[zbus(object_server)] server: &ObjectServer,
|
||||||
|
#[zbus(connection)] conn: &Connection,
|
||||||
|
parent_window: &str,
|
||||||
|
title: &str,
|
||||||
|
fd: zvariant::Fd<'_>,
|
||||||
|
options: HashMap<&str, zvariant::Value<'_>>,
|
||||||
|
) -> Result<zvariant::OwnedObjectPath> {
|
||||||
|
ReqHandler::prepare(&self.host, hdr, server, conn, &options)
|
||||||
|
.perform(async || self.host.print(parent_window, title, fd, options).await)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property, name = "version")]
|
||||||
|
fn version(&self) -> Result<u32> {
|
||||||
|
Ok(3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Print {
|
||||||
|
pub async fn new(host_session_conn: &Connection) -> Result<Self> {
|
||||||
|
let host = PrintProxy::builder(host_session_conn).build().await?;
|
||||||
|
Ok(Self { host })
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue