reg-watcher

Crates.ioreg-watcher
lib.rsreg-watcher
version0.1.1
sourcesrc
created_at2018-07-22 17:09:11.872439
updated_at2019-08-30 13:29:23.628391
descriptionA rust library for single instance application.
homepage
repositoryhttps://github.com/WLBF/reg-watcher
max_upload_size
id75524
size36,494
junction-labs (github:junction-labs:junction-labs)

documentation

README

reg-watcher

Crates.io Build status

Rust binding to MS Windows RegNotifyChangeKeyValue API.

Features

  • synchronous and asynchronous API for registry change watching
  • Tokio stream API

Usage

[dependencies]
reg-watcher = "0.1"

Basic usage

extern crate reg_watcher;
extern crate winreg;

use winreg::{
    RegKey,
    enums::*,
};
use reg_watcher::*;

fn main() {
    let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
    let reg_key = hklm.open_subkey(r#"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"#).unwrap();
    let res = watch(&reg_key, filter::REG_LEGAL_CHANGE_FILTER, true, Timeout::Milli(60 * 1000)).unwrap();
    println!("{:?}", res);
}

Async

extern crate reg_watcher;
extern crate winreg;

use std::{
    time::Duration,
    sync::mpsc::channel,
};
use winreg::{
    RegKey,
    enums::*,
};
use reg_watcher::*;

fn main() {
    let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
    let reg_key = hklm.open_subkey(r#"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"#).unwrap();
    let mut w = Watcher::new(reg_key, filter::REG_LEGAL_CHANGE_FILTER, true, Duration::from_secs(1));
    let (sender, receiver) = channel();
    let _ = w.watch_async(sender);

    loop {
        let res = receiver.recv().unwrap();
        println!("{:?}", res);
    }
}

Stream

extern crate futures;
extern crate reg_watcher;
extern crate winreg;
extern crate tokio;

use futures::prelude::*;
use std::{
    time::Duration,
};
use winreg::{
    RegKey,
    enums::*,
};
use reg_watcher::*;

fn main() {
    let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
    let reg_key = hklm.open_subkey(r#"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"#).unwrap();
    let w = Watcher::new(reg_key, filter::REG_LEGAL_CHANGE_FILTER, true, Duration::from_secs(1));

    let fut = w.for_each(|_| {
        println!("notify");
        Ok(())
    }).map_err(|err| {
        println!("accept error = {:?}", err);
    });

    tokio::run(fut);
}
Commit count: 11

cargo fmt