mod devices;
use sk_runtime::redjs::webapi::mediastream;
pub fn install() {
let raw = std::env::var("SK_MEDIA_CAPTURE").ok();
match capture_mode(raw.as_deref()) {
CaptureMode::Deny => {
mediastream::forbid_capture();
eprintln!("[sk] SK_MEDIA_CAPTURE=deny: microphone capture is off for this process");
}
CaptureMode::Fake => {
mediastream::set_fake_capture();
mediastream::set_capture_allowed(true);
eprintln!("[sk] SK_MEDIA_CAPTURE=fake: getUserMedia captures a synthetic 440 Hz tone; no device is opened");
}
CaptureMode::Device => {
if let Some(v) = raw.as_deref().filter(|v| !v.trim().is_empty()) {
eprintln!("[sk] SK_MEDIA_CAPTURE={v:?} is neither `deny` nor `fake`: ignored");
}
mediastream::set_capture_allowed(true);
}
}
devices::install();
if let Some(hint) = system_denied_hint() {
mediastream::set_system_denied_hint(hint);
}
}
fn system_denied_hint() -> Option<&'static str> {
if cfg!(target_os = "windows") {
Some(
"On Windows: Settings > Privacy & security > Microphone (ms-settings:privacy-microphone); both \
\"Microphone access\" and \"Let desktop apps access your microphone\" must be on. \
appPermissions.request(\"microphone\") opens that page.",
)
} else if cfg!(target_os = "macos") {
Some(
"On macOS: System Settings › Privacy & Security › Microphone \
(x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone); this app must be \
on. appPermissions.request(\"microphone\") opens that page.",
)
} else {
None
}
}
#[derive(Debug, PartialEq, Eq)]
enum CaptureMode {
Device,
Deny,
Fake,
}
fn capture_mode(value: Option<&str>) -> CaptureMode {
match value.map(str::trim) {
Some(v) if v.eq_ignore_ascii_case("deny") => CaptureMode::Deny,
Some(v) if v.eq_ignore_ascii_case("fake") => CaptureMode::Fake,
_ => CaptureMode::Device,
}
}