windows autostart

This commit is contained in:
j 2016-04-14 21:27:30 +02:00
parent 0551a18cc9
commit 18aebe76d3
5 changed files with 67 additions and 4 deletions

View file

@ -74,6 +74,14 @@ def command_restart(*args):
Restart Open Media Libary
"""
if sys.platform == 'win32':
from urllib.request import urlopen
from urllib.parse import urlencode
url = 'http://{address}:{port}/api/'.format(**settings.server)
data = urlencode({'action': 'quit', 'data': '{}'}).encode()
try:
urlopen(url, data, timeout=2)
except:
pass
from utils import check_pid, ctl
pidfile = os.path.join(settings.data_path, 'openmedialibrary.pid')
try:

View file

@ -10,10 +10,13 @@ root_dir = os.path.dirname(settings.base_dir)
def install_autostart():
if sys.platform == 'darwin':
install_launchd()
elif sys.platform.startswith('linux'):
elif sys.platform == 'win32':
install_autostart_win32()
elif sys.platform.startswith('linux') or \
os.path.exists(os.path.expanduser('~/.config/autostart')):
install_autostart_xdg()
else:
print('no launcher integration supported for %s' % sys.platform)
print('no autostart support for %s' % sys.platform)
def uninstall_autostart():
@ -30,6 +33,10 @@ def uninstall_autostart():
]):
if os.path.exists(f):
os.unlink(f)
elif sys.platform == 'win32':
lnk = get_startup_path()
if os.path.exists(lnk):
os.unlink(lnk)
def install_launcher():
if sys.platform.startswith('linux'):
@ -99,3 +106,36 @@ Icon=%(base)s/openmedialibrary/static/png/oml.png
Terminal=false
X-GNOME-Autostart-enabled=true
''' % {'base': root_dir})
def get_trayicon_version():
from win32com.client import Dispatch
ver_parser = Dispatch('Scripting.FileSystemObject')
info = ver_parser.GetFileVersion(get_trayicon_path())
if info == 'No Version Information Available':
info = None
return info
def get_trayicon_path():
from win32com.client import Dispatch
shell = Dispatch("WScript.Shell")
applnk = os.path.join('C:\\', 'ProgramData', 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Open Media Library.lnk')
if applnk and os.path.exists(applnk):
app = shell.CreateShortCut(applnk)
target = app.Targetpath
return target
def get_startup_path():
#return os.path.join('C:\\', 'ProgramData', 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Startup', 'Open Media Library.lnk')
return os.path.join(os.getenv('APPDATA'), 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Startup', 'Open Media Library.lnk')
def install_autostart_win32():
from win32com.client import Dispatch
shell = Dispatch("WScript.Shell")
target = get_trayicon_path()
if target:
lnk = get_startup_path()
shortcut = shell.CreateShortCut(lnk)
shortcut.Targetpath = target
shortcut.Arguments = '--autostart'
shortcut.save()

View file

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from contextlib import closing
import base64
import json
@ -21,6 +20,7 @@ from oxtornado import actions
import settings
import utils
import db
from integration import get_trayicon_version
import logging
@ -234,8 +234,8 @@ def get_app_version(app):
return subprocess.check_output(cmd).strip()
def upgrade_app():
base = os.path.dirname(settings.base_dir)
if sys.platform == 'darwin':
base = os.path.dirname(settings.base_dir)
bundled_app = os.path.join(base, 'platform_darwin64/Applications/Open Media Library.app')
app = '/Applications/Open Media Library.app'
version = get_app_version(app)
@ -246,6 +246,15 @@ def upgrade_app():
shutil.copytree(bundled_app, app)
except:
logger.debug('Failed to update Application', exc_info=True)
elif sys.platform == 'win32':
current_version = get_trayicon_version()
if current_version != '0.2.0.0':
msi = os.path.normpath(os.path.join(base, 'platform_win32', 'Open Media Library.msi'))
cmd = ['msiexec.exe', '/qb', '/I', msi]
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
subprocess.Popen(cmd, cwd=settings.base_dir, start_new_session=True, startupinfo=startupinfo)
def getVersion(data):
'''

View file

@ -19,6 +19,8 @@ if sys.platform == 'win32':
return output_buf.value
else:
output_buf_size = needed
else:
def get_short_path_name(long_name):
return long_name

View file

@ -220,6 +220,10 @@
loadOMLFiles(function() {
initOML(data);
});
},
updatestatus: function(data) {
document.location.href = document.location.protocol + '//'
+ document.location.host;
}
});
}