-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
362 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.DS_Store | ||
.idea | ||
.DS_Store | ||
.idea | ||
*.syso | ||
*.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,11 @@ | ||
# KakaoTalkAdBlock | ||
|
||
AdBlocker for KakaoTalk Windows client. (native, alpha) | ||
|
||
## Update History | ||
|
||
- Go [Releases](https://github.com/blurfx/KakaoTalkAdBlock/releases) page | ||
|
||
## At a glance | ||
|
||
 | ||
|
||
This program runs in the tray. | ||
|
||
 | ||
# KakaoTalkAdBlock | ||
|
||
AdBlocker for KakaoTalk Windows client. | ||
|
||
## At a glance | ||
|
||
 | ||
|
||
This program runs in the tray. To exit, double-click the tray icon. | ||
|
||
 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@echo off | ||
|
||
pushd winres | ||
|
||
go-winres simply -icon=icon.ico | ||
|
||
popd | ||
|
||
go build -o KakaoTalkAdBlock.exe -ldflags "-H windowsgui -s -w" .\cmd\main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package win | ||
|
||
import ( | ||
"unsafe" | ||
|
||
"golang.org/x/sys/windows" | ||
|
||
"kakaotalkadblock/internal/win/winapi" | ||
) | ||
|
||
var quit *chan struct{} | ||
|
||
func wndProc(hWnd uintptr, msg uint32, wParam, lParam uintptr) uintptr { | ||
switch msg { | ||
case winapi.WmTrayicon: | ||
switch uint16(lParam) { | ||
case winapi.WmLbuttondblclk: | ||
close(*quit) | ||
} | ||
case winapi.WmDestroy: | ||
winapi.PostQuitMessage(0) | ||
default: | ||
return winapi.DefWindowProc(hWnd, msg, wParam, lParam) | ||
} | ||
return 0 | ||
} | ||
|
||
func createMainWindow() (uintptr, error) { | ||
hInstance, err := winapi.GetModuleHandle(nil) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
wndClass, _ := windows.UTF16PtrFromString("KakaoTalkAdBlock") | ||
|
||
var windowClass winapi.WindowClassEx | ||
|
||
windowClass.CbSize = uint32(unsafe.Sizeof(windowClass)) | ||
windowClass.LpfnWndProc = windows.NewCallback(wndProc) | ||
windowClass.HInstance = hInstance | ||
windowClass.LpszClassName = wndClass | ||
if _, err := winapi.RegisterClassEx(&windowClass); err != nil { | ||
return 0, err | ||
} | ||
|
||
handle, err := winapi.CreateWindowEx( | ||
0, | ||
wndClass, | ||
windows.StringToUTF16Ptr("KakaoTalkAdBlock"), | ||
winapi.WsOverlappedwindow, | ||
winapi.CwUsedefault, | ||
winapi.CwUsedefault, | ||
1, | ||
1, | ||
0, | ||
0, | ||
hInstance, | ||
nil) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return handle, nil | ||
} | ||
|
||
type TrayIcon struct { | ||
notifyIconData winapi.NotifyIconData | ||
} | ||
|
||
func NewTrayIcon(quitChan *chan struct{}) *TrayIcon { | ||
var data winapi.NotifyIconData | ||
data.CbSize = uint32(unsafe.Sizeof(data)) | ||
data.UFlags = winapi.NifIcon | winapi.NifMessage | winapi.NifInfo | ||
data.UCallbackMessage = winapi.WmTrayicon | ||
|
||
hInst, err := winapi.GetModuleHandle(nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
icon, err := winapi.LoadIcon(hInst, winapi.MakeIntResource(1)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
data.HIcon = icon | ||
|
||
quit = quitChan | ||
return &TrayIcon{ | ||
notifyIconData: data, | ||
} | ||
} | ||
|
||
func (t *TrayIcon) Show() { | ||
if t.notifyIconData.HWnd == 0 { | ||
handle, err := createMainWindow() | ||
if err != nil { | ||
panic(err) | ||
} | ||
t.notifyIconData.HWnd = handle | ||
} | ||
if err := winapi.ShellNotifyIcon(winapi.NimAdd, &t.notifyIconData); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func (t *TrayIcon) Hide() { | ||
if err := winapi.ShellNotifyIcon(winapi.NimDelete, &t.notifyIconData); err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package winapi | ||
|
||
const ( | ||
Th32csSnapprocess = 0x2 | ||
MaxPath = 260 | ||
|
||
NimAdd = 0x00000000 | ||
NimDelete = 0x00000002 | ||
|
||
NifMessage = 0x00000001 | ||
NifIcon = 0x00000002 | ||
NifInfo = 0x00000010 | ||
|
||
CwUsedefault = ^0x7fffffff | ||
|
||
WsCaption = 0x00c00000 | ||
WsMaximizebox = 0x00010000 | ||
WsMinimizebox = 0x00020000 | ||
WsOverlapped = 0x00000000 | ||
WsSysmenu = 0x00080000 | ||
WsThickframe = 0x00040000 | ||
WsOverlappedwindow = WsOverlapped | WsCaption | WsSysmenu | WsThickframe | WsMinimizebox | WsMaximizebox | ||
|
||
WmDestroy = 0x0002 | ||
WmClose = 0x10 | ||
WmLbuttondblclk = 0x0203 | ||
WmApp = 0x8000 | ||
WmTrayicon = WmApp + 1 | ||
|
||
SwpNomove = 0x0002 | ||
) |
Oops, something went wrong.