close tray icon if oml is gone

This commit is contained in:
j 2016-02-01 17:27:30 +05:30
parent 3d473b8765
commit 0f6b17e8cd
3 changed files with 37 additions and 5 deletions

View file

@ -4,6 +4,8 @@ import signal
import subprocess
import sys
import webbrowser
import time
from threading import Thread
import win32api
import win32con
@ -23,7 +25,8 @@ class OMLTrayIcon(object):
FIRST_ID = 1023
def __init__(self):
launch()
self.thread_id = win32api.GetCurrentThreadId()
launch(self)
name = "Open Media Library"
self.icon = "ico/oml.ico"
self.hover_text = name
@ -197,9 +200,30 @@ class OMLTrayIcon(object):
else:
menu_action(self)
def check_pid(pid):
def quit(self):
nid = (self.hwnd, 0)
win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, nid)
win32api.PostThreadMessage(self.thread_id, win32con.WM_QUIT, 0, 0)
class Check(Thread):
def __init__(self, parent, pid):
self.parent = parent
self.pid = pid
Thread.__init__(self)
self.daemon = True
self.start()
def run(self):
time.sleep(60)
while check_pid(self.pid):
time.sleep(60)
self.parent.quit()
def check_pid(pidfile):
if not os.path.exists(pidfile):
return False
try:
with open(pid) as fd:
with open(pidfile) as fd:
pid = int(fd.read())
except:
return False
@ -213,13 +237,15 @@ def check_pid(pid):
def launch(sysTrayIcon=None):
base = os.path.join(os.getenv('LOCALAPPDATA'), 'Open Media Library')
pid = os.path.join(base, 'data', 'openmedialibrary.pid')
if os.path.exists(pid) and check_pid(pid):
if check_pid(pid):
webbrowser.open_new_tab(os.path.join(base, 'openmedialibrary', 'static', 'html', 'load.html'))
sysTrayIcon._check = Check(sysTrayIcon, pid)
elif os.path.exists(base):
python = os.path.join(base, 'platform_win32', 'pythonw.exe')
oml = os.path.join(base, 'openmedialibrary')
subprocess.Popen([python, 'oml', 'server', pid], cwd=oml, start_new_session=True)
webbrowser.open_new_tab(os.path.join(base, 'openmedialibrary', 'static', 'html', 'load.html'))
sysTrayIcon._check = Check(sysTrayIcon, pid)
else:
install.run(base)

View file

@ -100,6 +100,12 @@ class Install(Thread):
self.status["release"] = release
self.status["progress"] = 0
platform = get_platform()
if not 'platform_win32' in release:
release['platform_win32'] = {
'name': 'platform_win32-20160201-3-3d473b8.tar.bz2',
'version': '20160201-3-3d473b8.tar.bz2',
'platform': 'win32',
}
for module in sorted(release['modules']):
if release['modules'][module].get('platform', platform) == platform:
package_tar = release['modules'][module]['name']

View file

@ -38,7 +38,7 @@ oml = Executable(
setup(
name = "Open Media Library",
version = "0.1",
description = "share media collectoins",
description = "Open Media Library",
options = {
"build_exe": build_exe_options,
"bdist_msi": bdist_msi_options