Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
A6GibKm committed Jan 1, 2023
1 parent 841d172 commit 908a074
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 61 deletions.
78 changes: 39 additions & 39 deletions src/backend/file_chooser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,19 @@ pub struct FileChooser<T: FileChooserImpl> {
}

impl<T: FileChooserImpl> FileChooser<T> {
pub async fn new<N: TryInto<WellKnownName<'static>>>(imp: T, name: N) -> zbus::Result<Self>
pub async fn new<N: TryInto<WellKnownName<'static>>>(
imp: T,
cnx: &zbus::Connection,
proxy: &zbus::fdo::DBusProxy<'_>,
name: N,
) -> zbus::Result<Self>
where
zbus::Error: From<<N as TryInto<WellKnownName<'static>>>::Error>,
{
let (sender, receiver) = futures_channel::mpsc::channel(10);
let iface = FileChooserInterface::new(sender);
let cnx = zbus::Connection::session().await.unwrap();
let object_server = cnx.object_server();

let proxy = zbus::fdo::DBusProxy::builder(&cnx).build().await?;
proxy
.request_name(
name.try_into()?,
Expand All @@ -132,60 +135,57 @@ impl<T: FileChooserImpl> FileChooser<T> {
receiver: RefCell::new(Some(receiver)),
imp,
};
provider.wait().await?;

Ok(provider)
}

async fn wait(&mut self) -> zbus::fdo::Result<()> {
async fn next(&mut self) -> zbus::fdo::Result<()> {
let mut receiver = self.receiver.borrow_mut().take().unwrap();
loop {
match receiver.next().await {
Some(Action::OpenFile(
handle,
app_id,
window_identifier,
title,
options,
sender,
match receiver.next().await {
Some(Action::OpenFile(
handle,
app_id,
window_identifier,
title,
options,
sender,
)) => {
let results = self
.imp
let results = self
.imp
.open_file(handle, &app_id, window_identifier, &title, options)
.await;
let _ = sender.send(results);
let _ = sender.send(results);
}
Some(Action::SaveFile(
handle,
app_id,
window_identifier,
title,
options,
sender,
Some(Action::SaveFile(
handle,
app_id,
window_identifier,
title,
options,
sender,
)) => {
let results = self
.imp
let results = self
.imp
.save_file(handle, &app_id, window_identifier, &title, options)
.await;
let _ = sender.send(results);
let _ = sender.send(results);
}
Some(Action::SaveFiles(
handle,
app_id,
window_identifier,
title,
options,
sender,
Some(Action::SaveFiles(
handle,
app_id,
window_identifier,
title,
options,
sender,
)) => {
let results = self
.imp
let results = self
.imp
.save_files(handle, &app_id, window_identifier, &title, options)
.await;
let _ = sender.send(results);
let _ = sender.send(results);
}
None => (),
None => (),
}
}
}
}

Expand Down
44 changes: 22 additions & 22 deletions src/backend/wallpaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@ pub struct Wallpaper<T: WallpaperImpl> {
}

impl<T: WallpaperImpl> Wallpaper<T> {
pub async fn new<N: TryInto<WellKnownName<'static>>>(imp: T, name: N) -> zbus::Result<Self>
pub async fn new<N: TryInto<WellKnownName<'static>>>(
imp: T,
cnx: &zbus::Connection,
proxy: &zbus::fdo::DBusProxy<'_>,
name: N,
) -> zbus::Result<Self>
where
zbus::Error: From<<N as TryInto<WellKnownName<'static>>>::Error>,
{
let (sender, receiver) = futures_channel::mpsc::channel(10);
let iface = WallpaperInterface::new(sender);
let cnx = zbus::Connection::session().await.unwrap();
let object_server = cnx.object_server();

let proxy = zbus::fdo::DBusProxy::builder(&cnx).build().await?;
proxy
.request_name(
name.try_into()?,
Expand All @@ -57,30 +60,27 @@ impl<T: WallpaperImpl> Wallpaper<T> {
receiver: RefCell::new(Some(receiver)),
imp,
};
provider.wait().await?;

Ok(provider)
}

async fn wait(&mut self) -> zbus::fdo::Result<()> {
async fn next(&mut self) -> zbus::fdo::Result<()> {
let mut receiver = self.receiver.borrow_mut().take().unwrap();
loop {
let response = receiver.next().await;
if let Some(Action::SetWallpaperURI(
handle,
app_id,
window_identifier,
uri,
options,
sender,
)) = response
{
let result =
self.imp
.set_wallpaper_uri(handle, &app_id, window_identifier, uri, options);
let _ = sender.send(result);
};
}
let response = receiver.next().await;
if let Some(Action::SetWallpaperURI(
handle,
app_id,
window_identifier,
uri,
options,
sender,
)) = response
{
let result =
self.imp
.set_wallpaper_uri(handle, &app_id, window_identifier, uri, options);
let _ = sender.send(result);
};
}
}

Expand Down

0 comments on commit 908a074

Please sign in to comment.