mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Linux: Register calibre as URL handler for calibre:// URLs
This commit is contained in:
parent
df3fc1eba1
commit
03b5ad536b
@ -850,7 +850,13 @@ class PostInstall:
|
|||||||
def setup_desktop_integration(self): # {{{
|
def setup_desktop_integration(self): # {{{
|
||||||
try:
|
try:
|
||||||
self.info('Setting up desktop integration...')
|
self.info('Setting up desktop integration...')
|
||||||
|
self.do_setup_desktop_integration()
|
||||||
|
except Exception:
|
||||||
|
if self.opts.fatal_errors:
|
||||||
|
raise
|
||||||
|
self.task_failed('Setting up desktop integration failed')
|
||||||
|
|
||||||
|
def do_setup_desktop_integration(self):
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
cc = check_call
|
cc = check_call
|
||||||
if getattr(sys, 'frozen_path', False) and 'LD_LIBRARY_PATH' in env:
|
if getattr(sys, 'frozen_path', False) and 'LD_LIBRARY_PATH' in env:
|
||||||
@ -862,13 +868,13 @@ class PostInstall:
|
|||||||
|
|
||||||
if getattr(self.opts, 'staged_install', False):
|
if getattr(self.opts, 'staged_install', False):
|
||||||
for d in {'applications', 'desktop-directories', 'icons/hicolor', 'mime/packages'}:
|
for d in {'applications', 'desktop-directories', 'icons/hicolor', 'mime/packages'}:
|
||||||
try:
|
os.makedirs(os.path.join(self.opts.staging_root, 'share', d), exist_ok=True)
|
||||||
os.makedirs(os.path.join(self.opts.staging_root, 'share', d))
|
|
||||||
except OSError:
|
|
||||||
# python2 does not have exist_ok=True, failure will be reported by xdg-utils
|
|
||||||
pass
|
|
||||||
|
|
||||||
with TemporaryDirectory() as tdir, CurrentDir(tdir), PreserveMIMEDefaults():
|
with TemporaryDirectory() as tdir, CurrentDir(tdir):
|
||||||
|
with PreserveMIMEDefaults():
|
||||||
|
self.install_xdg_junk(cc, env)
|
||||||
|
|
||||||
|
def install_xdg_junk(self, cc, env):
|
||||||
|
|
||||||
def install_single_icon(iconsrc, basename, size, context, is_last_icon=False):
|
def install_single_icon(iconsrc, basename, size, context, is_last_icon=False):
|
||||||
filename = '%s-%s.png' % (basename, size)
|
filename = '%s-%s.png' % (basename, size)
|
||||||
@ -906,8 +912,11 @@ class PostInstall:
|
|||||||
mimetypes.add(mt)
|
mimetypes.add(mt)
|
||||||
mimetypes.discard('application/octet-stream')
|
mimetypes.discard('application/octet-stream')
|
||||||
|
|
||||||
def write_mimetypes(f):
|
def write_mimetypes(f, extra=''):
|
||||||
f.write(('MimeType=%s;\n'%';'.join(mimetypes)).encode('utf-8'))
|
line = 'MimeType={};'.format(';'.join(mimetypes))
|
||||||
|
if extra:
|
||||||
|
line += extra + ';'
|
||||||
|
f.write(line.encode('utf-8') + b'\n')
|
||||||
|
|
||||||
from calibre.ebooks.oeb.polish.main import SUPPORTED
|
from calibre.ebooks.oeb.polish.main import SUPPORTED
|
||||||
from calibre.ebooks.oeb.polish.import_book import IMPORTABLE
|
from calibre.ebooks.oeb.polish.import_book import IMPORTABLE
|
||||||
@ -922,10 +931,11 @@ class PostInstall:
|
|||||||
f.write(('MimeType=%s;\n'%';'.join(mt)).encode('utf-8'))
|
f.write(('MimeType=%s;\n'%';'.join(mt)).encode('utf-8'))
|
||||||
with open('calibre-gui.desktop', 'wb') as f:
|
with open('calibre-gui.desktop', 'wb') as f:
|
||||||
f.write(GUI.encode('utf-8'))
|
f.write(GUI.encode('utf-8'))
|
||||||
write_mimetypes(f)
|
write_mimetypes(f, 'x-scheme-handler/calibre')
|
||||||
des = ('calibre-gui.desktop', 'calibre-lrfviewer.desktop',
|
des = ('calibre-gui.desktop', 'calibre-lrfviewer.desktop',
|
||||||
'calibre-ebook-viewer.desktop', 'calibre-ebook-edit.desktop')
|
'calibre-ebook-viewer.desktop', 'calibre-ebook-edit.desktop')
|
||||||
appdata = os.path.join(os.path.dirname(self.opts.staging_sharedir), 'metainfo')
|
appdata = os.path.join(os.path.dirname(self.opts.staging_sharedir), 'metainfo')
|
||||||
|
translators = None
|
||||||
if not os.path.exists(appdata):
|
if not os.path.exists(appdata):
|
||||||
try:
|
try:
|
||||||
os.mkdir(appdata)
|
os.mkdir(appdata)
|
||||||
@ -943,8 +953,9 @@ class PostInstall:
|
|||||||
cc(' '.join(cmd), shell=True)
|
cc(' '.join(cmd), shell=True)
|
||||||
self.menu_resources.append(x)
|
self.menu_resources.append(x)
|
||||||
ak = x.partition('.')[0]
|
ak = x.partition('.')[0]
|
||||||
if ak in APPDATA and os.access(appdata, os.W_OK):
|
if ak in APPDATA and translators is not None and os.access(appdata, os.W_OK):
|
||||||
self.appdata_resources.append(write_appdata(ak, APPDATA[ak], appdata, translators))
|
self.appdata_resources.append(write_appdata(ak, APPDATA[ak], appdata, translators))
|
||||||
|
|
||||||
MIME_BASE = 'calibre-mimetypes.xml'
|
MIME_BASE = 'calibre-mimetypes.xml'
|
||||||
MIME = P(MIME_BASE)
|
MIME = P(MIME_BASE)
|
||||||
self.mime_resources.append(MIME_BASE)
|
self.mime_resources.append(MIME_BASE)
|
||||||
@ -954,11 +965,6 @@ class PostInstall:
|
|||||||
else:
|
else:
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
copyfile(MIME, os.path.join(env['XDG_DATA_DIRS'], 'mime', 'packages', MIME_BASE))
|
copyfile(MIME, os.path.join(env['XDG_DATA_DIRS'], 'mime', 'packages', MIME_BASE))
|
||||||
except Exception:
|
|
||||||
if self.opts.fatal_errors:
|
|
||||||
raise
|
|
||||||
self.task_failed('Setting up desktop integration failed')
|
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user