autostart

This commit is contained in:
j 2016-04-14 12:57:45 +02:00
parent 9d01cbf57e
commit 0551a18cc9
6 changed files with 69 additions and 10 deletions

View file

@ -302,6 +302,7 @@
], ],
"user": { "user": {
"preferences": { "preferences": {
"autostart": false,
"acceptMessage": "", "acceptMessage": "",
"contact": "", "contact": "",
"downloadRate": null, "downloadRate": null,

13
ctl
View file

@ -150,6 +150,19 @@ if [ "$1" == "open" ]; then
fi fi
exit 0 exit 0
fi fi
if [ "$1" == "autostart" ]; then
if [ $SYSTEM == "Darwin" ]; then
open "/Applications/Open Media Library.app" --args --autostart
fi
if [ $SYSTEM == "Linux" ]; then
if [ ! -e "$PID" ]; then
python3 "$NAME/oml/gtkstatus.py" --autostart
exit $?
fi
fi
exit 0
fi
if [ "$1" == "ui" ]; then if [ "$1" == "ui" ]; then
shift shift
python3 "$NAME/oml/ui.py" $@ python3 "$NAME/oml/ui.py" $@

View file

@ -2,7 +2,7 @@
import os import os
from os.path import dirname, abspath from os.path import dirname, abspath
import subprocess import subprocess
import time import sys
import webbrowser import webbrowser
import gi import gi
@ -26,7 +26,8 @@ class OMLIcon:
icon = None icon = None
indicator = None indicator = None
def __init__(self): def __init__(self, autostart=False):
self.autostart = autostart
if appindicator: if appindicator:
self.indicator = appindicator.Indicator.new("OML", icon, self.indicator = appindicator.Indicator.new("OML", icon,
appindicator.IndicatorCategory.APPLICATION_STATUS) appindicator.IndicatorCategory.APPLICATION_STATUS)
@ -40,7 +41,8 @@ class OMLIcon:
self.icon.connect("activate", self._click) self.icon.connect("activate", self._click)
self.icon.connect("popup-menu", self._click) self.icon.connect("popup-menu", self._click)
subprocess.Popen([ctl, 'start']) subprocess.Popen([ctl, 'start'])
GLib.timeout_add_seconds(1, self._open, None) if not self.autostart:
GLib.timeout_add_seconds(1, self._open, None)
GLib.timeout_add_seconds(60, self._check, None) GLib.timeout_add_seconds(60, self._check, None)
def _check(self, *args, **kwargs): def _check(self, *args, **kwargs):
@ -85,5 +87,7 @@ class OMLIcon:
webbrowser.open_new_tab(url) webbrowser.open_new_tab(url)
self.menu = None self.menu = None
OMLIcon() if __name__ == '__main__':
Gtk.main() autostart = len(sys.argv) > 1 and sys.argv[1] == '--autostart'
OMLIcon(autostart)
Gtk.main()

View file

@ -7,15 +7,16 @@ from utils import run
root_dir = os.path.dirname(settings.base_dir) root_dir = os.path.dirname(settings.base_dir)
def install_launcher(): def install_autostart():
if sys.platform == 'darwin': if sys.platform == 'darwin':
install_launchd() install_launchd()
elif sys.platform.startswith('linux'): elif sys.platform.startswith('linux'):
install_xdg() install_autostart_xdg()
else: else:
print('no launcher integration supported for %s' % sys.platform) print('no launcher integration supported for %s' % sys.platform)
def uninstall_launcher():
def uninstall_autostart():
if sys.platform == 'darwin': if sys.platform == 'darwin':
name = 'com.openmedialibrary.loginscript' name = 'com.openmedialibrary.loginscript'
plist = os.path.expanduser('~/Library/LaunchAgents/%s.plist'%name) plist = os.path.expanduser('~/Library/LaunchAgents/%s.plist'%name)
@ -25,12 +26,25 @@ def uninstall_launcher():
os.unlink(plist) os.unlink(plist)
elif sys.platform.startswith('linux'): elif sys.platform.startswith('linux'):
for f in map(os.path.expanduser, [ for f in map(os.path.expanduser, [
'~/.local/share/applications/openmedialibrary.desktop',
'~/.config/autostart/openmedialibrary.desktop' '~/.config/autostart/openmedialibrary.desktop'
]): ]):
if os.path.exists(f): if os.path.exists(f):
os.unlink(f) os.unlink(f)
def install_launcher():
if sys.platform.startswith('linux'):
install_xdg()
else:
print('no launcher integration supported for %s' % sys.platform)
def uninstall_launcher():
if sys.platform.startswith('linux'):
for f in map(os.path.expanduser, [
'~/.local/share/applications/openmedialibrary.desktop',
]):
if os.path.exists(f):
os.unlink(f)
def install_launchd(): def install_launchd():
return return
name = 'com.openmedialibrary.loginscript' name = 'com.openmedialibrary.loginscript'
@ -48,7 +62,7 @@ def install_launchd():
<key>ProgramArguments</key> <key>ProgramArguments</key>
<array> <array>
<string>%s/ctl</string> <string>%s/ctl</string>
<string>start</string> <string>autostart</string>
</array> </array>
<key>RunAtLoad</key> <key>RunAtLoad</key>
<true/> <true/>
@ -72,3 +86,16 @@ Terminal=false
Categories=Network;FileTransfer;P2P; Categories=Network;FileTransfer;P2P;
''' % {'base': root_dir}) ''' % {'base': root_dir})
def install_autostart_xdg():
app = os.path.expanduser('~/.config/autostart/openmedialibrary.desktop')
ox.makedirs(os.path.dirname(app))
with open(app, 'w') as fd:
fd.write('''[Desktop Entry]
Type=Application
Name=Open Media Library
Comment=
Exec=%(base)s/ctl autostart
Icon=%(base)s/openmedialibrary/static/png/oml.png
Terminal=false
X-GNOME-Autostart-enabled=true
''' % {'base': root_dir})

View file

@ -66,6 +66,8 @@ def setPreferences(data):
data['contact'] != settings.preferences['contact'] data['contact'] != settings.preferences['contact']
change_username = 'username' in data and \ change_username = 'username' in data and \
data['username'] != settings.preferences['username'] data['username'] != settings.preferences['username']
change_autostart = 'autostart' in data and \
data['autostart'] != settings.preferences['autostart']
if 'libraryPath' in data and \ if 'libraryPath' in data and \
data['libraryPath'] != settings.preferences['libraryPath']: data['libraryPath'] != settings.preferences['libraryPath']:
change_path = [settings.preferences['libraryPath'], data['libraryPath']] change_path = [settings.preferences['libraryPath'], data['libraryPath']]
@ -82,6 +84,12 @@ def setPreferences(data):
Changelog.record(state.user(), 'editcontact', data['contact']) Changelog.record(state.user(), 'editcontact', data['contact'])
if change_path: if change_path:
state.tasks.queue('changelibrarypath', change_path) state.tasks.queue('changelibrarypath', change_path)
if change_autostart:
import integration
if settings.preferences['autostart']:
integration.install_autostart()
else:
integration.uninstall_autostart()
return settings.preferences return settings.preferences
actions.register(setPreferences, cache=False) actions.register(setPreferences, cache=False)

View file

@ -136,6 +136,12 @@ oml.ui.preferencesPanel = function() {
} }
], ],
advanced: [ advanced: [
{
id: 'autostart',
title: 'Start Open Media Library at Login',
value: preferences.autostart,
help: 'Launch Open Media Library in the background once you login to your computer.'
},
{ {
id: 'showDebugMenu', id: 'showDebugMenu',
title: 'Show Debug Menu', title: 'Show Debug Menu',