Add tray icon again when explorer restarted (#639)
* 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.
This commit is contained in:
parent
c076f605aa
commit
4f3282099f
2 changed files with 16 additions and 66 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -24,4 +24,7 @@ tools/tor/*exe
|
||||||
tools/tor/*dll
|
tools/tor/*dll
|
||||||
|
|
||||||
# PhantomJS, downloaded manually for unit tests
|
# PhantomJS, downloaded manually for unit tests
|
||||||
tools/phantomjs
|
tools/phantomjs
|
||||||
|
|
||||||
|
# ZeroNet config file
|
||||||
|
zeronet.conf
|
||||||
|
|
|
@ -463,74 +463,17 @@ class WNDCLASSEX(ctypes.Structure):
|
||||||
("lpszClassName", ctypes.wintypes.LPCWSTR),
|
("lpszClassName", ctypes.wintypes.LPCWSTR),
|
||||||
("hIconSm", ctypes.wintypes.HANDLE)]
|
("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 = ctypes.windll.user32.ShowWindow
|
||||||
ShowWindow.argtypes = [ctypes.wintypes.HWND, ctypes.c_int]
|
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):
|
def GenerateDummyWindow(callback, uid):
|
||||||
newclass = WNDCLASSEX()
|
newclass = WNDCLASSEX()
|
||||||
newclass.lpfnWndProc = callback
|
newclass.lpfnWndProc = callback
|
||||||
newclass.style = CS_VREDRAW | CS_HREDRAW
|
|
||||||
newclass.lpszClassName = uid.replace("-", "")
|
newclass.lpszClassName = uid.replace("-", "")
|
||||||
newclass.hBrush = COLOR_BACKGROUND
|
|
||||||
newclass.hCursor = LoadCursor(0, 32512)
|
|
||||||
ATOM = ctypes.windll.user32.RegisterClassExW(ctypes.byref(newclass))
|
ATOM = ctypes.windll.user32.RegisterClassExW(ctypes.byref(newclass))
|
||||||
#print "ATOM", ATOM
|
#print "ATOM", ATOM
|
||||||
#print "CLASS", newclass.lpszClassName
|
#print "CLASS", newclass.lpszClassName
|
||||||
hwnd = ctypes.windll.user32.CreateWindowExW(0,
|
hwnd = ctypes.windll.user32.CreateWindowExW(0, newclass.lpszClassName, None, WS_POPUP, 0, 0, 0, 0, 0, 0, 0, 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)
|
|
||||||
return hwnd
|
return hwnd
|
||||||
|
|
||||||
# Message loop calls
|
# Message loop calls
|
||||||
|
@ -613,6 +556,8 @@ class NotificationIcon(object):
|
||||||
|
|
||||||
|
|
||||||
def _run(self):
|
def _run(self):
|
||||||
|
self.WM_TASKBARCREATED = ctypes.windll.user32.RegisterWindowMessageW(u'TaskbarCreated')
|
||||||
|
|
||||||
self._windowproc = WNDPROC(self._callback)
|
self._windowproc = WNDPROC(self._callback)
|
||||||
self._hwnd = GenerateDummyWindow(self._windowproc, str(self._uid))
|
self._hwnd = GenerateDummyWindow(self._windowproc, str(self._uid))
|
||||||
|
|
||||||
|
@ -623,16 +568,16 @@ class NotificationIcon(object):
|
||||||
iconinfo.uCallbackMessage = WM_MENUCOMMAND
|
iconinfo.uCallbackMessage = WM_MENUCOMMAND
|
||||||
iconinfo.hIcon = self._hicon
|
iconinfo.hIcon = self._hicon
|
||||||
iconinfo.szTip = self._tooltip
|
iconinfo.szTip = self._tooltip
|
||||||
iconinfo.dwState = NIS_SHAREDICON
|
#iconinfo.dwState = NIS_SHAREDICON
|
||||||
iconinfo.dwInfoFlags = NIIF_INFO
|
#iconinfo.dwInfoFlags = NIIF_INFO
|
||||||
# iconinfo.dwStateMask = NIS_SHAREDICON
|
#iconinfo.dwStateMask = NIS_SHAREDICON
|
||||||
iconinfo.szInfo = "Application Title"
|
#iconinfo.szInfo = "Application Title"
|
||||||
iconinfo.union.uTimeout = 5000
|
#iconinfo.union.uTimeout = 5000
|
||||||
|
|
||||||
Shell_NotifyIcon(NIM_ADD, ctypes.pointer(iconinfo))
|
Shell_NotifyIcon(NIM_ADD, ctypes.pointer(iconinfo))
|
||||||
|
|
||||||
iconinfo.union.uVersion = NOTIFYICON_VERSION
|
#iconinfo.union.uVersion = NOTIFYICON_VERSION
|
||||||
Shell_NotifyIcon(NIM_SETVERSION, ctypes.pointer(iconinfo))
|
#Shell_NotifyIcon(NIM_SETVERSION, ctypes.pointer(iconinfo))
|
||||||
self.iconinfo = iconinfo
|
self.iconinfo = iconinfo
|
||||||
|
|
||||||
PostMessage(self._hwnd, WM_NULL, 0, 0)
|
PostMessage(self._hwnd, WM_NULL, 0, 0)
|
||||||
|
@ -732,6 +677,8 @@ class NotificationIcon(object):
|
||||||
self.clicked()
|
self.clicked()
|
||||||
elif msg == WM_MENUCOMMAND and lParam == WM_RBUTTONUP:
|
elif msg == WM_MENUCOMMAND and lParam == WM_RBUTTONUP:
|
||||||
self._menu()
|
self._menu()
|
||||||
|
elif msg == self.WM_TASKBARCREATED: # Explorer restarted, add the icon again.
|
||||||
|
Shell_NotifyIcon(NIM_ADD, ctypes.pointer(self.iconinfo))
|
||||||
else:
|
else:
|
||||||
return DefWindowProc(hWnd, msg, wParam, lParam)
|
return DefWindowProc(hWnd, msg, wParam, lParam)
|
||||||
return 1
|
return 1
|
||||||
|
|
Loading…
Reference in a new issue