Skip to content

Commit

Permalink
Merge pull request #226 from faressoft/use-temp-rendering-dir
Browse files Browse the repository at this point in the history
Fix: Use Temporary Directory for GIF Rendering (Fixes #216)
  • Loading branch information
faressoft authored Jul 15, 2023
2 parents 38fc00f + e0b5107 commit 88afc77
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
23 changes: 13 additions & 10 deletions commands/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
* @author Mohammad Fares <[email protected]>
*/

const tmp = require('tmp');

tmp.setGracefulCleanup();

/**
* The directory to render the frames into
*/
var renderDir = tmp.dirSync({ unsafeCleanup: true }).name;

/**
* Create a progress bar for processing frames
*
Expand Down Expand Up @@ -80,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) {
Expand All @@ -90,7 +99,6 @@ function getFrameDimensions() {
};
});
}

/**
* Render the frames into PNG images
*
Expand All @@ -115,7 +123,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 }
);

Expand Down Expand Up @@ -205,7 +213,6 @@ function mergeFrames(records, options, frameDimensions) {
// Write the headers
gif.writeHeader();

// Foreach frame
di.async.eachOfSeries(
records,
function (frame, index, callback) {
Expand All @@ -217,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)
Expand Down Expand Up @@ -250,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();
Expand Down
46 changes: 33 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
6 changes: 3 additions & 3 deletions render/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
4 changes: 1 addition & 3 deletions utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down

0 comments on commit 88afc77

Please sign in to comment.