mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-08-17 05:05:44 +02:00
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
This commit is contained in:
parent
7c265a950c
commit
012034fe67
11 changed files with 47 additions and 95 deletions
|
@ -115,8 +115,7 @@ if(WITH_WEBENGINE)
|
||||||
WebEngineCore
|
WebEngineCore
|
||||||
WebEngineQuick
|
WebEngineQuick
|
||||||
WebChannel
|
WebChannel
|
||||||
WebEngineWidgets
|
WebEngineWidgets)
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS
|
set(CMAKE_CXX_FLAGS
|
||||||
|
@ -159,14 +158,14 @@ set(PYTHON_EXEC ${Python3_EXECUTABLE})
|
||||||
# changes.
|
# changes.
|
||||||
# Only include webengine resources if specified.
|
# Only include webengine resources if specified.
|
||||||
if(WITH_WEBENGINE)
|
if(WITH_WEBENGINE)
|
||||||
set(GEN_QML_QRC_ARGS "--with-webengine")
|
set(GEN_QRC_ARGS "--with-webengine")
|
||||||
endif()
|
endif()
|
||||||
file(GLOB_RECURSE
|
file(GLOB_RECURSE
|
||||||
QML_FILES CONFIGURE_DEPENDS
|
QML_FILES CONFIGURE_DEPENDS
|
||||||
${APP_SRC_DIR}/*)
|
${APP_SRC_DIR}/*)
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND
|
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})
|
WORKING_DIRECTORY ${APP_SRC_DIR})
|
||||||
set(QML_RESOURCES_QML ${APP_SRC_DIR}/qml.qrc)
|
set(QML_RESOURCES_QML ${APP_SRC_DIR}/qml.qrc)
|
||||||
# Image and misc. resources
|
# Image and misc. resources
|
||||||
|
@ -176,7 +175,7 @@ file(GLOB_RECURSE
|
||||||
RES_FILES CONFIGURE_DEPENDS
|
RES_FILES CONFIGURE_DEPENDS
|
||||||
${PROJECT_SOURCE_DIR}/resources/*)
|
${PROJECT_SOURCE_DIR}/resources/*)
|
||||||
execute_process(
|
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})
|
WORKING_DIRECTORY ${APP_SRC_DIR})
|
||||||
set(QML_RESOURCES ${APP_SRC_DIR}/resources.qrc)
|
set(QML_RESOURCES ${APP_SRC_DIR}/resources.qrc)
|
||||||
|
|
||||||
|
@ -508,7 +507,6 @@ qt_add_executable(
|
||||||
${COMMON_SOURCES}
|
${COMMON_SOURCES}
|
||||||
${QML_RESOURCES}
|
${QML_RESOURCES}
|
||||||
${QML_RESOURCES_QML}
|
${QML_RESOURCES_QML}
|
||||||
${LIBCLIENT_SRC_DIR}/webresource.qrc
|
|
||||||
${SFPM_OBJECTS})
|
${SFPM_OBJECTS})
|
||||||
|
|
||||||
foreach(MODULE ${QT_MODULES})
|
foreach(MODULE ${QT_MODULES})
|
||||||
|
|
|
@ -49,21 +49,33 @@ def format_qml_prop(prop):
|
||||||
).lower()
|
).lower()
|
||||||
|
|
||||||
|
|
||||||
# Generate the the resources.qrc file and the JamiResources.qml file
|
def path_contains_dir(filepath, dir_str):
|
||||||
# that will be used to access the resources.
|
""" Return True if the given filepath contains the given directory. """
|
||||||
with open(resfile, 'w', encoding='utf-8') as qrc, \
|
# Split the filepath into its components
|
||||||
open(qmlfile, 'w', encoding='utf-8') as qml:
|
path_components = os.path.normpath(filepath).split(os.sep)
|
||||||
qrc.write('<RCC>\n')
|
# Return True if the given directory is in the path
|
||||||
qml.write('pragma Singleton\nimport QtQuick\nQtObject {\n')
|
return dir_str in path_components
|
||||||
for root, _, files in os.walk(resdir):
|
|
||||||
if len(files):
|
|
||||||
|
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]
|
prefix = root.rsplit(os.sep, 1)[-1]
|
||||||
# add a prefix to the resource file
|
# add a prefix to the resource file
|
||||||
qrc.write(f'\t<qresource prefix="/{prefix}">\n')
|
qrc.write(f'\t<qresource prefix="/{prefix}">\n')
|
||||||
for filename in files:
|
for filename in files:
|
||||||
# use posix separators in the resource path
|
# use posix separators in the resource path
|
||||||
filepath = os.path.join(root, filename).replace(os.sep, '/')
|
filepath = os.path.join(
|
||||||
qrc.write(f'\t\t<file alias="{filename}">{filepath}</file>\n')
|
root, filename).replace(os.sep, '/')
|
||||||
|
qrc.write(
|
||||||
|
f'\t\t<file alias="{filename}">{filepath}</file>\n')
|
||||||
# only record images/icons as properties
|
# only record images/icons as properties
|
||||||
if re.match("icons|images", prefix):
|
if re.match("icons|images", prefix):
|
||||||
resource = f'qrc:/{prefix}/{filename}'
|
resource = f'qrc:/{prefix}/{filename}'
|
||||||
|
@ -73,5 +85,15 @@ with open(resfile, 'w', encoding='utf-8') as qrc, \
|
||||||
f' "{resource}"\n'
|
f' "{resource}"\n'
|
||||||
)
|
)
|
||||||
qrc.write('\t</qresource>\n')
|
qrc.write('\t</qresource>\n')
|
||||||
qml.write('}')
|
qml.write('}')
|
||||||
qrc.write('</RCC>')
|
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_);
|
channel_->registerObject(QStringLiteral("jsbridge"), &parent_);
|
||||||
|
|
||||||
setWebChannel(channel_);
|
setWebChannel(channel_);
|
||||||
runJavaScript(Utils::QByteArrayFromFile(":/linkify.js"), QWebEngineScript::MainWorld);
|
runJavaScript(Utils::QByteArrayFromFile(":webengine/linkify.js"),
|
||||||
runJavaScript(Utils::QByteArrayFromFile(":/linkify-string.js"), QWebEngineScript::MainWorld);
|
QWebEngineScript::MainWorld);
|
||||||
runJavaScript(Utils::QByteArrayFromFile(":/qwebchannel.js"), QWebEngineScript::MainWorld);
|
runJavaScript(Utils::QByteArrayFromFile(":webengine/linkify-string.js"),
|
||||||
runJavaScript(Utils::QByteArrayFromFile(":/previewInfo.js"), QWebEngineScript::MainWorld);
|
QWebEngineScript::MainWorld);
|
||||||
runJavaScript(Utils::QByteArrayFromFile(":/misc/previewInterop.js"),
|
runJavaScript(Utils::QByteArrayFromFile(":webengine/qwebchannel.js"),
|
||||||
|
QWebEngineScript::MainWorld);
|
||||||
|
runJavaScript(Utils::QByteArrayFromFile(":webengine/previewInfo.js"),
|
||||||
|
QWebEngineScript::MainWorld);
|
||||||
|
runJavaScript(Utils::QByteArrayFromFile(":webengine/previewInterop.js"),
|
||||||
QWebEngineScript::MainWorld);
|
QWebEngineScript::MainWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
{
|
|
||||||
"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
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,33 +0,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.
|
|
|
@ -1,8 +0,0 @@
|
||||||
<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>
|
|
Loading…
Add table
Reference in a new issue