Browse Source

autostart

j 2 years ago
parent
commit
0551a18cc9
6 changed files with 69 additions and 10 deletions
  1. 1
    0
      config.json
  2. 13
    0
      ctl
  3. 9
    5
      oml/gtkstatus.py
  4. 32
    5
      oml/integration.py
  5. 8
    0
      oml/user/api.py
  6. 6
    0
      static/js/preferencesPanel.js

+ 1
- 0
config.json View File

@@ -302,6 +302,7 @@
302 302
     ],
303 303
     "user": {
304 304
         "preferences": {
305
+            "autostart": false,
305 306
             "acceptMessage": "",
306 307
             "contact": "",
307 308
             "downloadRate": null,

+ 13
- 0
ctl View File

@@ -150,6 +150,19 @@ if [ "$1" == "open" ]; then
150 150
     fi
151 151
     exit 0
152 152
 fi
153
+if [ "$1" == "autostart" ]; then
154
+    if [ $SYSTEM == "Darwin" ]; then
155
+        open "/Applications/Open Media Library.app" --args --autostart
156
+    fi
157
+    if [ $SYSTEM == "Linux" ]; then
158
+        if [ ! -e "$PID" ]; then
159
+            python3 "$NAME/oml/gtkstatus.py" --autostart
160
+            exit $?
161
+        fi
162
+    fi
163
+    exit 0
164
+fi
165
+
153 166
 if [ "$1" == "ui" ]; then
154 167
     shift
155 168
     python3 "$NAME/oml/ui.py" $@

+ 9
- 5
oml/gtkstatus.py View File

@@ -2,7 +2,7 @@
2 2
 import os
3 3
 from os.path import dirname, abspath
4 4
 import subprocess
5
-import time
5
+import sys
6 6
 import webbrowser
7 7
 
8 8
 import gi
@@ -26,7 +26,8 @@ class OMLIcon:
26 26
     icon = None
27 27
     indicator = None
28 28
 
29
-    def __init__(self):
29
+    def __init__(self, autostart=False):
30
+        self.autostart = autostart
30 31
         if appindicator:
31 32
             self.indicator = appindicator.Indicator.new("OML", icon,
32 33
                 appindicator.IndicatorCategory.APPLICATION_STATUS)
@@ -40,7 +41,8 @@ class OMLIcon:
40 41
             self.icon.connect("activate", self._click)
41 42
             self.icon.connect("popup-menu", self._click)
42 43
         subprocess.Popen([ctl, 'start'])
43
-        GLib.timeout_add_seconds(1, self._open, None)
44
+        if not self.autostart:
45
+            GLib.timeout_add_seconds(1, self._open, None)
44 46
         GLib.timeout_add_seconds(60, self._check, None)
45 47
 
46 48
     def _check(self, *args, **kwargs):
@@ -85,5 +87,7 @@ class OMLIcon:
85 87
         webbrowser.open_new_tab(url)
86 88
         self.menu = None
87 89
 
88
-OMLIcon()
89
-Gtk.main()
90
+if __name__ == '__main__':
91
+    autostart = len(sys.argv) > 1 and sys.argv[1] == '--autostart'
92
+    OMLIcon(autostart)
93
+    Gtk.main()

+ 32
- 5
oml/integration.py View File

@@ -7,15 +7,16 @@ from utils import run
7 7
 
8 8
 root_dir = os.path.dirname(settings.base_dir)
9 9
 
10
-def install_launcher():
10
+def install_autostart():
11 11
     if sys.platform == 'darwin':
12 12
         install_launchd()
13 13
     elif sys.platform.startswith('linux'):
14
-        install_xdg()
14
+        install_autostart_xdg()
15 15
     else:
16 16
         print('no launcher integration supported for %s' % sys.platform)
17 17
 
18
-def uninstall_launcher():
18
+
19
+def uninstall_autostart():
19 20
     if sys.platform == 'darwin':
20 21
         name = 'com.openmedialibrary.loginscript'
21 22
         plist = os.path.expanduser('~/Library/LaunchAgents/%s.plist'%name)
@@ -25,12 +26,25 @@ def uninstall_launcher():
25 26
             os.unlink(plist)
26 27
     elif sys.platform.startswith('linux'):
27 28
         for f in map(os.path.expanduser, [
28
-            '~/.local/share/applications/openmedialibrary.desktop',
29 29
             '~/.config/autostart/openmedialibrary.desktop'
30 30
         ]):
31 31
             if os.path.exists(f):
32 32
                 os.unlink(f)
33 33
 
34
+def install_launcher():
35
+    if sys.platform.startswith('linux'):
36
+        install_xdg()
37
+    else:
38
+        print('no launcher integration supported for %s' % sys.platform)
39
+
40
+def uninstall_launcher():
41
+    if sys.platform.startswith('linux'):
42
+        for f in map(os.path.expanduser, [
43
+            '~/.local/share/applications/openmedialibrary.desktop',
44
+        ]):
45
+            if os.path.exists(f):
46
+                os.unlink(f)
47
+
34 48
 def install_launchd():
35 49
     return
36 50
     name = 'com.openmedialibrary.loginscript'
@@ -48,7 +62,7 @@ def install_launchd():
48 62
     <key>ProgramArguments</key>
49 63
     <array>
50 64
         <string>%s/ctl</string>
51
-        <string>start</string>
65
+        <string>autostart</string>
52 66
     </array>
53 67
     <key>RunAtLoad</key>
54 68
     <true/>
@@ -72,3 +86,16 @@ Terminal=false
72 86
 Categories=Network;FileTransfer;P2P;
73 87
 ''' % {'base': root_dir})
74 88
 
89
+def install_autostart_xdg():
90
+    app = os.path.expanduser('~/.config/autostart/openmedialibrary.desktop')
91
+    ox.makedirs(os.path.dirname(app))
92
+    with open(app, 'w') as fd:
93
+        fd.write('''[Desktop Entry]
94
+Type=Application
95
+Name=Open Media Library
96
+Comment=
97
+Exec=%(base)s/ctl autostart
98
+Icon=%(base)s/openmedialibrary/static/png/oml.png
99
+Terminal=false
100
+X-GNOME-Autostart-enabled=true
101
+''' % {'base': root_dir})

+ 8
- 0
oml/user/api.py View File

@@ -66,6 +66,8 @@ def setPreferences(data):
66 66
             data['contact'] != settings.preferences['contact']
67 67
     change_username = 'username' in data and \
68 68
             data['username'] != settings.preferences['username']
69
+    change_autostart = 'autostart' in data and \
70
+            data['autostart'] != settings.preferences['autostart']
69 71
     if 'libraryPath' in data and \
70 72
             data['libraryPath'] != settings.preferences['libraryPath']:
71 73
         change_path = [settings.preferences['libraryPath'], data['libraryPath']]
@@ -82,6 +84,12 @@ def setPreferences(data):
82 84
         Changelog.record(state.user(), 'editcontact', data['contact'])
83 85
     if change_path:
84 86
         state.tasks.queue('changelibrarypath', change_path)
87
+    if change_autostart:
88
+        import integration
89
+        if settings.preferences['autostart']:
90
+            integration.install_autostart()
91
+        else:
92
+            integration.uninstall_autostart()
85 93
     return settings.preferences
86 94
 actions.register(setPreferences, cache=False)
87 95
 

+ 6
- 0
static/js/preferencesPanel.js View File

@@ -137,6 +137,12 @@ oml.ui.preferencesPanel = function() {
137 137
             ],
138 138
             advanced: [
139 139
                 {
140
+                    id: 'autostart',
141
+                    title: 'Start Open Media Library at Login',
142
+                    value: preferences.autostart,
143
+                    help: 'Launch Open Media Library in the background once you login to your computer.'
144
+                },
145
+                {
140 146
                     id: 'showDebugMenu',
141 147
                     title: 'Show Debug Menu',
142 148
                     value: ui.showDebugMenu,