Skip to content

Commit

Permalink
chore: up
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Nov 24, 2024
1 parent 292571b commit 5dcb678
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const TASK_MANAGER_OVERRIDE_REGKEY: &str =
const TASK_MANAGER_OVERRIDE_ENABLED_VALUE: [u8; 12] = [
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
const E_ACCESSDENIED: u32 = 0x80070005;
const E_FILENOTFOUND: u32 = 0x80070002;
const E_ACCESSDENIED: HRESULT = HRESULT::from_win32(0x80070005_u32);
const E_FILENOTFOUND: HRESULT = HRESULT::from_win32(0x80070002_u32);

/// Windows implement
impl AutoLaunch {
Expand Down Expand Up @@ -41,7 +41,7 @@ impl AutoLaunch {
pub fn enable(&self) -> Result<()> {
self.enable_as_admin()
.or_else(|e| {
if e.code() == windows_result::HRESULT(E_ACCESSDENIED as i32) {
if e.code() == E_ACCESSDENIED {
self.enable_as_current_user()
} else {
Err(e)
Expand Down Expand Up @@ -92,7 +92,7 @@ impl AutoLaunch {
pub fn disable(&self) -> Result<()> {
self.disable_as_admin()
.or_else(|e| {
if e.code() == HRESULT(E_ACCESSDENIED as i32) {
if e.code() == E_ACCESSDENIED {
self.disable_as_current_user()
} else {
Err(e)
Expand All @@ -118,9 +118,7 @@ impl AutoLaunch {
pub fn is_enabled(&self) -> Result<bool> {
let res = match self.is_enabled_as_admin() {
Ok(false) => self.is_enabled_as_current_user(),
Err(e) if e.code() == HRESULT(E_ACCESSDENIED as i32) => {
self.is_enabled_as_current_user()
}
Err(e) if e.code() == E_ACCESSDENIED => self.is_enabled_as_current_user(),
Ok(enabled) => Ok(enabled),
Err(e) => Err(e),
}
Expand All @@ -134,7 +132,7 @@ impl AutoLaunch {
.get_string(&self.app_name)
.map(|_| true)
.or_else(|e| {
if e.code() == HRESULT(E_FILENOTFOUND as i32) {
if e.code() == E_FILENOTFOUND {
Ok(false)
} else {
Err(e)
Expand All @@ -152,7 +150,7 @@ impl AutoLaunch {
.get_string(&self.app_name)
.map(|_| true)
.or_else(|e| {
if e.code() == HRESULT(E_FILENOTFOUND as i32) {
if e.code() == E_FILENOTFOUND {
Ok(false)
} else {
Err(e)
Expand Down

0 comments on commit 5dcb678

Please sign in to comment.