Skip to content

Commit

Permalink
demo/remote-desktop: Add persistence of sessions support
Browse files Browse the repository at this point in the history
  • Loading branch information
bilelmoussaoui committed Jul 21, 2024
1 parent 4119ab3 commit 47aa993
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
15 changes: 15 additions & 0 deletions ashpd-demo/data/resources/ui/remote_desktop.ui
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@
</child>
</object>
</child>
<child>
<object class="AdwComboRow" id="persist_mode_combo">
<property name="title" translatable="yes">Persist Session Mode</property>
<property name="model">
<object class="GtkStringList">
<items>
<item translatable="yes">Do Not</item>
<item translatable="yes">Application</item>
<item translatable="yes">Explicitly Revoked</item>
</items>
</object>
</property>
<property name="selected">0</property>
</object>
</child>
</object>
</child>
<child>
Expand Down
20 changes: 19 additions & 1 deletion ashpd-demo/src/portals/desktop/remote_desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ mod imp {
pub virtual_check: TemplateChild<gtk::CheckButton>,
#[template_child]
pub cursor_mode_combo: TemplateChild<adw::ComboRow>,
#[template_child]
pub persist_mode_combo: TemplateChild<adw::ComboRow>,
pub session_token: Arc<Mutex<Option<String>>>,
}

#[glib::object_subclass]
Expand Down Expand Up @@ -154,6 +157,15 @@ impl RemoteDesktopPage {
sources
}

fn selected_persist_mode(&self) -> PersistMode {
match self.imp().persist_mode_combo.selected() {
0 => PersistMode::DoNot,
1 => PersistMode::Application,
2 => PersistMode::ExplicitlyRevoked,
_ => unreachable!(),
}
}

/// Returns the selected CursorMode
fn selected_cursor_mode(&self) -> CursorMode {
match self
Expand Down Expand Up @@ -220,6 +232,8 @@ impl RemoteDesktopPage {
let cursor_mode = self.selected_cursor_mode();
let sources = self.selected_sources();
let devices = self.selected_devices();
let persist_mode = self.selected_persist_mode();
let mut token = imp.session_token.lock().await;

let proxy = RemoteDesktop::new().await?;
let session = proxy.create_session().await?;
Expand All @@ -237,11 +251,15 @@ impl RemoteDesktopPage {
.await?;
}
proxy
.select_devices(&session, devices, None, PersistMode::default())
.select_devices(&session, devices, token.as_deref(), persist_mode)
.await?;

self.info("Starting a remote desktop session");
let response = proxy.start(&session, &identifier).await?.response()?;
if let Some(t) = response.restore_token() {
token.replace(t.to_owned());
}

Ok((
response.devices(),
response.streams().unwrap_or_default().to_owned(),
Expand Down

0 comments on commit 47aa993

Please sign in to comment.