Skip to content

Commit

Permalink
fix(wm): ghost windows
Browse files Browse the repository at this point in the history
  • Loading branch information
eythaann committed Jan 16, 2025
1 parent 1fbfae8 commit 75a0c6c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 50 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
### refactor
- create separated system service to handle elevated actions.

###
- fix ghost windows caused by a refactor donde on v2.0.13

## [2.0.14]
### hotfix
- not creating the default (system) icon pack.
Expand Down
15 changes: 1 addition & 14 deletions src/background/windows_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,6 @@ impl WindowsApi {
Ok(())
}

pub fn close_handle(handle: HANDLE) -> Result<()> {
unsafe {
CloseHandle(handle)?;
}
Ok(())
}

fn process_handle(process_id: u32) -> Result<HANDLE> {
Self::open_process(PROCESS_QUERY_INFORMATION, false, process_id)
}
Expand All @@ -433,10 +426,8 @@ impl WindowsApi {
unsafe { GetDesktopWindow() }
}

pub fn window_is_uwp_suspended(hwnd: HWND) -> Result<bool> {
let (process_id, _) = Self::window_thread_process_id(hwnd);
pub fn is_process_frozen(process_id: u32) -> Result<bool> {
let handle = Self::open_process(PROCESS_QUERY_LIMITED_INFORMATION, false, process_id)?;

let is_frozen = unsafe {
let mut buffer: [PROCESS_EXTENDED_BASIC_INFORMATION; 1] = std::mem::zeroed();
let status = NtQueryInformationProcess(
Expand All @@ -458,8 +449,6 @@ impl WindowsApi {
let data = buffer[0];
data.Anonymous.Flags & ProcessInformationFlag::IsFrozen as u32 != 0
};

Self::close_handle(handle)?;
Ok(is_frozen)
}

Expand All @@ -472,8 +461,6 @@ impl WindowsApi {
unsafe {
QueryFullProcessImageNameW(handle, PROCESS_NAME_WIN32, PWSTR(text_ptr), &mut len)?;
}
Self::close_handle(handle)?;

Ok(String::from_utf16(&path[..len as usize])?)
}

Expand Down
47 changes: 21 additions & 26 deletions src/background/windows_api/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,42 +45,37 @@ impl Process {
self.0
}

fn with_handle<T, F>(&self, f: F) -> Result<T>
where
F: FnOnce(HANDLE) -> T,
{
let handle = WindowsApi::open_process(PROCESS_QUERY_INFORMATION, false, self.0)?;
let result = f(handle);
WindowsApi::close_handle(handle)?;
Ok(result)
pub fn handle(&self) -> Result<HANDLE> {
WindowsApi::open_process(PROCESS_QUERY_INFORMATION, false, self.0)
}

pub fn is_frozen(&self) -> Result<bool> {
WindowsApi::is_process_frozen(self.0)
}

pub fn package_family_name(&self) -> Result<String> {
self.with_handle(|hprocess| {
let mut len = 1024_u32;
let mut family_name = WindowsString::new_to_fill(len as usize);
unsafe { GetPackageFamilyName(hprocess, &mut len, family_name.as_pwstr()).ok()? };
Ok(family_name.to_string())
})?
let hprocess = self.handle()?;
let mut len = 1024_u32;
let mut family_name = WindowsString::new_to_fill(len as usize);
unsafe { GetPackageFamilyName(hprocess, &mut len, family_name.as_pwstr()).ok()? };
Ok(family_name.to_string())
}

pub fn package_full_name(&self) -> Result<String> {
self.with_handle(|hprocess| {
let mut len = 1024_u32;
let mut family_name = WindowsString::new_to_fill(len as usize);
unsafe { GetPackageFullName(hprocess, &mut len, family_name.as_pwstr()).ok()? };
Ok(family_name.to_string())
})?
let hprocess = self.handle()?;
let mut len = 1024_u32;
let mut family_name = WindowsString::new_to_fill(len as usize);
unsafe { GetPackageFullName(hprocess, &mut len, family_name.as_pwstr()).ok()? };
Ok(family_name.to_string())
}

/// package app user model id
pub fn package_app_user_model_id(&self) -> Result<String> {
self.with_handle(|hprocess| {
let mut len = 1024_u32;
let mut id = WindowsString::new_to_fill(len as usize);
unsafe { GetApplicationUserModelId(hprocess, &mut len, id.as_pwstr()).ok()? };
Ok(id.to_string())
})?
let hprocess = self.handle()?;
let mut len = 1024_u32;
let mut id = WindowsString::new_to_fill(len as usize);
unsafe { GetApplicationUserModelId(hprocess, &mut len, id.as_pwstr()).ok()? };
Ok(id.to_string())
}

pub fn package_app_info(&self) -> Result<AppInfo> {
Expand Down
12 changes: 2 additions & 10 deletions src/background/windows_api/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,24 +258,16 @@ impl Window {
return false;
}

/* if let Ok(frame_creator) = window.get_frame_creator() {
if let Ok(frame_creator) = self.get_frame_creator() {
if frame_creator.is_none() {
return false;
}
}

if WindowsApi::window_is_uwp_suspended(window.hwnd()).unwrap_or_default() {
if self.process().is_frozen().unwrap_or(false) {
return false;
} */

/* if let Some(config) = FULL_STATE.load().get_app_config_by_window(hwnd) {
if config.options.contains(&AppExtraFlag::Hidden) {
log::trace!("Skipping by config: {:?}", window);
return false;
}
}

!TITLE_BLACK_LIST.contains(&window.title().as_str()) */
true
}
}

0 comments on commit 75a0c6c

Please sign in to comment.