1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
Description: Generate grammars.dat from Prism during build
And consolidate dynamic resources into a single file.
Author: Nicholas Guriev <guriev-ns@ya.ru>
Last-Update: Thu, 28 Dec 2023 18:15:35 +0300
--- a/Telegram/CMakeLists.txt
+++ b/Telegram/CMakeLists.txt
@@ -1547,6 +1547,32 @@ if (APPLE AND NOT build_macstore)
)
endif()
+find_program(NODE_COMMAND NAMES node nodejs)
+
+add_custom_command(
+OUTPUT
+ ${CMAKE_CURRENT_BINARY_DIR}/grammars.dat
+ ${CMAKE_CURRENT_BINARY_DIR}/highlighting.qrc
+DEPENDS
+ ${third_party_loc}/libprisma/generate.js
+ ${CMAKE_CURRENT_SOURCE_DIR}/lib_spellcheck/highlighting/highlighting.qrc
+COMMAND
+ ${NODE_COMMAND}
+ ${third_party_loc}/libprisma/generate.js
+ ${CMAKE_CURRENT_BINARY_DIR}/grammars.dat
+COMMAND
+ ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_SOURCE_DIR}/lib_spellcheck/highlighting/highlighting.qrc
+ ${CMAKE_CURRENT_BINARY_DIR}/highlighting.qrc
+COMMENT
+ "Generating syntax highlighting grammar..."
+)
+
+target_sources(Telegram
+PRIVATE
+ ${CMAKE_CURRENT_BINARY_DIR}/highlighting.qrc
+)
+
if (WIN32)
# message(${CMAKE_GENERATOR})
# mt.exe -manifest "${res_loc}/winrc/Telegram.manifest" "-inputresource:\"$<TARGET_FILE:Telegram>\";#1" "-outputresource:\"$<TARGET_FILE:Telegram>\";#1" >NUL
--- a/Telegram/ThirdParty/libprisma/generate.js
+++ b/Telegram/ThirdParty/libprisma/generate.js
@@ -39,12 +39,12 @@ async function loadLanguage(lng) {
console.log(`${langNumber} | Loading ${lng}`);
// TODO: version should probably not be hardcoded
- await loadScript(`https://cdn.jsdelivr.net/npm/prismjs@1.29.0/components/prism-${lng}.min.js`)
+ require(`prismjs/components/prism-${lng}`)
}
}
function loadLocalLanguage(path, code, title, alias) {
- include(fs.readFileSync(path))
+ require(path)
components.languages[code] = {
title: title,
@@ -215,8 +215,8 @@ async function generate() {
"sparql" // requires turtle
]
- await loadScript("https://cdn.jsdelivr.net/npm/prismjs@1.29.0/components/prism-core.min.js")
- await loadScript("https://prismjs.com/components.js")
+ require("prismjs/components/prism-core")
+ components = require("prismjs/components")
await loadLanguages(Object.keys(components.languages))
console.log(`\nLoaded all ${langNumber} languages`)
console.log("Processing...")
@@ -415,7 +415,7 @@ async function saveBlob(blob, filename)
fs.writeFileSync(filename, buffer)
}
-const filepath = "libprisma/grammars.dat";
+const filepath = process.argv[2] ?? "libprisma/grammars.dat";
generate().then(blob => {
saveBlob(blob, filepath).then(() => {
--- a/Telegram/lib_spellcheck/CMakeLists.txt
+++ b/Telegram/lib_spellcheck/CMakeLists.txt
@@ -35,7 +35,6 @@ endif()
target_precompile_headers(lib_spellcheck PRIVATE ${src_loc}/spellcheck/spellcheck_pch.h)
nice_target_sources(lib_spellcheck ${src_loc}
PRIVATE
- highlighting/highlighting.qrc
spellcheck/platform/linux/language_linux.cpp
spellcheck/platform/linux/language_linux.h
--- a/Telegram/lib_spellcheck/spellcheck/spellcheck_highlight_syntax.cpp
+++ b/Telegram/lib_spellcheck/spellcheck/spellcheck_highlight_syntax.cpp
@@ -20,15 +20,6 @@
#include <string>
void spellchecker_InitHighlightingResource() {
-#ifdef Q_OS_MAC // Use resources from the .app bundle on macOS.
-
- base::RegisterBundledResources(u"lib_spellcheck.rcc"_q);
-
-#else // Q_OS_MAC
-
- Q_INIT_RESOURCE(highlighting);
-
-#endif // Q_OS_MAC
}
namespace Spellchecker {
|