mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Windows: When running on windows 8 and newer register with default programs so that users can more easily select calibre or its viewer/editor as the default program to launch ebook files. See #1422248 (calibre does not show up in win 8.1 default programs)
This commit is contained in:
parent
e07fc77a52
commit
e962bd3e24
@ -41,15 +41,31 @@ def init_dbus():
|
|||||||
threads_init()
|
threads_init()
|
||||||
DBusGMainLoop(set_as_default=True)
|
DBusGMainLoop(set_as_default=True)
|
||||||
|
|
||||||
|
def register_with_default_programs():
|
||||||
|
from calibre.constants import iswindows
|
||||||
|
if iswindows:
|
||||||
|
from calibre.utils.winreg.default_programs import Register
|
||||||
|
from calibre.gui2 import gprefs
|
||||||
|
return Register(gprefs)
|
||||||
|
else:
|
||||||
|
class Dummy(object):
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
def __exit__(self, *args):
|
||||||
|
pass
|
||||||
|
return Dummy()
|
||||||
|
|
||||||
def calibre(args=sys.argv):
|
def calibre(args=sys.argv):
|
||||||
detach_gui()
|
detach_gui()
|
||||||
init_dbus()
|
init_dbus()
|
||||||
|
with register_with_default_programs():
|
||||||
from calibre.gui2.main import main
|
from calibre.gui2.main import main
|
||||||
main(args)
|
main(args)
|
||||||
|
|
||||||
def ebook_viewer(args=sys.argv):
|
def ebook_viewer(args=sys.argv):
|
||||||
detach_gui()
|
detach_gui()
|
||||||
init_dbus()
|
init_dbus()
|
||||||
|
with register_with_default_programs():
|
||||||
from calibre.gui2.viewer.main import main
|
from calibre.gui2.viewer.main import main
|
||||||
main(args)
|
main(args)
|
||||||
|
|
||||||
@ -62,6 +78,7 @@ def gui_ebook_edit(path=None, notify=None):
|
|||||||
def ebook_edit(args=sys.argv):
|
def ebook_edit(args=sys.argv):
|
||||||
detach_gui()
|
detach_gui()
|
||||||
init_dbus()
|
init_dbus()
|
||||||
|
with register_with_default_programs():
|
||||||
from calibre.gui2.tweak_book.main import main
|
from calibre.gui2.tweak_book.main import main
|
||||||
main(args)
|
main(args)
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import os, sys
|
import os, sys, time
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from calibre import guess_type, prints
|
from calibre import guess_type, prints
|
||||||
@ -157,5 +157,16 @@ class Register(Thread):
|
|||||||
if self.prefs.get('windows_register_default_programs', None) != __version__:
|
if self.prefs.get('windows_register_default_programs', None) != __version__:
|
||||||
self.prefs['windows_register_default_programs'] = __version__
|
self.prefs['windows_register_default_programs'] = __version__
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
|
st = time.time()
|
||||||
prints('Registering with default programs...')
|
prints('Registering with default programs...')
|
||||||
register()
|
register()
|
||||||
|
if DEBUG:
|
||||||
|
prints('Registered with default programs in %.1f seconds' % (time.time() - st))
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, *args):
|
||||||
|
# Give the thread some time to finish in case the user quit the
|
||||||
|
# application very quickly
|
||||||
|
self.join(4.0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user