generated from marc2332/tauri-deno-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from SARDONYX-sard/feature/revert-interval-pat…
…tern Feature/revert interval pattern
- Loading branch information
Showing
19 changed files
with
387 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/// Convert address(`de:ad:be:ee:ee:ef`) of string (e.g., `Bluetooth#Bluetooth00:00:00:ff:ff:00-de:ad:be:ee:ee:ef`) into a [u64]. | ||
pub fn id_to_address(id: &mut &str) -> winnow::PResult<u64> { | ||
use winnow::prelude::Parser as _; | ||
|
||
let input = id; | ||
let prefix = "Bluetooth#Bluetooth"; | ||
let _ = (prefix, hex_address, '-').parse_next(input)?; | ||
|
||
// Convert address string (e.g., "00:00:00:ff:ff:00") into a u64. | ||
let address = hex_address.parse_next(input)?; | ||
let combined = ((address.0 as u64) << 40) | ||
| ((address.1 as u64) << 32) | ||
| ((address.2 as u64) << 24) | ||
| ((address.3 as u64) << 16) | ||
| ((address.4 as u64) << 8) | ||
| (address.5 as u64); | ||
Ok(combined) | ||
} | ||
|
||
fn hex_primary(input: &mut &str) -> winnow::PResult<u8> { | ||
use winnow::token::take_while; | ||
use winnow::Parser; | ||
|
||
take_while(2, |c: char| c.is_ascii_hexdigit()) | ||
.try_map(|input| u8::from_str_radix(input, 16)) | ||
.parse_next(input) | ||
} | ||
|
||
/// Parse hex address e.g. `de:ad:be:ee:ee:ef` | ||
fn hex_address(input: &mut &str) -> winnow::PResult<(u8, u8, u8, u8, u8, u8)> { | ||
use winnow::seq; | ||
use winnow::Parser as _; | ||
|
||
seq! { | ||
hex_primary, | ||
_: ':', | ||
hex_primary, | ||
_: ':', | ||
hex_primary, | ||
_: ':', | ||
|
||
hex_primary, | ||
_: ':', | ||
hex_primary, | ||
_: ':', | ||
hex_primary, | ||
} | ||
.parse_next(input) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use winnow::Parser as _; | ||
|
||
#[test] | ||
fn test_id_to_address() { | ||
let id = "Bluetooth#Bluetooth00:00:00:ff:ff:00-de:ad:be:ee:ee:ef"; | ||
let address = id_to_address | ||
.parse(id) | ||
.unwrap_or_else(|err| panic!("{err}")); | ||
assert_eq!(address, 0xdeadbeeeeeef); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use windows::core::{IInspectable, Interface as _, HSTRING}; | ||
use windows::Foundation::Collections::IKeyValuePair; | ||
use windows::Foundation::IReference; | ||
|
||
use crate::device::device_info::LocalTime; | ||
|
||
/// print property key and value. | ||
/// | ||
/// # Errors | ||
/// If failed to type cast | ||
pub fn reveal_value(prop: IKeyValuePair<HSTRING, IInspectable>) -> windows::core::Result<()> { | ||
let key = prop.Key()?; | ||
let value = prop.Value()?; | ||
|
||
match value.GetRuntimeClassName()?.to_string().as_str() { | ||
"Windows.Foundation.IReference`1<Boolean>" => { | ||
let val: bool = value.cast::<IReference<bool>>()?.Value()?; | ||
println!("{} = {} (Boolean)", key, val); | ||
} | ||
"Windows.Foundation.IReference`1<String>" => { | ||
let val: HSTRING = value.cast::<IReference<HSTRING>>()?.Value()?; | ||
println!("{} = {} (String)", key, val); | ||
} | ||
"Windows.Foundation.IReference`1<UInt8>" => { | ||
let val: u8 = value.cast::<IReference<u8>>()?.Value()?; | ||
println!("{} = {} (UInt8)", key, val); | ||
} | ||
"Windows.Foundation.IReference`1<Windows.Foundation.DateTime>" => { | ||
let val = value | ||
.cast::<IReference<windows::Foundation::DateTime>>()? | ||
.Value()?; | ||
|
||
let utc_time = windows_datetime_to_chrono(val.UniversalTime); | ||
println!("{} = {:?} (DateTime)", key, LocalTime::from_utc(&utc_time)); | ||
} | ||
unknown => { | ||
println!("{key} = <Unknown Type: {unknown}>"); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn windows_datetime_to_chrono(universal_time: i64) -> chrono::DateTime<chrono::Utc> { | ||
use chrono::TimeZone as _; | ||
// Windows FILETIME epoch (1601-01-01) to Unix epoch (1970-01-01) in 100ns units | ||
const EPOCH_DIFFERENCE_100NS: i64 = 11_644_473_600 * 10_000_000; | ||
// Adjust to Unix epoch | ||
let unix_time_100ns = universal_time - EPOCH_DIFFERENCE_100NS; | ||
// Convert 100ns to seconds and nanoseconds | ||
let seconds = unix_time_100ns / 10_000_000; | ||
let nanoseconds = (unix_time_100ns % 10_000_000) * 100; | ||
// Create chrono::DateTime | ||
chrono::Utc | ||
.timestamp_opt(seconds, nanoseconds as u32) | ||
.unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
mod address_parser; | ||
pub mod device_info; | ||
pub mod device_searcher; | ||
mod device_searcher; | ||
pub mod inspect; | ||
pub mod watch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
"LOCALMFG", | ||
"PCSTR", | ||
"PCWSTR", | ||
"PKEY", | ||
"repr", | ||
"serde", | ||
"tauri", | ||
|
Oops, something went wrong.