This commit is contained in:
Kovid Goyal 2018-07-31 14:55:25 +05:30
parent 03df594e07
commit 1d892d9c0d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 11 additions and 13 deletions

View File

@ -8,7 +8,6 @@ import socket
import sys
import time
import traceback
from functools import partial
import apsw
from PyQt5.Qt import QCoreApplication, QIcon, QObject, QTimer
@ -244,18 +243,12 @@ class GuiRunner(QObject):
self.timed_print('splash screen hidden')
self.splash_screen = None
self.timed_print('Started up in %.2f seconds'%(monotonic() - self.startup_time), 'with', len(db.data), 'books')
add_filesystem_book = partial(main.iactions['Add Books'].add_filesystem_book, allow_device=False)
main.set_exception_handler()
if len(self.args) > 1:
files = [os.path.abspath(p) for p in self.args[1:] if not
os.path.isdir(p)]
if len(files) < len(sys.argv[1:]):
prints('Ignoring directories passed as command line arguments')
if files:
add_filesystem_book(files)
main.handle_cli_args(self.args[1:])
for event in self.app.file_event_hook.events:
add_filesystem_book(event)
self.app.file_event_hook = add_filesystem_book
main.handle_cli_args(event)
self.app.file_event_hook = main.handle_cli_args
def choose_dir(self, initial_dir):
self.hide_splash_screen()

View File

@ -613,6 +613,13 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
m.research()
self.tags_view.recount()
def handle_cli_args(self, args):
if isinstance(args, basestring):
args = [args]
files = [os.path.abspath(p) for p in args if not os.path.isdir(p) and os.access(p, os.R_OK)]
if files:
self.iactions['Add Books'].add_filesystem_book(files)
def another_instance_wants_to_talk(self):
try:
msg = self.listener.queue.get_nowait()
@ -631,9 +638,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
det_msg='Invalid msg: %r' % msg, show=True)
argv = ()
if isinstance(argv, (list, tuple)) and len(argv) > 1:
files = [os.path.abspath(p) for p in argv[1:] if not os.path.isdir(p) and os.access(p, os.R_OK)]
if files:
self.iactions['Add Books'].add_filesystem_book(files)
self.handle_cli_args(argv[1:])
self.setWindowState(self.windowState() & ~Qt.WindowMinimized|Qt.WindowActive)
self.show_windows()
self.raise_()