Skip to content

Commit 495ce28

Browse files
committed
Bugfix for multiple callback inside async system like 'async' for nodejs
1 parent 0250014 commit 495ce28

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

ftpm-module.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,38 @@ var ftpm = require('./lib/ftpm');
22

33
var ftpmModule = {
44
installOsFont: function(fontName, cb) {
5-
ftpm.callbackFunction = cb;
5+
ftpm.callbackLink = cb;
66
ftpm.emit('runDriver', 'osfont', 'install', fontName);
77
},
88
uninstallOsFont: function(fontName, cb) {
99
fontName = fontName.toTitleCase();
10-
ftpm.callbackFunction = cb;
10+
ftpm.callbackAlreadyFired = false;
11+
ftpm.callbackLink = cb;
1112
if (existsSync(ftpm.path.getFontPath(ftpm.platform) + fontName.removeSpaces() + '.ftpm.ttf')) {
1213
ftpm.emit('runDriver', 'osfont', 'uninstall', fontName);
1314
}
1415
},
1516
listIntalledFonts: function(cb) {
16-
ftpm.callbackFunction = cb;
17+
ftpm.callbackAlreadyFired = false;
18+
ftpm.callbackLink = cb;
1719
ftpm.emit('runDriver', 'osfont', 'local', '');
1820
},
1921
downloadWebFont: function(fontName, fontPath, cb) {
20-
ftpm.callbackFunction = cb;
22+
ftpm.callbackAlreadyFired = false;
23+
ftpm.callbackLink = cb;
2124
ftpm.outputPath = fontPath;
2225
ftpm.emit('runDriver', 'webfont', 'web', fontName);
2326
},
2427
getCssFont: function(fontName, fontPath, cb) {
25-
ftpm.callbackFunction = cb;
28+
ftpm.callbackAlreadyFired = false;
29+
ftpm.callbackLink = cb;
2630
ftpm.outputPath = fontPath;
2731
ftpm.showContent = (!fontPath) ? true : false;
2832
ftpm.emit('runDriver', 'cssfont', 'css', fontName);
2933
},
3034
getDataURI: function(fontName, fontPath, cb) {
31-
ftpm.callbackFunction = cb;
35+
ftpm.callbackAlreadyFired = false;
36+
ftpm.callbackLink = cb;
3237
ftpm.outputPath = fontPath;
3338
ftpm.showContent = (!fontPath) ? true : false;
3439
ftpm.emit('runDriver', 'cssfont', 'datauri', fontName);

lib/ftpm.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ ftpm = _.extend(ftpm, {
1111
platform: process.platform,
1212
file: require('./utils/file'),
1313
path: require('./utils/path'),
14-
callbackFunction: function(type, msg) {},
14+
callbackFunction: function(type, msg) {
15+
if(!ftpm.callbackAlreadyFired) {
16+
ftpm.callbackAlreadyFired = true;
17+
ftpm.callbackLink(type, msg);
18+
}
19+
},
20+
callbackLink: function (type, msg) {},
21+
callbackAlreadyFired: false,
1522
outputPath: false,
1623
showContent:false
1724
});

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ftpm-module",
3-
"version": "0.0.6",
3+
"version": "0.0.7",
44
"description": "Porting of ftpm library can be used as a class within nodejs.",
55
"main": "ftpm-module.js",
66
"dependencies": {
@@ -32,13 +32,13 @@
3232
"fonts"
3333
],
3434
"author": {
35-
"name": "Marco Bicchi"
35+
"name": "Marco Bicchi, Daniele Sassoli"
3636
},
3737
"license": "MIT",
3838
"bugs": {
3939
"url": "https://github.com/alanmastro/ftpm-module/issues"
4040
},
4141
"homepage": "https://github.com/alanmastro/ftpm-module",
42-
"_id": "ftpm-module@0.0.6",
43-
"_resolved": "https://github.com/alanmastro/ftpm-module/archive/0.0.6.tar.gz"
42+
"_id": "ftpm-module@0.0.7",
43+
"_resolved": "https://github.com/alanmastro/ftpm-module/archive/0.0.7.tar.gz"
4444
}

0 commit comments

Comments
 (0)