Skip to content

Commit 12cb7b8

Browse files
committed
backwards compatability + enum error
1 parent 11d386e commit 12cb7b8

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/capturer/mod.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ mod engine;
22

33
use std::sync::mpsc;
44

5-
use crate::{frame::{Frame, FrameType}, has_permission, is_supported, request_permission, targets::Target};
5+
use crate::{
6+
frame::{Frame, FrameType},
7+
has_permission, is_supported, request_permission,
8+
targets::Target,
9+
};
610

711
#[derive(Debug, Clone, Copy, Default)]
812
pub enum Resolution {
@@ -70,15 +74,32 @@ pub struct Capturer {
7074
rx: mpsc::Receiver<Frame>,
7175
}
7276

77+
pub enum CapturerBuildError {
78+
NotSupported,
79+
PermissionNotGranted,
80+
}
81+
7382
impl Capturer {
83+
/// Create a new capturer instance with the provided options
84+
#[deprecated(
85+
since = "0.0.6",
86+
note = "Use `build` instead of `new` to create a new capturer instance."
87+
)]
88+
pub fn new(options: Options) -> Capturer {
89+
let (tx, rx) = mpsc::channel::<Frame>();
90+
let engine = engine::Engine::new(&options, tx);
91+
92+
Capturer { engine, rx }
93+
}
94+
7495
/// Build a new [Capturer] instance with the provided options
75-
pub fn build(options: Options) -> Result<Capturer, &'static str> {
96+
pub fn build(options: Options) -> Result<Capturer, CapturerBuildError> {
7697
if !is_supported() {
77-
return Err("❌ Platform not supported");
98+
return Err(CapturerBuildError::NotSupported);
7899
}
79100

80-
if !has_permission() && !request_permission() {
81-
return Err("❌ Permission not granted.");
101+
if !has_permission() {
102+
return Err(CapturerBuildError::PermissionNotGranted);
82103
}
83104

84105
let (tx, rx) = mpsc::channel::<Frame>();
@@ -87,7 +108,6 @@ impl Capturer {
87108
Ok(Capturer { engine, rx })
88109
}
89110

90-
91111
// TODO
92112
// Prevent starting capture if already started
93113
/// Start capturing the frames

0 commit comments

Comments
 (0)