mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Have the develop mode env var work for the server as well
This commit is contained in:
parent
b9082d95dc
commit
58b35f1aab
@ -219,8 +219,6 @@ def create_profile():
|
||||
# DO NOT change the user agent as it is used to workaround
|
||||
# Qt bugs see workaround_qt_bug() in ajax.pyj
|
||||
ua = 'calibre-viewer {} {}'.format(__version__, osname)
|
||||
if hasenv('CALIBRE_ENABLE_DEVELOP_MODE'):
|
||||
ua += ' CALIBRE_ENABLE_DEVELOP_MODE'
|
||||
ans.setHttpUserAgent(ua)
|
||||
if is_running_from_develop:
|
||||
from calibre.utils.rapydscript import compile_viewer
|
||||
@ -229,6 +227,8 @@ def create_profile():
|
||||
js = P('viewer.js', data=True, allow_user_override=False)
|
||||
translations_json = get_translations_data() or b'null'
|
||||
js = js.replace(b'__TRANSLATIONS_DATA__', translations_json, 1)
|
||||
if hasenv('CALIBRE_ENABLE_DEVELOP_MODE'):
|
||||
js = js.replace(b'__IN_DEVELOP_MODE__', os.environ['CALIBRE_ENABLE_DEVELOP_MODE'].encode('ascii'))
|
||||
insert_scripts(ans, create_script('viewer.js', js))
|
||||
url_handler = UrlSchemeHandler(ans)
|
||||
ans.installUrlSchemeHandler(QByteArray(FAKE_PROTOCOL.encode('ascii')), url_handler)
|
||||
|
@ -5,6 +5,7 @@
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
import random
|
||||
import shutil
|
||||
import sys
|
||||
@ -25,18 +26,23 @@ from calibre.srv.metadata import (
|
||||
from calibre.srv.routes import endpoint, json
|
||||
from calibre.srv.utils import get_library_data, get_use_roman
|
||||
from calibre.utils.config import prefs, tweaks
|
||||
from calibre.utils.icu import sort_key, numeric_sort_key
|
||||
from calibre.utils.localization import get_lang, lang_map_for_ui, localize_website_link
|
||||
from calibre.utils.icu import numeric_sort_key, sort_key
|
||||
from calibre.utils.localization import (
|
||||
get_lang, lang_map_for_ui, localize_website_link
|
||||
)
|
||||
from calibre.utils.search_query_parser import ParseException
|
||||
from calibre.utils.serialize import json_dumps
|
||||
from polyglot.builtins import iteritems, itervalues
|
||||
from polyglot.builtins import iteritems, itervalues, hasenv
|
||||
|
||||
POSTABLE = frozenset({'GET', 'POST', 'HEAD'})
|
||||
|
||||
|
||||
@endpoint('', auth_required=False)
|
||||
def index(ctx, rd):
|
||||
return lopen(P('content-server/index-generated.html'), 'rb')
|
||||
ans_file = lopen(P('content-server/index-generated.html'), 'rb')
|
||||
if not hasenv('CALIBRE_ENABLE_DEVELOP_MODE'):
|
||||
return ans_file
|
||||
return ans_file.read().replace(b'__IN_DEVELOP_MODE__', os.environ['CALIBRE_ENABLE_DEVELOP_MODE'].encode('ascii'))
|
||||
|
||||
|
||||
@endpoint('/robots.txt', auth_required=False)
|
||||
|
@ -76,10 +76,11 @@ register_callback(def():
|
||||
set_system_colors({'background': '#111', 'foreground': '#ddd', 'link': dark_link_color})
|
||||
)
|
||||
|
||||
IN_DEVELOP_MODE = '__IN_DEVELOP_MODE__'
|
||||
runtime = {
|
||||
'is_standalone_viewer': False,
|
||||
'viewer_in_full_screen': False,
|
||||
'in_develop_mode': window.navigator.userAgent.indexOf('CALIBRE_ENABLE_DEVELOP_MODE') > 0,
|
||||
'in_develop_mode': IN_DEVELOP_MODE is '1',
|
||||
}
|
||||
|
||||
|
||||
|
@ -331,6 +331,14 @@ def shortcuts_definition():
|
||||
),
|
||||
|
||||
}
|
||||
if runtime.in_develop_mode:
|
||||
ans.create_annotation = desc(
|
||||
"a",
|
||||
'ui',
|
||||
_('Create a highlight'),
|
||||
)
|
||||
|
||||
|
||||
return ans
|
||||
|
||||
|
||||
@ -385,13 +393,6 @@ def add_standalone_viewer_shortcuts():
|
||||
_('Toggle the toolbar'),
|
||||
)
|
||||
|
||||
if runtime.in_develop_mode:
|
||||
sc['create_annotation'] = desc(
|
||||
"a",
|
||||
'ui',
|
||||
_('Create a highlight'),
|
||||
)
|
||||
|
||||
|
||||
def create_shortcut_map(custom_shortcuts):
|
||||
ans = {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user