tauri-plugin-screen-wake-lock 0.1.0

A Tauri plugin to keep the screen awake while enabled (desktop only).
Documentation
use tauri::{
  plugin::{Builder, TauriPlugin},
  Manager, Runtime,
};

pub use models::*;

#[cfg(desktop)]
mod desktop;
#[cfg(mobile)]
mod mobile;

mod commands;
mod error;
mod models;

pub use error::{Error, Result};

#[cfg(desktop)]
use desktop::ScreenWakeLock;
#[cfg(mobile)]
use mobile::ScreenWakeLock;

/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the screen-wake-lock APIs.
pub trait ScreenWakeLockExt<R: Runtime> {
  fn screen_wake_lock(&self) -> &ScreenWakeLock<R>;
}

impl<R: Runtime, T: Manager<R>> crate::ScreenWakeLockExt<R> for T {
  fn screen_wake_lock(&self) -> &ScreenWakeLock<R> {
    self.state::<ScreenWakeLock<R>>().inner()
  }
}

/// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> {
  Builder::new("screen-wake-lock")
    .invoke_handler(tauri::generate_handler![
      commands::set_enabled,
      commands::is_enabled,
      commands::is_supported
    ])
    .setup(|app, api| {
      #[cfg(mobile)]
      let screen_wake_lock = mobile::init(app, api)?;
      #[cfg(desktop)]
      let screen_wake_lock = desktop::init(app, api)?;
      app.manage(screen_wake_lock);
      Ok(())
    })
    .build()
}