From 1a75305ea84501511f8ea14ee5ab64d8b7d39e5a Mon Sep 17 00:00:00 2001 From: Mohammad Fares Date: Sun, 9 Jul 2023 11:59:16 +0200 Subject: [PATCH 1/3] Add renderDir --- app.js | 1 + commands/render.js | 7 ++++++- package-lock.json | 46 +++++++++++++++++++++++++++++++++------------- package.json | 1 + render/index.js | 6 +++--- 5 files changed, 44 insertions(+), 17 deletions(-) diff --git a/app.js b/app.js index 2625f65..49fd614 100644 --- a/app.js +++ b/app.js @@ -30,6 +30,7 @@ di.require('os'); di.require('electron'); di.require('deepmerge'); di.require('uuid'); +di.require('tmp'); di.require('lodash', '_'); di.require('fs-extra', 'fs'); di.require('js-yaml', 'yaml'); diff --git a/commands/render.js b/commands/render.js index f6eb2d5..905840b 100644 --- a/commands/render.js +++ b/commands/render.js @@ -5,6 +5,11 @@ * @author Mohammad Fares */ +/** + * The directory to render the frames into + */ +var renderDir = tmp.dirSync({ unsafeCleanup: true }).name; + /** * Create a progress bar for processing frames * @@ -115,7 +120,7 @@ function renderFrames(records, options) { // Execute the rendering process var render = di.spawn( di.electron, - [di.path.join(ROOT_PATH, "render/index.js"), options.step], + [di.path.join(ROOT_PATH, "render/index.js"), renderDir, options.step,], { detached: false } ); diff --git a/package-lock.json b/package-lock.json index 1a35770..1b47cd6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,6 +27,7 @@ "request": "^2.88.2", "require-dir": "^1.1.0", "string-argv": "0.0.2", + "tmp": "^0.2.1", "uuid": "^3.4.0", "yargs": "^17.7.2" }, @@ -587,7 +588,6 @@ }, "node_modules/balanced-match": { "version": "1.0.2", - "dev": true, "license": "MIT" }, "node_modules/base64-js": { @@ -640,7 +640,6 @@ }, "node_modules/brace-expansion": { "version": "1.1.11", - "dev": true, "license": "MIT", "dependencies": { "balanced-match": "^1.0.0", @@ -948,7 +947,6 @@ }, "node_modules/concat-map": { "version": "0.0.1", - "dev": true, "license": "MIT" }, "node_modules/console-control-strings": { @@ -1378,6 +1376,17 @@ "node": ">=4" } }, + "node_modules/external-editor/node_modules/tmp": { + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", + "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", + "dependencies": { + "os-tmpdir": "~1.0.2" + }, + "engines": { + "node": ">=0.6.0" + } + }, "node_modules/extract-zip": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-2.0.1.tgz", @@ -1472,7 +1481,6 @@ }, "node_modules/fs.realpath": { "version": "1.0.0", - "dev": true, "license": "ISC" }, "node_modules/function-bind": { @@ -1593,7 +1601,6 @@ }, "node_modules/glob": { "version": "7.2.3", - "dev": true, "license": "ISC", "dependencies": { "fs.realpath": "^1.0.0", @@ -1878,7 +1885,6 @@ }, "node_modules/inflight": { "version": "1.0.6", - "dev": true, "license": "ISC", "dependencies": { "once": "^1.3.0", @@ -2331,7 +2337,6 @@ }, "node_modules/minimatch": { "version": "3.1.2", - "dev": true, "license": "ISC", "dependencies": { "brace-expansion": "^1.1.7" @@ -2471,7 +2476,8 @@ }, "node_modules/os-tmpdir": { "version": "1.0.2", - "license": "MIT", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==", "engines": { "node": ">=0.10.0" } @@ -2516,7 +2522,6 @@ }, "node_modules/path-is-absolute": { "version": "1.0.1", - "dev": true, "license": "MIT", "engines": { "node": ">=0.10.0" @@ -3396,13 +3401,28 @@ "license": "MIT" }, "node_modules/tmp": { - "version": "0.0.33", - "license": "MIT", + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz", + "integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==", "dependencies": { - "os-tmpdir": "~1.0.2" + "rimraf": "^3.0.0" }, "engines": { - "node": ">=0.6.0" + "node": ">=8.17.0" + } + }, + "node_modules/tmp/node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, "node_modules/tough-cookie": { diff --git a/package.json b/package.json index 976b5c7..c2f87a3 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "request": "^2.88.2", "require-dir": "^1.1.0", "string-argv": "0.0.2", + "tmp": "^0.2.1", "uuid": "^3.4.0", "yargs": "^17.7.2" }, diff --git a/render/index.js b/render/index.js index 86eb042..eca1360 100644 --- a/render/index.js +++ b/render/index.js @@ -15,17 +15,17 @@ const os = require('os'); let mainWindow = null; /** - * The temporary rendering directory's path + * The directory to render the frames into * @type {String} */ -var renderDir = path.join(__dirname, 'frames'); +const renderDir = process.argv[2]; /** * The step option * To reduce the number of rendered frames (step > 1) * @type {Number} */ -var step = process.argv[2] || 1; +const step = process.argv[3] || 1; // Hide the Dock for macOS if (os.platform() == 'darwin') { From 2533271eca2615e3b99c9dbdb3ed69a77edf5996 Mon Sep 17 00:00:00 2001 From: Mohammad Fares Date: Sun, 9 Jul 2023 12:29:12 +0200 Subject: [PATCH 2/3] Render in the created temporry directory --- commands/render.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/commands/render.js b/commands/render.js index 905840b..1e188cb 100644 --- a/commands/render.js +++ b/commands/render.js @@ -5,6 +5,10 @@ * @author Mohammad Fares */ +const tmp = require('tmp'); + +tmp.setGracefulCleanup(); + /** * The directory to render the frames into */ @@ -85,7 +89,7 @@ function loadPNG(path) { */ function getFrameDimensions() { // The path of the first rendered frame - var framePath = di.path.join(ROOT_PATH, "render/frames/0.png"); + var framePath = di.path.join(renderDir, "0.png"); // Read and parse a PNG image file return loadPNG(framePath).then(function (png) { @@ -95,7 +99,6 @@ function getFrameDimensions() { }; }); } - /** * Render the frames into PNG images * @@ -210,7 +213,6 @@ function mergeFrames(records, options, frameDimensions) { // Write the headers gif.writeHeader(); - // Foreach frame di.async.eachOfSeries( records, function (frame, index, callback) { @@ -222,11 +224,7 @@ function mergeFrames(records, options, frameDimensions) { stepsCounter = (stepsCounter + 1) % options.step; // The path of the rendered frame - var framePath = di.path.join( - ROOT_PATH, - "render/frames", - index + ".png" - ); + var framePath = di.path.join(renderDir, index + ".png"); // Read and parse the rendered frame loadPNG(framePath) @@ -255,7 +253,7 @@ function mergeFrames(records, options, frameDimensions) { // Write the footer gif.finish(); - + // Finish console.log(di.chalk.green('[merge] Process successfully completed in ' + (Date.now() - start) + 'ms.')); resolve(); From e0b5107233b56bf8ebfe9757e3f86bee0556b12b Mon Sep 17 00:00:00 2001 From: Mohammad Fares Date: Sat, 15 Jul 2023 20:44:27 +0200 Subject: [PATCH 3/3] Change the config directory to be under ~/.config for Mac and Linux --- README.md | 2 +- commands/init.js | 2 +- utility.js | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e5e86f7..4305d15 100644 --- a/README.md +++ b/README.md @@ -243,7 +243,7 @@ terminalizer config terminalizer init ``` -For Linux and MacOS, the created directory is located under the home directory `~/.terminalizer`. For Windows, it is located under the `AppData`. +For Linux and MacOS, the created directory is located under the home directory `~/config/terminalizer`. For Windows, it is located under the `AppData`. ## Recording diff --git a/commands/init.js b/commands/init.js index a4a32f7..d497882 100644 --- a/commands/init.js +++ b/commands/init.js @@ -32,7 +32,7 @@ function command(argv) { // Create the global directory try { - di.fs.mkdirSync(di.utility.getGlobalDirectory()); + di.fs.mkdirSync(di.utility.getGlobalDirectory(), { recursive: true }); } catch (error) { diff --git a/utility.js b/utility.js index 992f294..b5922c2 100644 --- a/utility.js +++ b/utility.js @@ -235,14 +235,12 @@ function changeYAMLValue(data, key, value) { * @return {String} */ function getGlobalDirectory() { - // Windows if (typeof process.env.APPDATA != 'undefined') { return di.path.join(process.env.APPDATA, 'terminalizer'); } - return di.path.join(process.env.HOME, '.terminalizer'); - + return di.path.join(process.env.HOME, '.config/terminalizer'); } /**