voelin-ui: let "Choose via system dialog" always open the portal's dialog
After a share that granted a portal restore token, every later share passed the stored token, and xdg-desktop-portal restored the earlier choice without showing its picker: on Wayland the share dialog's only source, "Choose via system dialog", never showed a dialog again, and nothing could change what was shared. That entry now never sends the token, so the portal always asks (and may grant a new token, which is stored as before). With a stored token the share dialog lists a second entry, "Same as last time", which restores the last choice without the dialog. The studio's portal sources are added without a token and ask every time; docs/studio.md claimed the token was written back into the scene, which the UI does not do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
630ff848b2
commit
3e37c24836
3 files changed
+80
-28
No files matched your search
@@ -414,7 +414,8 @@ impl App {
|
|||||||
let test_pattern = cfg!(debug_assertions)
|
let test_pattern = cfg!(debug_assertions)
|
||||||
|| self.demo
|
|| self.demo
|
||||||
|| std::env::var("VOELIN_TEST_PATTERN").is_ok_and(|v| v == "1");
|
|| std::env::var("VOELIN_TEST_PATTERN").is_ok_and(|v| v == "1");
|
||||||
let sources = match self.video.sources(test_pattern) {
|
let restorable = self.settings.portal_restore_token.is_some();
|
||||||
|
let sources = match self.video.sources(test_pattern, restorable) {
|
||||||
Ok(sources) => {
|
Ok(sources) => {
|
||||||
if self.share.is_none() {
|
if self.share.is_none() {
|
||||||
self.share_error.clear();
|
self.share_error.clear();
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use std::sync::Arc;
|
|||||||
use slint::{Image, Rgba8Pixel, SharedPixelBuffer};
|
use slint::{Image, Rgba8Pixel, SharedPixelBuffer};
|
||||||
use tokio::runtime::Handle;
|
use tokio::runtime::Handle;
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
use voelin_core::media::voelin_media::capture::SourceId;
|
use voelin_core::media::voelin_media::capture::{CaptureSource, SourceId};
|
||||||
use voelin_core::media::voelin_media::{Codec, Codecs, EncoderReport, VideoFrame, convert};
|
use voelin_core::media::voelin_media::{Codec, Codecs, EncoderReport, VideoFrame, convert};
|
||||||
use voelin_core::media::{
|
use voelin_core::media::{
|
||||||
self, AudioSourceSpec, EncoderPreference, Latest, LocalPreview, Streamer, StreamerConfig,
|
self, AudioSourceSpec, EncoderPreference, Latest, LocalPreview, Streamer, StreamerConfig,
|
||||||
@@ -63,7 +63,7 @@ pub(crate) struct Video {
|
|||||||
encoder: EncoderPreference,
|
encoder: EncoderPreference,
|
||||||
codec: Option<Codec>,
|
codec: Option<Codec>,
|
||||||
/// Sources of the share dialog, by index.
|
/// Sources of the share dialog, by index.
|
||||||
sources: Vec<(SourceId, String)>,
|
sources: Vec<ShareEntry>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Video {
|
impl Video {
|
||||||
@@ -199,8 +199,14 @@ impl Video {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Screens and windows to share, as (name, detail); the test pattern too
|
/// Screens and windows to share, as (name, detail); the test pattern too
|
||||||
/// when asked for.
|
/// when asked for. With `restorable` (a portal restore token from an
|
||||||
pub fn sources(&mut self, test_pattern: bool) -> Result<Vec<(String, String)>, String> {
|
/// earlier share) the portal comes twice: its dialog, which always asks,
|
||||||
|
/// and the last choice again without the dialog.
|
||||||
|
pub fn sources(
|
||||||
|
&mut self,
|
||||||
|
test_pattern: bool,
|
||||||
|
restorable: bool,
|
||||||
|
) -> Result<Vec<(String, String)>, String> {
|
||||||
let mut error = None;
|
let mut error = None;
|
||||||
let mut sources = match media::screen_sources() {
|
let mut sources = match media::screen_sources() {
|
||||||
Ok(list) => list,
|
Ok(list) => list,
|
||||||
@@ -215,26 +221,9 @@ impl Video {
|
|||||||
if sources.is_empty() {
|
if sources.is_empty() {
|
||||||
return Err(error.unwrap_or_else(|| "Nothing to share was found.".into()));
|
return Err(error.unwrap_or_else(|| "Nothing to share was found.".into()));
|
||||||
}
|
}
|
||||||
self.sources = sources.iter().map(|s| (s.id.clone(), s.name.clone())).collect();
|
let (rows, entries) = share_rows(&sources, restorable);
|
||||||
Ok(sources
|
self.sources = entries;
|
||||||
.iter()
|
Ok(rows)
|
||||||
.map(|s| {
|
|
||||||
let name = match s.id {
|
|
||||||
SourceId::Portal => "Choose via system dialog".to_owned(),
|
|
||||||
_ => s.name.clone(),
|
|
||||||
};
|
|
||||||
let detail = match (&s.id, s.primary) {
|
|
||||||
(SourceId::Monitor(_), true) => {
|
|
||||||
format!("{} · primary", size_text(s.width, s.height))
|
|
||||||
}
|
|
||||||
(SourceId::Window(_), _) => {
|
|
||||||
format!("window {}", size_text(s.width, s.height)).trim().to_owned()
|
|
||||||
}
|
|
||||||
_ => size_text(s.width, s.height),
|
|
||||||
};
|
|
||||||
(name, detail)
|
|
||||||
})
|
|
||||||
.collect())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start capturing source `index` of [`Video::sources`]; `done` runs on
|
/// Start capturing source `index` of [`Video::sources`]; `done` runs on
|
||||||
@@ -246,7 +235,7 @@ impl Video {
|
|||||||
options: CaptureRequest,
|
options: CaptureRequest,
|
||||||
done: impl FnOnce(Result<Capture, String>) + Send + 'static,
|
done: impl FnOnce(Result<Capture, String>) + Send + 'static,
|
||||||
) {
|
) {
|
||||||
let Some((source, name)) = self.sources.get(index).cloned() else {
|
let Some((source, name, restore)) = self.sources.get(index).cloned() else {
|
||||||
done(Err("Pick something to share.".into()));
|
done(Err("Pick something to share.".into()));
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@@ -264,7 +253,8 @@ impl Video {
|
|||||||
encoder: self.encoder.clone(),
|
encoder: self.encoder.clone(),
|
||||||
audio: options.audio,
|
audio: options.audio,
|
||||||
audio_sources: options.audio_sources,
|
audio_sources: options.audio_sources,
|
||||||
restore_token: options.restore_token,
|
// The portal skips its dialog with a token: only when asked to.
|
||||||
|
restore_token: options.restore_token.filter(|_| restore),
|
||||||
..StreamerConfig::default()
|
..StreamerConfig::default()
|
||||||
};
|
};
|
||||||
runtime.spawn(async move {
|
runtime.spawn(async move {
|
||||||
@@ -368,6 +358,40 @@ fn deliver(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// What a row of the share dialog starts: the source, its name, and whether
|
||||||
|
/// to restore the portal's last choice instead of asking.
|
||||||
|
type ShareEntry = (SourceId, String, bool);
|
||||||
|
|
||||||
|
/// The share dialog's rows (name, detail) for `sources`, and what each row
|
||||||
|
/// starts (restoring only in the extra portal row with `restorable`).
|
||||||
|
fn share_rows(
|
||||||
|
sources: &[CaptureSource],
|
||||||
|
restorable: bool,
|
||||||
|
) -> (Vec<(String, String)>, Vec<ShareEntry>) {
|
||||||
|
let mut rows = Vec::with_capacity(sources.len() + 1);
|
||||||
|
let mut entries = Vec::with_capacity(sources.len() + 1);
|
||||||
|
for s in sources {
|
||||||
|
let name = match s.id {
|
||||||
|
SourceId::Portal => "Choose via system dialog".to_owned(),
|
||||||
|
_ => s.name.clone(),
|
||||||
|
};
|
||||||
|
let detail = match (&s.id, s.primary) {
|
||||||
|
(SourceId::Monitor(_), true) => format!("{} · primary", size_text(s.width, s.height)),
|
||||||
|
(SourceId::Window(_), _) => {
|
||||||
|
format!("window {}", size_text(s.width, s.height)).trim().to_owned()
|
||||||
|
}
|
||||||
|
_ => size_text(s.width, s.height),
|
||||||
|
};
|
||||||
|
rows.push((name, detail));
|
||||||
|
entries.push((s.id.clone(), s.name.clone(), false));
|
||||||
|
if s.id == SourceId::Portal && restorable {
|
||||||
|
rows.push(("Same as last time".to_owned(), "without the dialog".to_owned()));
|
||||||
|
entries.push((s.id.clone(), s.name.clone(), true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(rows, entries)
|
||||||
|
}
|
||||||
|
|
||||||
/// Share settings from the dialog.
|
/// Share settings from the dialog.
|
||||||
pub(crate) struct CaptureRequest {
|
pub(crate) struct CaptureRequest {
|
||||||
pub fps: u32,
|
pub fps: u32,
|
||||||
@@ -473,3 +497,30 @@ impl Decoder {
|
|||||||
stats.error.filter(|_| stats.decoded == 0)
|
stats.error.filter(|_| stats.decoded == 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
/// "Choose via system dialog" never passes the restore token, so the
|
||||||
|
/// portal always asks; with a token the last choice gets its own row.
|
||||||
|
#[test]
|
||||||
|
fn the_portal_dialog_always_asks() {
|
||||||
|
let portal = CaptureSource {
|
||||||
|
id: SourceId::Portal,
|
||||||
|
name: "Screen".into(),
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
primary: false,
|
||||||
|
};
|
||||||
|
let (rows, entries) = share_rows(std::slice::from_ref(&portal), false);
|
||||||
|
assert_eq!(rows.len(), 1);
|
||||||
|
assert_eq!(rows[0].0, "Choose via system dialog");
|
||||||
|
assert!(!entries[0].2);
|
||||||
|
let (rows, entries) = share_rows(&[portal], true);
|
||||||
|
let names: Vec<_> = rows.iter().map(|(name, _)| name.as_str()).collect();
|
||||||
|
assert_eq!(names, ["Choose via system dialog", "Same as last time"]);
|
||||||
|
let restore: Vec<_> = entries.iter().map(|e| e.2).collect();
|
||||||
|
assert_eq!(restore, [false, true]);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -43,7 +43,7 @@ the UI) and a `background` (replacement, below).
|
|||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `screen` | `monitor`, `backend` (`portal`, `wlroots`, `x11`, `windows`; none: this session's), `cursor` | a capture backend, frames borrowed and copied into pooled frames |
|
| `screen` | `monitor`, `backend` (`portal`, `wlroots`, `x11`, `windows`; none: this session's), `cursor` | a capture backend, frames borrowed and copied into pooled frames |
|
||||||
| `window` | `handle` (X11 id, `HWND`), `backend`, `cursor` | the same |
|
| `window` | `handle` (X11 id, `HWND`), `backend`, `cursor` | the same |
|
||||||
| `portal` | `restore_token`, `cursor` | the ScreenCast portal's dialog (Wayland); the token is written back so it is asked once |
|
| `portal` | `restore_token`, `cursor` | the ScreenCast portal's dialog (Wayland); with a `restore_token` the portal may restore its last choice without asking. The UI adds portal sources without one, so the dialog asks each time the source starts |
|
||||||
| `camera` | `device` (a `camera::Camera::id`; empty: the first), `size`, `fps`, `mirror` | see [Cameras](#cameras) |
|
| `camera` | `device` (a `camera::Camera::id`; empty: the first), `size`, `fps`, `mirror` | see [Cameras](#cameras) |
|
||||||
| `image` | `path` | PNG or JPEG, alpha kept, read once |
|
| `image` | `path` | PNG or JPEG, alpha kept, read once |
|
||||||
| `text` | `text`, `font` (none: the bundled Inter), `size_px`, `colour`, `backdrop`, `align`, `padding` | rasterised once with `ab_glyph` |
|
| `text` | `text`, `font` (none: the bundled Inter), `size_px`, `colour`, `backdrop`, `align`, `padding` | rasterised once with `ab_glyph` |
|
||||||
|
|||||||
Reference in new issue
Block a user