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): # {{{
|
||||
try:
|
||||
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()
|
||||
cc = check_call
|
||||
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):
|
||||
for d in {'applications', 'desktop-directories', 'icons/hicolor', 'mime/packages'}:
|
||||
try:
|
||||
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
|
||||
os.makedirs(os.path.join(self.opts.staging_root, 'share', d), exist_ok=True)
|
||||
|
||||
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):
|
||||
filename = '%s-%s.png' % (basename, size)
|
||||
@ -906,8 +912,11 @@ class PostInstall:
|
||||
mimetypes.add(mt)
|
||||
mimetypes.discard('application/octet-stream')
|
||||
|
||||
def write_mimetypes(f):
|
||||
f.write(('MimeType=%s;\n'%';'.join(mimetypes)).encode('utf-8'))
|
||||
def write_mimetypes(f, extra=''):
|
||||
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.import_book import IMPORTABLE
|
||||
@ -922,10 +931,11 @@ class PostInstall:
|
||||
f.write(('MimeType=%s;\n'%';'.join(mt)).encode('utf-8'))
|
||||
with open('calibre-gui.desktop', 'wb') as f:
|
||||
f.write(GUI.encode('utf-8'))
|
||||
write_mimetypes(f)
|
||||
write_mimetypes(f, 'x-scheme-handler/calibre')
|
||||
des = ('calibre-gui.desktop', 'calibre-lrfviewer.desktop',
|
||||
'calibre-ebook-viewer.desktop', 'calibre-ebook-edit.desktop')
|
||||
appdata = os.path.join(os.path.dirname(self.opts.staging_sharedir), 'metainfo')
|
||||
translators = None
|
||||
if not os.path.exists(appdata):
|
||||
try:
|
||||
os.mkdir(appdata)
|
||||
@ -943,8 +953,9 @@ class PostInstall:
|
||||
cc(' '.join(cmd), shell=True)
|
||||
self.menu_resources.append(x)
|
||||
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))
|
||||
|
||||
MIME_BASE = 'calibre-mimetypes.xml'
|
||||
MIME = P(MIME_BASE)
|
||||
self.mime_resources.append(MIME_BASE)
|
||||
@ -954,11 +965,6 @@ class PostInstall:
|
||||
else:
|
||||
from shutil import copyfile
|
||||
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