Skip to content
Snippets Groups Projects
Commit 012034fe authored by Andreas Traczyk's avatar Andreas Traczyk
Browse files

misc: migrate the webengine resources from libclient to the client

Adds a `--with-engine` option for the resource generator script which will prevent packaging unused resources when building without webengine support.

Change-Id: If2f31284ef59166615221235427a53d0df8da2ce
parent 7c265a95
No related branches found
No related tags found
No related merge requests found
......@@ -115,8 +115,7 @@ if(WITH_WEBENGINE)
WebEngineCore
WebEngineQuick
WebChannel
WebEngineWidgets
)
WebEngineWidgets)
endif()
set(CMAKE_CXX_FLAGS
......@@ -159,14 +158,14 @@ set(PYTHON_EXEC ${Python3_EXECUTABLE})
# changes.
# Only include webengine resources if specified.
if(WITH_WEBENGINE)
set(GEN_QML_QRC_ARGS "--with-webengine")
set(GEN_QRC_ARGS "--with-webengine")
endif()
file(GLOB_RECURSE
QML_FILES CONFIGURE_DEPENDS
${APP_SRC_DIR}/*)
execute_process(
COMMAND
${PYTHON_EXEC} ${SCRIPTS_DIR}/gen_qml_qrc.py ${GEN_QML_QRC_ARGS}
${PYTHON_EXEC} ${SCRIPTS_DIR}/gen_qml_qrc.py ${GEN_QRC_ARGS}
WORKING_DIRECTORY ${APP_SRC_DIR})
set(QML_RESOURCES_QML ${APP_SRC_DIR}/qml.qrc)
# Image and misc. resources
......@@ -176,7 +175,7 @@ file(GLOB_RECURSE
RES_FILES CONFIGURE_DEPENDS
${PROJECT_SOURCE_DIR}/resources/*)
execute_process(
COMMAND ${PYTHON_EXEC} ${SCRIPTS_DIR}/gen_resources_qrc.py
COMMAND ${PYTHON_EXEC} ${SCRIPTS_DIR}/gen_resources_qrc.py ${GEN_QRC_ARGS}
WORKING_DIRECTORY ${APP_SRC_DIR})
set(QML_RESOURCES ${APP_SRC_DIR}/resources.qrc)
......@@ -508,7 +507,6 @@ qt_add_executable(
${COMMON_SOURCES}
${QML_RESOURCES}
${QML_RESOURCES_QML}
${LIBCLIENT_SRC_DIR}/webresource.qrc
${SFPM_OBJECTS})
foreach(MODULE ${QT_MODULES})
......
......@@ -49,21 +49,33 @@ def format_qml_prop(prop):
).lower()
# Generate the the resources.qrc file and the JamiResources.qml file
# that will be used to access the resources.
with open(resfile, 'w', encoding='utf-8') as qrc, \
open(qmlfile, 'w', encoding='utf-8') as qml:
qrc.write('<RCC>\n')
qml.write('pragma Singleton\nimport QtQuick\nQtObject {\n')
for root, _, files in os.walk(resdir):
if len(files):
def path_contains_dir(filepath, dir_str):
""" Return True if the given filepath contains the given directory. """
# Split the filepath into its components
path_components = os.path.normpath(filepath).split(os.sep)
# Return True if the given directory is in the path
return dir_str in path_components
def gen_resources_qrc(with_webengine):
""" Generate the resources.qrc file. """
with open(resfile, 'w', encoding='utf-8') as qrc, \
open(qmlfile, 'w', encoding='utf-8') as qml:
qrc.write('<RCC>\n')
qml.write('pragma Singleton\nimport QtQuick\nQtObject {\n')
for root, _, files in os.walk(resdir):
# Skip the webengine directory if we can't use webengine
if not with_webengine and path_contains_dir(root, 'webengine'):
continue
prefix = root.rsplit(os.sep, 1)[-1]
# add a prefix to the resource file
qrc.write(f'\t<qresource prefix="/{prefix}">\n')
for filename in files:
# use posix separators in the resource path
filepath = os.path.join(root, filename).replace(os.sep, '/')
qrc.write(f'\t\t<file alias="{filename}">{filepath}</file>\n')
filepath = os.path.join(
root, filename).replace(os.sep, '/')
qrc.write(
f'\t\t<file alias="{filename}">{filepath}</file>\n')
# only record images/icons as properties
if re.match("icons|images", prefix):
resource = f'qrc:/{prefix}/{filename}'
......@@ -73,5 +85,15 @@ with open(resfile, 'w', encoding='utf-8') as qrc, \
f' "{resource}"\n'
)
qrc.write('\t</qresource>\n')
qml.write('}')
qrc.write('</RCC>')
qml.write('}')
qrc.write('</RCC>')
if __name__ == '__main__':
# We can't use webengine if we're building for macOS app store
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--with-webengine', action='store_true',
default=False, help='Include webengine resources')
args = parser.parse_args()
gen_resources_qrc(args.with_webengine)
......@@ -64,11 +64,15 @@ public:
channel_->registerObject(QStringLiteral("jsbridge"), &parent_);
setWebChannel(channel_);
runJavaScript(Utils::QByteArrayFromFile(":/linkify.js"), QWebEngineScript::MainWorld);
runJavaScript(Utils::QByteArrayFromFile(":/linkify-string.js"), QWebEngineScript::MainWorld);
runJavaScript(Utils::QByteArrayFromFile(":/qwebchannel.js"), QWebEngineScript::MainWorld);
runJavaScript(Utils::QByteArrayFromFile(":/previewInfo.js"), QWebEngineScript::MainWorld);
runJavaScript(Utils::QByteArrayFromFile(":/misc/previewInterop.js"),
runJavaScript(Utils::QByteArrayFromFile(":webengine/linkify.js"),
QWebEngineScript::MainWorld);
runJavaScript(Utils::QByteArrayFromFile(":webengine/linkify-string.js"),
QWebEngineScript::MainWorld);
runJavaScript(Utils::QByteArrayFromFile(":webengine/qwebchannel.js"),
QWebEngineScript::MainWorld);
runJavaScript(Utils::QByteArrayFromFile(":webengine/previewInfo.js"),
QWebEngineScript::MainWorld);
runJavaScript(Utils::QByteArrayFromFile(":webengine/previewInterop.js"),
QWebEngineScript::MainWorld);
}
......
{
"env": {
"browser": true
},
"plugins": ["html"],
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 6
},
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"never"
],
"no-inner-declarations": [
0
]
}
}
# README - chatview
The chatview runs under a WebKit GTK view. It is written using web technologies
(HTML5/CSS3/JS) and is responsible for displaying everything that deals with the
navbar, the messages, and the message bar.
## Contributing - syntax
We have a set of ESLint rules that define clear syntax rules (web/.eslintrc.json).
You will need the following tools:
- ESLint (The pluggable linting utility for JavaScript and JSX)
https://eslint.org/
- ESLint HTML plugin (eslint-plugin-html)
https://www.npmjs.com/package/eslint-plugin-html
Before pushing a patch, make sure that it passes ESLint:
$ eslint chatview.html
Most trivial issues can be fixed using
$ eslint chatview.js --fix
We will not accept patches introducing non-ESLint-compliant code.
## WebKit GTK
Everything runs under WebKit GTK, that is if you need to write browser specific
code, you will only need to support WebKit (CSS -webkit- prefix).
Do not use querySelector if getElementById or getElementByClassName can be used
instead. querySelector doesn't always make the code easier and has very bad
performances.
<RCC>
<qresource prefix="/">
<file alias="linkify.js">web-chatview/linkify.js</file>
<file alias="linkify-string.js">web-chatview/linkify-string.js</file>
<file alias="previewInfo.js">web-chatview/previewInfo.js</file>
<file alias="qwebchannel.js">web-chatview/qwebchannel.js</file>
</qresource>
</RCC>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment