diff --git a/Cargo.toml b/Cargo.toml index ba156ad..9ddd135 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pure_kakao" -version = "0.1.5" +version = "0.1.6" edition = "2021" [dependencies] diff --git a/README.md b/README.md index 58c9dbf..3227fcb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Pure-Kakao ![Generic badge](https://img.shields.io/badge/version-0.1.5-green.svg) +# Pure-Kakao ![Generic badge](https://img.shields.io/badge/version-0.1.6-green.svg) Simple & lightweight ad-remover for kakaotalk pc client, written in Rust diff --git a/src/main.rs b/src/main.rs index 7c54dbd..8c27678 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,78 +1,77 @@ #![windows_subsystem = "windows"] use std::{ - thread, time::Duration + thread, time::Duration }; use windows::{ - core::*, Win32::Foundation::*, Win32::Graphics::Gdi::*, Win32::UI::WindowsAndMessaging::* + core::*, Win32::Foundation::*, Win32::Graphics::Gdi::*, Win32::UI::WindowsAndMessaging::* }; fn main() { - let title = w!("카카오톡"); - - loop { - let pwnd = unsafe { FindWindowW(PCWSTR::null(), title) }; - - if pwnd == HWND(0) { - thread::sleep(Duration::from_secs(1)); - continue; - } - - _ = unsafe { EnumWindows(Some(check), LPARAM(pwnd.0)) }; - thread::sleep(Duration::from_millis(15)); - } + let title = w!("카카오톡"); + + loop { + let pwnd = unsafe { FindWindowW(PCWSTR::null(), title) }; + + if pwnd == HWND(0) { + thread::sleep(Duration::from_secs(1)); + continue; + } + + _ = unsafe { EnumWindows(Some(check), LPARAM(pwnd.0)) }; + thread::sleep(Duration::from_millis(15)); + } } unsafe extern "system" fn check(hwnd: HWND, param: LPARAM) -> BOOL { - let pwnd = HWND(param.0); + let pwnd = HWND(param.0); - if pwnd == GetParent(hwnd) { - let cwnd = GetWindow(hwnd, GW_CHILD); + if pwnd == GetParent(hwnd) { + let cwnd = GetWindow(hwnd, GW_CHILD); + let nwnd = GetWindow(hwnd, GW_HWNDNEXT); - if cwnd != HWND(0) { - hide(hwnd, pwnd); - return FALSE; - } - } + if cwnd != HWND(0) && nwnd == pwnd { + hide(hwnd, pwnd); + return FALSE; + } + } - TRUE + TRUE } fn hide(hwnd: HWND, pwnd: HWND) { - let mut cwnd = HWND(0); - let mut frame = RECT::default(); + let mut cwnd = HWND(0); + let mut frame = RECT::default(); - _ = unsafe { GetWindowRect(pwnd, &mut frame) }; - let kt_size = frame.bottom - frame.top; + _ = unsafe { GetWindowRect(pwnd, &mut frame) }; + let kt_size = frame.bottom - frame.top; - _ = unsafe { GetWindowRect(hwnd, &mut frame) }; - let ad_size = frame.bottom - frame.top; + _ = unsafe { GetWindowRect(hwnd, &mut frame) }; + let ad_size = frame.bottom - frame.top; - _ = unsafe { ShowWindow(hwnd, SW_HIDE) }; + _ = unsafe { ShowWindow(hwnd, SW_HIDE) }; - loop { - cwnd = unsafe { FindWindowExA(pwnd, cwnd, PCSTR::null(), PCSTR::null()) }; + loop { + cwnd = unsafe { FindWindowExA(pwnd, cwnd, PCSTR::null(), PCSTR::null()) }; - if cwnd == HWND(0) { - break; - } + if cwnd == HWND(0) { + break; + } - let size = unsafe { GetWindowTextLengthW(cwnd) } as usize; - let mut caption_vec = vec![0 as u16; size]; - _ = unsafe { GetWindowTextW(cwnd, &mut caption_vec) }; - let caption = String::from_utf16(&mut caption_vec).unwrap(); + let size = unsafe { GetWindowTextLengthW(cwnd) } as usize; + let mut caption_vec = vec![0 as u16; size]; + _ = unsafe { GetWindowTextW(cwnd, &mut caption_vec) }; + let caption = String::from_utf16(&mut caption_vec).unwrap(); - if caption.starts_with("OnlineMainView") || caption.starts_with("LockModeView") { - _ = unsafe { GetWindowRect(cwnd, &mut frame) }; - let wn_size = frame.bottom - frame.top; + if caption.starts_with("OnlineMainView") || caption.starts_with("LockModeView") { + _ = unsafe { GetWindowRect(cwnd, &mut frame) }; + let wn_size = frame.bottom - frame.top; - if wn_size != 0 && kt_size > wn_size + ad_size { - _ = unsafe { SetWindowPos(cwnd, HWND(0), 0, 0, frame.right - frame.left, wn_size + ad_size + 1, SWP_NOZORDER | SWP_NOMOVE) }; - } + if wn_size != 0 && kt_size > wn_size + ad_size { + _ = unsafe { SetWindowPos(cwnd, HWND(0), 0, 0, frame.right - frame.left, wn_size + ad_size + 1, SWP_NOZORDER | SWP_NOMOVE) }; + } _ = unsafe { RedrawWindow(cwnd, None, HRGN(0), RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN) }; - } else { - _ = unsafe { ShowWindow(cwnd, SW_HIDE) }; } - } + } } \ No newline at end of file