autostart
This commit is contained in:
parent
9d01cbf57e
commit
0551a18cc9
6 changed files with 69 additions and 10 deletions
|
@ -302,6 +302,7 @@
|
|||
],
|
||||
"user": {
|
||||
"preferences": {
|
||||
"autostart": false,
|
||||
"acceptMessage": "",
|
||||
"contact": "",
|
||||
"downloadRate": null,
|
||||
|
|
13
ctl
13
ctl
|
@ -150,6 +150,19 @@ if [ "$1" == "open" ]; then
|
|||
fi
|
||||
exit 0
|
||||
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
|
||||
shift
|
||||
python3 "$NAME/oml/ui.py" $@
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import os
|
||||
from os.path import dirname, abspath
|
||||
import subprocess
|
||||
import time
|
||||
import sys
|
||||
import webbrowser
|
||||
|
||||
import gi
|
||||
|
@ -26,7 +26,8 @@ class OMLIcon:
|
|||
icon = None
|
||||
indicator = None
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, autostart=False):
|
||||
self.autostart = autostart
|
||||
if appindicator:
|
||||
self.indicator = appindicator.Indicator.new("OML", icon,
|
||||
appindicator.IndicatorCategory.APPLICATION_STATUS)
|
||||
|
@ -40,6 +41,7 @@ class OMLIcon:
|
|||
self.icon.connect("activate", self._click)
|
||||
self.icon.connect("popup-menu", self._click)
|
||||
subprocess.Popen([ctl, 'start'])
|
||||
if not self.autostart:
|
||||
GLib.timeout_add_seconds(1, self._open, None)
|
||||
GLib.timeout_add_seconds(60, self._check, None)
|
||||
|
||||
|
@ -85,5 +87,7 @@ class OMLIcon:
|
|||
webbrowser.open_new_tab(url)
|
||||
self.menu = None
|
||||
|
||||
OMLIcon()
|
||||
if __name__ == '__main__':
|
||||
autostart = len(sys.argv) > 1 and sys.argv[1] == '--autostart'
|
||||
OMLIcon(autostart)
|
||||
Gtk.main()
|
||||
|
|
|
@ -7,15 +7,16 @@ from utils import run
|
|||
|
||||
root_dir = os.path.dirname(settings.base_dir)
|
||||
|
||||
def install_launcher():
|
||||
def install_autostart():
|
||||
if sys.platform == 'darwin':
|
||||
install_launchd()
|
||||
elif sys.platform.startswith('linux'):
|
||||
install_xdg()
|
||||
install_autostart_xdg()
|
||||
else:
|
||||
print('no launcher integration supported for %s' % sys.platform)
|
||||
|
||||
def uninstall_launcher():
|
||||
|
||||
def uninstall_autostart():
|
||||
if sys.platform == 'darwin':
|
||||
name = 'com.openmedialibrary.loginscript'
|
||||
plist = os.path.expanduser('~/Library/LaunchAgents/%s.plist'%name)
|
||||
|
@ -25,12 +26,25 @@ def uninstall_launcher():
|
|||
os.unlink(plist)
|
||||
elif sys.platform.startswith('linux'):
|
||||
for f in map(os.path.expanduser, [
|
||||
'~/.local/share/applications/openmedialibrary.desktop',
|
||||
'~/.config/autostart/openmedialibrary.desktop'
|
||||
]):
|
||||
if os.path.exists(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():
|
||||
return
|
||||
name = 'com.openmedialibrary.loginscript'
|
||||
|
@ -48,7 +62,7 @@ def install_launchd():
|
|||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>%s/ctl</string>
|
||||
<string>start</string>
|
||||
<string>autostart</string>
|
||||
</array>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
|
@ -72,3 +86,16 @@ Terminal=false
|
|||
Categories=Network;FileTransfer;P2P;
|
||||
''' % {'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})
|
||||
|
|
|
@ -66,6 +66,8 @@ def setPreferences(data):
|
|||
data['contact'] != settings.preferences['contact']
|
||||
change_username = 'username' in data and \
|
||||
data['username'] != settings.preferences['username']
|
||||
change_autostart = 'autostart' in data and \
|
||||
data['autostart'] != settings.preferences['autostart']
|
||||
if 'libraryPath' in data and \
|
||||
data['libraryPath'] != settings.preferences['libraryPath']:
|
||||
change_path = [settings.preferences['libraryPath'], data['libraryPath']]
|
||||
|
@ -82,6 +84,12 @@ def setPreferences(data):
|
|||
Changelog.record(state.user(), 'editcontact', data['contact'])
|
||||
if 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
|
||||
actions.register(setPreferences, cache=False)
|
||||
|
||||
|
|
|
@ -136,6 +136,12 @@ oml.ui.preferencesPanel = function() {
|
|||
}
|
||||
],
|
||||
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',
|
||||
title: 'Show Debug Menu',
|
||||
|
|
Loading…
Reference in a new issue