pub struct PortalGrant { /* private fields */ }Expand description
A desktop portal grant kept in a file, so a later run can skip the picker.
PortalGrant::selection seeds a Selection with the stored restore
token and stores each new token the portal grants. On a compositor that
keeps grants, the next run then shares the same screen or window without
asking.
The file survives an open that is killed or refused, since the open takes
the token before asking the portal. Once the portal has granted a new
token, the end of the stream (for example the user stopped sharing)
deletes the file, so the next run asks again, unless
keep_after_end is set.
The file holds the token as text, readable only by its owner.
VideoOpenOptions::with_portal_grants
keeps grants for sources opened from a specifier.
§Examples
use moq_ext_sources::{PortalGrant, VideoSource};
use moq_video::capture::{self, portal::Kind};
let grant = PortalGrant::in_config_dir(Kind::Screen, "my-app").expect("a home directory");
let mut config = capture::Config::default();
config.source = capture::Source::Portal(grant.selection());
let screen = VideoSource::capture(config).await?;Implementations§
Source§impl PortalGrant
impl PortalGrant
Sourcepub fn new(kind: Kind, path: impl Into<PathBuf>) -> Self
pub fn new(kind: Kind, path: impl Into<PathBuf>) -> Self
Creates a grant of kind stored in the file at path.
Sourcepub fn keep_after_end(self) -> Self
pub fn keep_after_end(self) -> Self
Keeps the stored grant when the stream ends, until a new one replaces it.
The next run then tries the stored token, and the portal asks only if the compositor no longer honors it.
Sourcepub fn in_config_dir(kind: Kind, app: &str) -> Option<Self>
pub fn in_config_dir(kind: Kind, app: &str) -> Option<Self>
Creates a grant of kind stored in the user’s config directory.
The file is <app>/portal/{screen,window}.token under
$XDG_CONFIG_HOME, or ~/.config when that is unset or not absolute.
Returns None without either, or when app is not a single file name.
Sourcepub fn selection(&self) -> Selection
pub fn selection(&self) -> Selection
Returns a selection seeded with the stored token, which stores each new one.
A missing or unreadable file gives a selection without a token, so the portal asks. New tokens are stored by a task that ends with the last clone of the selection; outside a tokio runtime they are not stored.
Trait Implementations§
Source§impl Clone for PortalGrant
impl Clone for PortalGrant
Source§impl Debug for PortalGrant
impl Debug for PortalGrant
impl Eq for PortalGrant
Source§impl PartialEq for PortalGrant
impl PartialEq for PortalGrant
impl StructuralPartialEq for PortalGrant
Auto Trait Implementations§
impl Freeze for PortalGrant
impl RefUnwindSafe for PortalGrant
impl Send for PortalGrant
impl Sync for PortalGrant
impl Unpin for PortalGrant
impl UnsafeUnpin for PortalGrant
impl UnwindSafe for PortalGrant
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.