@@ -2,7 +2,11 @@ mod engine;
2
2
3
3
use std:: sync:: mpsc;
4
4
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
+ } ;
6
10
7
11
#[ derive( Debug , Clone , Copy , Default ) ]
8
12
pub enum Resolution {
@@ -70,15 +74,32 @@ pub struct Capturer {
70
74
rx : mpsc:: Receiver < Frame > ,
71
75
}
72
76
77
+ pub enum CapturerBuildError {
78
+ NotSupported ,
79
+ PermissionNotGranted ,
80
+ }
81
+
73
82
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
+
74
95
/// 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 > {
76
97
if !is_supported ( ) {
77
- return Err ( "❌ Platform not supported" ) ;
98
+ return Err ( CapturerBuildError :: NotSupported ) ;
78
99
}
79
100
80
- if !has_permission ( ) && ! request_permission ( ) {
81
- return Err ( "❌ Permission not granted." ) ;
101
+ if !has_permission ( ) {
102
+ return Err ( CapturerBuildError :: PermissionNotGranted ) ;
82
103
}
83
104
84
105
let ( tx, rx) = mpsc:: channel :: < Frame > ( ) ;
@@ -87,7 +108,6 @@ impl Capturer {
87
108
Ok ( Capturer { engine, rx } )
88
109
}
89
110
90
-
91
111
// TODO
92
112
// Prevent starting capture if already started
93
113
/// Start capturing the frames
0 commit comments