diff --git a/CMakeLists.txt b/CMakeLists.txt index cf61ef3b..91b6b23e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -516,14 +516,6 @@ add_custom_command(TARGET LOOT POST_BUILD "${CEF_LOCALES_DIR}/${CEF_LOCALE_FILE}" $/resources/l10n/${CEF_LOCALE_FILE}) -# Copy UI fonts. Not necessary for the build, but useful for testing. -FOREACH(font Roboto-Bold.ttf Roboto-BoldItalic.ttf Roboto-Italic.ttf Roboto-Light.ttf Roboto-LightItalic.ttf Roboto-Medium.ttf Roboto-MediumItalic.ttf Roboto-Regular.ttf) -add_custom_command(TARGET LOOT POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - "${CMAKE_SOURCE_DIR}/resources/ui/fonts/${font}" - $/resources/ui/fonts/${font}) -ENDFOREACH() - # Build the UI HTML. add_custom_command(TARGET LOOT POST_BUILD COMMAND "node" "${CMAKE_SOURCE_DIR}/scripts/build_ui.js" diff --git a/package.json b/package.json index 1f5bd538..f90edcec 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,12 @@ "homepage": "https://github.com/loot/loot", "private": true, "dependencies": { + "decompress": "^4.0.0", + "decompress-unzip": "^4.0.1", "fs-extra": "^0.30.0", "hydrolysis": "^1.24.1", - "replace": "^0.3.0" + "replace": "^0.3.0", + "request": "^2.79.0" }, "devDependencies": { "bower": "^1.7.1", diff --git a/resources/ui/fonts/Roboto-Bold.ttf b/resources/ui/fonts/Roboto-Bold.ttf deleted file mode 100644 index 68822caf..00000000 Binary files a/resources/ui/fonts/Roboto-Bold.ttf and /dev/null differ diff --git a/resources/ui/fonts/Roboto-BoldItalic.ttf b/resources/ui/fonts/Roboto-BoldItalic.ttf deleted file mode 100644 index aebf8eb0..00000000 Binary files a/resources/ui/fonts/Roboto-BoldItalic.ttf and /dev/null differ diff --git a/resources/ui/fonts/Roboto-Italic.ttf b/resources/ui/fonts/Roboto-Italic.ttf deleted file mode 100644 index 2041cbc0..00000000 Binary files a/resources/ui/fonts/Roboto-Italic.ttf and /dev/null differ diff --git a/resources/ui/fonts/Roboto-Light.ttf b/resources/ui/fonts/Roboto-Light.ttf deleted file mode 100644 index aa453407..00000000 Binary files a/resources/ui/fonts/Roboto-Light.ttf and /dev/null differ diff --git a/resources/ui/fonts/Roboto-LightItalic.ttf b/resources/ui/fonts/Roboto-LightItalic.ttf deleted file mode 100644 index a85444f2..00000000 Binary files a/resources/ui/fonts/Roboto-LightItalic.ttf and /dev/null differ diff --git a/resources/ui/fonts/Roboto-Medium.ttf b/resources/ui/fonts/Roboto-Medium.ttf deleted file mode 100644 index a3c1a1f1..00000000 Binary files a/resources/ui/fonts/Roboto-Medium.ttf and /dev/null differ diff --git a/resources/ui/fonts/Roboto-MediumItalic.ttf b/resources/ui/fonts/Roboto-MediumItalic.ttf deleted file mode 100644 index b8282055..00000000 Binary files a/resources/ui/fonts/Roboto-MediumItalic.ttf and /dev/null differ diff --git a/resources/ui/fonts/Roboto-Regular.ttf b/resources/ui/fonts/Roboto-Regular.ttf deleted file mode 100644 index 0e58508a..00000000 Binary files a/resources/ui/fonts/Roboto-Regular.ttf and /dev/null differ diff --git a/scripts/build_ui.js b/scripts/build_ui.js index f31e45d0..14d00518 100644 --- a/scripts/build_ui.js +++ b/scripts/build_ui.js @@ -3,6 +3,7 @@ const helpers = require('./helpers'); const hyd = require('hydrolysis'); const fs = require('fs-extra'); const path = require('path'); +const getRobotoFiles = require('./get_roboto_files').getRobotoFiles; function getHtmlImports(filePath) { return hyd.Analyzer.analyze(filePath).then((analyzer) => @@ -85,20 +86,31 @@ function copyFiles(pathsPromise, destinationRootPath) { }); } -helpers.getAppReleasePaths('.').forEach(releasePath => { - const index = 'src/gui/html/index.html'; - const destinationRootPath = `${releasePath.path}/resources/ui`; - const imports = new Set(); +const url = 'https://github.com/google/roboto/releases/download/v2.135/roboto-hinted.zip'; +const fontsPath = 'build/fonts'; - copyFiles(getRecursiveHtmlImports(index, imports), destinationRootPath); - copyFiles(getJavaScriptSources(index), destinationRootPath); - fs.copySync('src/gui/html/css', `${destinationRootPath}/css`); - fs.copySync('resources/ui/css/dark-theme.css', `${destinationRootPath}/css/dark-theme.css`); - fs.copySync('resources/ui/fonts', `${destinationRootPath}/fonts`); - copyNormalisedFile(index, `${destinationRootPath}/index.html`); +Promise.resolve().then(() => { + if (!fs.existsSync(fontsPath)) { + return getRobotoFiles(url, fontsPath); + } - // This is the only JS file referenced by a HTML import (neon-animation), - // so just hardcode it instead of recursively searching for it. - const webAnimationsJs = 'bower_components/web-animations-js/web-animations-next-lite.min.js'; - fs.copySync(webAnimationsJs, `${destinationRootPath}/${webAnimationsJs}`); + return ''; +}).then(() => { + helpers.getAppReleasePaths('.').forEach(releasePath => { + const index = 'src/gui/html/index.html'; + const destinationRootPath = `${releasePath.path}/resources/ui`; + const imports = new Set(); + + copyFiles(getRecursiveHtmlImports(index, imports), destinationRootPath); + copyFiles(getJavaScriptSources(index), destinationRootPath); + fs.copySync('src/gui/html/css', `${destinationRootPath}/css`); + fs.copySync('resources/ui/css/dark-theme.css', `${destinationRootPath}/css/dark-theme.css`); + fs.copySync(fontsPath, `${destinationRootPath}/fonts`); + copyNormalisedFile(index, `${destinationRootPath}/index.html`); + + // This is the only JS file referenced by a HTML import (neon-animation), + // so just hardcode it instead of recursively searching for it. + const webAnimationsJs = 'bower_components/web-animations-js/web-animations-next-lite.min.js'; + fs.copySync(webAnimationsJs, `${destinationRootPath}/${webAnimationsJs}`); + }); }); diff --git a/scripts/get_roboto_files.js b/scripts/get_roboto_files.js new file mode 100644 index 00000000..c4d01760 --- /dev/null +++ b/scripts/get_roboto_files.js @@ -0,0 +1,26 @@ +const fs = require('fs-extra'); +const path = require('path'); +const request = require('request'); +const decompress = require('decompress'); +const decompressUnzip = require('decompress-unzip'); + +function getRobotoFiles(url, destinationPath) { + const extractPath = path.dirname(destinationPath); + const downloadPath = path.join(extractPath, 'roboto-hinted.zip'); + + return new Promise((resolve, reject) => { + request(url) + .pipe(fs.createWriteStream(downloadPath)) + .on('close', (err) => { + if (err) { + reject(err); + } + resolve(); + }); + }).then(() => decompress(downloadPath, extractPath)).then(() => { + fs.renameSync(path.join(extractPath, 'roboto-hinted'), destinationPath); + fs.removeSync(downloadPath); + }); +} + +module.exports.getRobotoFiles = getRobotoFiles;