Skip to content

Commit

Permalink
fix to hide daily popup ad (fix #62)
Browse files Browse the repository at this point in the history
  • Loading branch information
blurfx committed Apr 23, 2024
1 parent 38c0952 commit c08fd31
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
36 changes: 12 additions & 24 deletions internal/ad.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,6 @@ const (
MainViewPadding = 31
)

func HidePopupAd() {
var popupHandle windows.HWND
for {
popupHandle = winapi.FindWindowEx(0, popupHandle, "", "")
if popupHandle == 0 {
break
}
if winapi.GetParent(popupHandle) != 0 {
continue
}
className := winapi.GetClassName(popupHandle)
if !strings.Contains(className, "RichPopWnd") {
continue
}
rect := new(winapi.Rect)
_ = winapi.GetWindowRect(popupHandle, rect)
width := rect.Right - rect.Left
height := rect.Bottom - rect.Top
if width == 300 && height == 150 {
winapi.SendMessage(popupHandle, winapi.WmClose, 0, 0)
}
}
}

func HideMainWindowAd(windowClass string, handle windows.HWND) {
// @deprecated
if windowClass == "BannerAdWnd" {
Expand Down Expand Up @@ -70,3 +46,15 @@ func HideMainViewAdArea(windowText string, rect *winapi.Rect, handle windows.HWN
winapi.SetWindowPos(handle, 0, 0, 0, width, height, winapi.SwpNomove)
}
}

func HidePopupAd(windowClass string, handle windows.HWND) {
if windowClass == "AdFitWebView" {
parentHandle := winapi.GetParent(handle)
winapi.SendMessage(parentHandle, winapi.WmClose, 0, 0)
winapi.ShowWindow(parentHandle, 0)
winapi.MoveWindow(parentHandle, 0, 0, 0, 0, true)
winapi.SendMessage(handle, winapi.WmClose, 0, 0)
winapi.ShowWindow(handle, 0)
winapi.MoveWindow(handle, 0, 0, 0, 0, true)
}
}
2 changes: 1 addition & 1 deletion internal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func removeAd() {
HideMainWindowAd(className, childHandle)
HideMainViewAdArea(windowText, rect, childHandle)
HideLockScreenAdArea(windowText, rect, childHandle)
HidePopupAd(className, childHandle)
}
if mainWindowParentHandle != 0 && len(candidates) > 0 {
for _, candidate := range candidates {
Expand All @@ -116,7 +117,6 @@ func removeAd() {
}
}
}
HidePopupAd()
mutex.Unlock()
time.Sleep(sleepTime)
}
Expand Down

0 comments on commit c08fd31

Please sign in to comment.