Skip to content

Commit 8675267

Browse files
committed
initial commit: replaced Capturer::new with Capturer::build
1 parent fa776e0 commit 8675267

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/target
22
.DS_Store
33
/test
4+
/.idea

src/capturer/mod.rs

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

33
use std::sync::mpsc;
44

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

107
#[derive(Debug, Clone, Copy, Default)]
118
pub enum Resolution {
@@ -74,14 +71,23 @@ pub struct Capturer {
7471
}
7572

7673
impl Capturer {
77-
/// Create a new capturer instance with the provided options
78-
pub fn new(options: Options) -> Capturer {
74+
/// Build a new [Capturer] instance with the provided options
75+
pub fn build(options: Options) -> Result<Capturer, &'static str> {
76+
if !is_supported() {
77+
return Err("❌ Platform not supported");
78+
}
79+
80+
if !has_permission() && !request_permission() {
81+
return Err("❌ Permission not granted.");
82+
}
83+
7984
let (tx, rx) = mpsc::channel::<Frame>();
8085
let engine = engine::Engine::new(&options, tx);
8186

82-
Capturer { engine, rx }
87+
Ok(Capturer { engine, rx })
8388
}
8489

90+
8591
// TODO
8692
// Prevent starting capture if already started
8793
/// Start capturing the frames

src/main.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
use scap::{
55
capturer::{Area, Capturer, Options, Point, Size},
6-
frame::Frame,
7-
Target,
6+
frame::Frame
7+
,
88
};
9+
use std::process;
910

1011
fn main() {
1112
// Check if the platform is supported
@@ -46,7 +47,10 @@ fn main() {
4647
};
4748

4849
// Create Recorder with options
49-
let mut recorder = Capturer::new(options);
50+
let mut recorder = Capturer::build(options).unwrap_or_else(|err| {
51+
println!("Problem with building Capturer: {err}");
52+
process::exit(1);
53+
});
5054

5155
// Start Capture
5256
recorder.start_capture();

0 commit comments

Comments
 (0)