Add Store support and unsigned app releases

This commit is contained in:
Tamas Csikel
2026-10-25 14:11:49 +01:00
parent 4975784491
commit d7e9fe4568
157 changed files with 22985 additions and 944 deletions

View File

@@ -13,7 +13,7 @@ use evdev::{EventType, KeyCode};
use crate::link::Link;
const ESC_HOLD: Duration = Duration::from_millis(800);
const OWN_DEVICE: &str = "SmartFox Siri Remote";
const OWN_DEVICE: &str = "Fennec OS Siri Remote";
pub fn spawn(link: Link) {
std::thread::spawn(move || {

View File

@@ -99,7 +99,7 @@ impl Keys {
keys.insert(KeyCode::KEY_PAUSECD);
let dev = VirtualDevice::builder()
.context("opening /dev/uinput (is the user in the smartfox group?)")?
.name("SmartFox Siri Remote")
.name("Fennec OS Siri Remote")
.with_keys(&keys)?
.build()?;
Ok(Self { dev: Some(dev) })
@@ -244,6 +244,9 @@ async fn wake_target(adapter: &Adapter, dev: &Device) -> Option<wake::Target> {
/// Handles one connection until the remote disconnects.
async fn serve(dev: &Device, keys: &mut Keys, step: i32, link: &Link) -> Result<()> {
use bluer::{DeviceEvent, DeviceProperty};
let mut events = dev.events().await?;
let mut reports = futures::stream::select_all(subscribe(dev).await?);
let mut gestures = Gestures::new(step);
let mut held: u16 = 0;
@@ -253,9 +256,20 @@ async fn serve(dev: &Device, keys: &mut Keys, step: i32, link: &Link) -> Result<
let mut held_since = Instant::now();
let mut last_repeat = Instant::now();
let mut tick = tokio::time::interval(Duration::from_millis(20));
let mut connection_check = tokio::time::interval(Duration::from_secs(2));
loop {
tokio::select! {
event = events.next() => match event {
Some(DeviceEvent::PropertyChanged(DeviceProperty::Connected(false))) | None => return Ok(()),
Some(_) => {}
},
_ = connection_check.tick() => {
// Notification streams can stay open after the GATT link goes away.
if !dev.is_connected().await.unwrap_or(false) {
return Ok(());
}
}
item = reports.next() => {
let Some(data) = item else { return Ok(()) };
match protocol::parse(&data) {
@@ -319,13 +333,16 @@ async fn serve(dev: &Device, keys: &mut Keys, step: i32, link: &Link) -> Result<
}
}
/// The remote advertises with a rotating private address. The controller's
/// accept list only knows its identity address, so BlueZ's passive
/// auto-connect never sees it. An active scan lets the kernel resolve the
/// address with the bonded IRK; we connect as soon as an advert arrives.
async fn wait_for_advert(adapter: &Adapter, dev: &Device) -> Result<()> {
/// The remote advertises with a rotating private address. Keep discovery
/// active while connecting so BlueZ can resolve that address with the bonded
/// IRK. Also retry without an RSSI event: some controllers do not report one
/// for an already known device after the remote restarts.
async fn connect(adapter: &Adapter, dev: &Device) -> Result<bool> {
use bluer::{DeviceEvent, DeviceProperty, DiscoveryFilter, DiscoveryTransport};
if dev.is_connected().await.unwrap_or(false) {
return Ok(true);
}
adapter
.set_discovery_filter(DiscoveryFilter {
transport: DiscoveryTransport::Le,
@@ -335,30 +352,48 @@ async fn wait_for_advert(adapter: &Adapter, dev: &Device) -> Result<()> {
.await?;
let mut discovery = adapter.discover_devices_with_changes().await?;
let mut events = dev.events().await?;
let mut recheck = tokio::time::interval(Duration::from_secs(2));
let mut retry = tokio::time::interval(Duration::from_secs(5));
retry.reset();
loop {
tokio::select! {
// A connection may come up between our checks (e.g. a pending Connect()).
_ = recheck.tick() => {
if dev.is_connected().await.unwrap_or(false) {
return Ok(());
}
// Removed in the launcher's settings: go back to pairing.
if !dev.is_paired().await.unwrap_or(false) {
anyhow::bail!("remote {} was unpaired", dev.address());
}
}
let should_connect = tokio::select! {
_ = retry.tick() => true,
ev = events.next() => match ev {
Some(DeviceEvent::PropertyChanged(DeviceProperty::Rssi(rssi))) => {
log::info!("remote advertising (rssi {rssi}), connecting");
return Ok(());
true
}
Some(DeviceEvent::PropertyChanged(DeviceProperty::Connected(true))) => return Ok(()),
Some(_) => {}
Some(DeviceEvent::PropertyChanged(DeviceProperty::Connected(true))) => return Ok(true),
Some(_) => false,
None => anyhow::bail!("device event stream ended"),
},
// Keep the discovery session alive and drained.
_ = discovery.next() => {}
event = discovery.next() => {
if event.is_none() {
anyhow::bail!("discovery ended");
}
false
}
};
if !should_connect {
continue;
}
if dev.is_connected().await.unwrap_or(false) {
return Ok(true);
}
// Removed in the launcher's settings: go back to pairing.
if !dev.is_paired().await.unwrap_or(false) {
anyhow::bail!("remote {} was unpaired", dev.address());
}
match tokio::time::timeout(Duration::from_secs(10), dev.connect()).await {
Ok(Ok(())) => return Ok(true),
Ok(Err(e)) if e.kind == bluer::ErrorKind::InProgress => {
tokio::time::sleep(Duration::from_secs(2)).await;
}
Ok(Err(e)) => log::debug!("connect: {e}"),
Err(_) => log::debug!("connect timed out"),
}
if dev.is_connected().await.unwrap_or(false) {
return Ok(true);
}
}
}
@@ -426,31 +461,6 @@ async fn pair_new(adapter: &Adapter, link: &Link) -> Result<Device> {
}
}
async fn connect(adapter: &Adapter, dev: &Device) -> Result<bool> {
if dev.is_connected().await.unwrap_or(false) {
return Ok(true);
}
wait_for_advert(adapter, dev).await?;
if dev.is_connected().await.unwrap_or(false) {
return Ok(true);
}
match tokio::time::timeout(Duration::from_secs(10), dev.connect()).await {
Ok(Ok(())) => Ok(true),
Ok(Err(e)) if e.kind == bluer::ErrorKind::InProgress => {
tokio::time::sleep(Duration::from_secs(2)).await;
Ok(false)
}
Ok(Err(e)) => {
log::debug!("connect: {e}");
Ok(false)
}
Err(_) => {
log::debug!("connect timed out");
Ok(false)
}
}
}
pub fn run() -> Result<()> {
let opts = parse_args();
let link = Link::new(opts.home_socket.clone());

View File

@@ -1,6 +1,6 @@
#![cfg_attr(not(target_os = "linux"), allow(dead_code))]
//! sf-remote: Apple Siri Remote driver for SmartFox.
//! sf-remote: Apple Siri Remote driver for Fennec OS.
//!
//! Subscribes to the remote's HID report characteristics over BlueZ D-Bus
//! (BlueZ's own HID plugin must be disabled, it drops these reports) and

View File

@@ -5,7 +5,7 @@
//! on its USB device and the ports above it.
//! 2. The kernel keeps scanning for the remote while suspended. It does that
//! for devices on its connect list that carry the "remote wakeup" flag.
//! BlueZ sets both only through its HID plugins, which SmartFox disables
//! BlueZ sets both only through its HID plugins, which Fennec OS disables
//! (they drop the Siri Remote's reports), so we send the two management
//! commands ourselves: Add Device (auto-connect) and Set Device Flags.
//!