-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
141 lines (128 loc) · 3.95 KB
/
index.js
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* globals CSInterface, cep, SystemPath */
'use strict';
angular.module('codemill.adobe', [])
.service('cmAdobeService', ['$window', '$q', '$log',
function ($window, $q, $log) {
var csInterface = new CSInterface();
var hostAvailable = typeof(csInterface.openURLInDefaultBrowser) !== 'undefined';
function evalCSScriptDefer(script, returnIsObject) {
var deferred = $q.defer();
csInterface.evalScript(script, function(data) {
deferred.resolve(returnIsObject ? JSON.parse(data) : data);
});
return deferred.promise;
}
function variableAsString(variable) {
return variable === undefined ? 'undefined' :
(variable === null ? 'null' : '\'' + variable + '\'');
}
var callToScript = function(callOpts) {
var call = callOpts.method + '(';
if (callOpts.args && callOpts.args.length > 0) {
var first = true;
for (var i = 0; i < callOpts.args.length; i++) {
if (!first) {
call += ', ';
}
var arg = callOpts.args[i];
if (typeof(arg) === 'object') {
arg = JSON.stringify(arg);
}
call += variableAsString(arg);
first = false;
}
}
call += ')';
return call;
};
this.callCS = function(callOpts) {
if (hostAvailable) {
return evalCSScriptDefer(callToScript(callOpts), callOpts.returnsObject);
} else {
return $q.when();
}
};
this.registerEventListener = function(eventId, callback) {
if (hostAvailable) {
csInterface.addEventListener(eventId, callback);
}
};
this.openURLInDefaultBrowser = function (url) {
if (hostAvailable) {
csInterface.openURLInDefaultBrowser(url);
} else {
$window.open(url);
}
};
var pathSeparator = function () {
var OSVersion = csInterface.getOSInformation();
if (OSVersion.indexOf('Mac') >= 0) {
return '/';
} else {
return '\\';
}
};
var getBase = function(pathType) {
if (!hostAvailable) {
if (pathType === undefined || pathType === null) {
pathType = 'documents';
}
return '/tmp/' + pathType + '/';
} else {
var type;
switch(pathType) {
case 'documents':
type = SystemPath.MY_DOCUMENTS;
break;
case 'extension':
type = SystemPath.EXTENSION;
break;
case 'userdata':
type = SystemPath.USER_DATA;
break;
default:
type = SystemPath.MY_DOCUMENTS;
break;
}
return csInterface.getSystemPath(type) + pathSeparator();
}
};
this.getFilePath = function (config) {
if (config === undefined || config === null) {
return config;
}
var base = null;
switch(config.pathType) {
case 'null':
return null;
case 'full':
if (hostAvailable) {
cep.fs.makedir(config.filePath);
}
return config.filePath;
default:
base = getBase(config.pathType);
break;
}
var filePath = base + config.filePath;
if (!config.isFile) {
if (hostAvailable) {
cep.fs.makedir(filePath);
filePath += pathSeparator();
} else {
filePath += '/';
}
}
$log.info('File path ' + filePath);
return filePath;
};
this.isHostAvailable = function () {
return hostAvailable;
};
this.openDirectoryDialog = function(title, initialPath) {
if (hostAvailable) {
return cep.fs.showOpenDialog(false, true, title, initialPath);
}
return '';
};
}]);