Skip to content

Commit

Permalink
Add tray icon again when explorer restarted (HelloZeroNet#639)
Browse files Browse the repository at this point in the history
* Add zeronet.conf to .gitignore

* notificationicon.py - Remove unnecessary window size and 'ShowWindow' etc.

* notificationicon.py - Comment unnecessary iconinfo and NIM_SETVERSION.

* notificationicon.py - Add tray icon again when explorer restarted.
  • Loading branch information
ysc3839 authored and HelloZeroNet committed Nov 11, 2016
1 parent c076f60 commit 4f32820
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 66 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ tools/tor/*exe
tools/tor/*dll

# PhantomJS, downloaded manually for unit tests
tools/phantomjs
tools/phantomjs

# ZeroNet config file
zeronet.conf
77 changes: 12 additions & 65 deletions plugins/Trayicon/lib/notificationicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,74 +463,17 @@ def __init__(self, *args, **kwargs):
("lpszClassName", ctypes.wintypes.LPCWSTR),
("hIconSm", ctypes.wintypes.HANDLE)]

UpdateWindow = ctypes.windll.user32.UpdateWindow
UpdateWindow.argtypes = [ctypes.wintypes.HWND]

SW_HIDE = 0
SW_SHOWNORMAL = 1
SW_SHOW = 5

ShowWindow = ctypes.windll.user32.ShowWindow
ShowWindow.argtypes = [ctypes.wintypes.HWND, ctypes.c_int]

CS_VREDRAW = 0x0001
CS_HREDRAW = 0x0002
CS_KEYCVTWINDOW = 0x0004
CS_DBLCLKS = 0x0008
CS_OWNDC = 0x0020
CS_CLASSDC = 0x0040
CS_PARENTDC = 0x0080
CS_NOKEYCVT = 0x0100
CS_NOCLOSE = 0x0200
CS_SAVEBITS = 0x0800
CS_BYTEALIGNCLIENT = 0x1000
CS_BYTEALIGNWINDOW = 0x2000
CS_GLOBALCLASS = 0x4000

COLOR_SCROLLBAR = 0
COLOR_BACKGROUND = 1
COLOR_ACTIVECAPTION = 2
COLOR_INACTIVECAPTION = 3
COLOR_MENU = 4
COLOR_WINDOW = 5
COLOR_WINDOWFRAME = 6
COLOR_MENUTEXT = 7
COLOR_WINDOWTEXT = 8
COLOR_CAPTIONTEXT = 9
COLOR_ACTIVEBORDER = 10
COLOR_INACTIVEBORDER = 11
COLOR_APPWORKSPACE = 12
COLOR_HIGHLIGHT = 13
COLOR_HIGHLIGHTTEXT = 14
COLOR_BTNFACE = 15
COLOR_BTNSHADOW = 16
COLOR_GRAYTEXT = 17
COLOR_BTNTEXT = 18
COLOR_INACTIVECAPTIONTEXT = 19
COLOR_BTNHIGHLIGHT = 20

LoadCursor = ctypes.windll.user32.LoadCursorW

def GenerateDummyWindow(callback, uid):
newclass = WNDCLASSEX()
newclass.lpfnWndProc = callback
newclass.style = CS_VREDRAW | CS_HREDRAW
newclass.lpszClassName = uid.replace("-", "")
newclass.hBrush = COLOR_BACKGROUND
newclass.hCursor = LoadCursor(0, 32512)
ATOM = ctypes.windll.user32.RegisterClassExW(ctypes.byref(newclass))
#print "ATOM", ATOM
#print "CLASS", newclass.lpszClassName
hwnd = ctypes.windll.user32.CreateWindowExW(0,
newclass.lpszClassName,
u"Dummy Window",
WS_OVERLAPPEDWINDOW | WS_SYSMENU,
ctypes.windll.user32.GetSystemMetrics(SM_CXVIRTUALSCREEN),
ctypes.windll.user32.GetSystemMetrics(SM_CYVIRTUALSCREEN),
800, 600, 0, 0, 0, 0)
ShowWindow(hwnd, SW_SHOW)
UpdateWindow(hwnd)
ShowWindow(hwnd, SW_HIDE)
hwnd = ctypes.windll.user32.CreateWindowExW(0, newclass.lpszClassName, None, WS_POPUP, 0, 0, 0, 0, 0, 0, 0, 0)
return hwnd

# Message loop calls
Expand Down Expand Up @@ -613,6 +556,8 @@ def _bubble(self, iconinfo):


def _run(self):
self.WM_TASKBARCREATED = ctypes.windll.user32.RegisterWindowMessageW(u'TaskbarCreated')

self._windowproc = WNDPROC(self._callback)
self._hwnd = GenerateDummyWindow(self._windowproc, str(self._uid))

Expand All @@ -623,16 +568,16 @@ def _run(self):
iconinfo.uCallbackMessage = WM_MENUCOMMAND
iconinfo.hIcon = self._hicon
iconinfo.szTip = self._tooltip
iconinfo.dwState = NIS_SHAREDICON
iconinfo.dwInfoFlags = NIIF_INFO
# iconinfo.dwStateMask = NIS_SHAREDICON
iconinfo.szInfo = "Application Title"
iconinfo.union.uTimeout = 5000
#iconinfo.dwState = NIS_SHAREDICON
#iconinfo.dwInfoFlags = NIIF_INFO
#iconinfo.dwStateMask = NIS_SHAREDICON
#iconinfo.szInfo = "Application Title"
#iconinfo.union.uTimeout = 5000

Shell_NotifyIcon(NIM_ADD, ctypes.pointer(iconinfo))

iconinfo.union.uVersion = NOTIFYICON_VERSION
Shell_NotifyIcon(NIM_SETVERSION, ctypes.pointer(iconinfo))
#iconinfo.union.uVersion = NOTIFYICON_VERSION
#Shell_NotifyIcon(NIM_SETVERSION, ctypes.pointer(iconinfo))
self.iconinfo = iconinfo

PostMessage(self._hwnd, WM_NULL, 0, 0)
Expand Down Expand Up @@ -732,6 +677,8 @@ def _callback(self, hWnd, msg, wParam, lParam):
self.clicked()
elif msg == WM_MENUCOMMAND and lParam == WM_RBUTTONUP:
self._menu()
elif msg == self.WM_TASKBARCREATED: # Explorer restarted, add the icon again.
Shell_NotifyIcon(NIM_ADD, ctypes.pointer(self.iconinfo))
else:
return DefWindowProc(hWnd, msg, wParam, lParam)
return 1
Expand Down

0 comments on commit 4f32820

Please sign in to comment.