pub struct Text<'a, 'b, 'c, 'd, 'e, 'f> {
pub android: AndroidText<'a, 'b, 'c>,
pub apple: &'d str,
pub windows: WindowsText<'e, 'f>,
}
pub struct AndroidText<'a, 'b, 'c> {
pub title: &'a str,
pub subtitle: Option<&'b str>,
pub description: Option<&'c str>,
}
pub struct WindowsText<'a, 'b> {
#[allow(dead_code)]
pub(crate) title: &'a str,
#[allow(dead_code)]
pub(crate) description: &'b str,
}
impl<'a, 'b> WindowsText<'a, 'b> {
#[cfg(target_os = "windows")]
pub const fn new(title: &'a str, description: &'b str) -> Option<Self> {
use windows::Win32::Security::Credentials::{
CREDUI_MAX_CAPTION_LENGTH, CREDUI_MAX_MESSAGE_LENGTH,
};
if title.len() <= CREDUI_MAX_CAPTION_LENGTH as usize
&& description.len() <= CREDUI_MAX_MESSAGE_LENGTH as usize
{
Some(Self { title, description })
} else {
None
}
}
#[cfg(not(target_os = "windows"))]
pub const fn new(title: &'a str, description: &'b str) -> Option<Self> {
Some(Self { title, description })
}
#[cfg(target_os = "windows")]
pub fn new_truncated(title: &'a str, description: &'b str) -> Self {
use windows::Win32::Security::Credentials::{
CREDUI_MAX_CAPTION_LENGTH, CREDUI_MAX_MESSAGE_LENGTH,
};
let title_max_len = std::cmp::min(CREDUI_MAX_CAPTION_LENGTH as usize, title.len());
let description_max_len = std::cmp::min(CREDUI_MAX_MESSAGE_LENGTH as usize, description.len());
Self {
title: &title[..title_max_len],
description: &description[..description_max_len],
}
}
#[cfg(not(target_os = "windows"))]
pub fn new_truncated(title: &'a str, description: &'b str) -> Self {
Self { title, description }
}
}