pub struct DesktopApp { /* private fields */ }Expand description
A small convenience wrapper around common Windows desktop app identity tasks.
DesktopApp keeps a validated app identity in one place and uses it for app-data
paths and single-instance locking. It does not own any global state.
§Examples
let app = win_desktop_utils::DesktopApp::new(format!(
"demo-app-{}",
std::process::id()
))?;
let local = app.ensure_local_data_dir()?;
assert!(local.exists());Implementations§
Source§impl DesktopApp
impl DesktopApp
Sourcepub fn new(app_name: impl Into<String>) -> Result<Self>
pub fn new(app_name: impl Into<String>) -> Result<Self>
Creates a desktop app identity without a company namespace.
§Errors
Returns Error::InvalidInput if app_name is empty, contains NUL bytes,
or contains characters that are invalid in Windows file names.
Sourcepub fn with_company(
company_name: impl Into<String>,
app_name: impl Into<String>,
) -> Result<Self>
pub fn with_company( company_name: impl Into<String>, app_name: impl Into<String>, ) -> Result<Self>
Creates a desktop app identity grouped under a company namespace.
App-data paths are nested as Company\App, while the default single-instance
mutex ID uses Company.App.
§Errors
Returns Error::InvalidInput if either identity part is empty, contains NUL
bytes, or contains characters that are invalid in Windows file names.
Sourcepub fn instance_scope(self, scope: InstanceScope) -> Self
pub fn instance_scope(self, scope: InstanceScope) -> Self
Sets the default single-instance mutex namespace scope used by Self::single_instance.
Sourcepub fn company_name(&self) -> Option<&str>
pub fn company_name(&self) -> Option<&str>
Returns the optional company name.
Sourcepub fn app_dir_name(&self) -> &str
pub fn app_dir_name(&self) -> &str
Returns the app-data directory name used by the paths helpers.
Sourcepub fn configured_instance_scope(&self) -> InstanceScope
pub fn configured_instance_scope(&self) -> InstanceScope
Returns the configured single-instance scope.
Sourcepub fn local_data_dir(&self) -> Result<PathBuf>
pub fn local_data_dir(&self) -> Result<PathBuf>
Returns the per-user local app-data directory for this app without creating it.
Sourcepub fn roaming_data_dir(&self) -> Result<PathBuf>
pub fn roaming_data_dir(&self) -> Result<PathBuf>
Returns the per-user roaming app-data directory for this app without creating it.
Sourcepub fn ensure_local_data_dir(&self) -> Result<PathBuf>
pub fn ensure_local_data_dir(&self) -> Result<PathBuf>
Creates and returns the per-user local app-data directory for this app.
Sourcepub fn ensure_roaming_data_dir(&self) -> Result<PathBuf>
pub fn ensure_roaming_data_dir(&self) -> Result<PathBuf>
Creates and returns the per-user roaming app-data directory for this app.
Sourcepub fn single_instance_options(&self) -> SingleInstanceOptions
pub fn single_instance_options(&self) -> SingleInstanceOptions
Returns single-instance options for this app.
Sourcepub fn single_instance(&self) -> Result<Option<InstanceGuard>>
pub fn single_instance(&self) -> Result<Option<InstanceGuard>>
Attempts to acquire the configured single-instance guard for this app.
Trait Implementations§
Source§impl Clone for DesktopApp
impl Clone for DesktopApp
Source§fn clone(&self) -> DesktopApp
fn clone(&self) -> DesktopApp
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more