forked from Inventsable/CEP-Spy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
469 lines (457 loc) · 14.5 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
const path = window.__adobe_cep__ ? require("path") : null;
const fs = window.__adobe_cep__ ? require("fs") : null;
/**
*
* @param {String} str - The path to attempt resolution to
* @param {Boolean} asJSON - If data should return as parsed JSON
*/
function resolveString(str, asJSON = false) {
let result;
result = path.resolve(
str.replace(
/file\:\/{1,}/,
navigator.platform.indexOf("Mac") > -1 ? "/" : ""
)
);
if (navigator.platform.indexOf("Mac") > -1)
result = result.replace(/\\{1}/gm, "/");
return asJSON ? JSON.parse(result) : result;
}
function getRoot() {
let result = resolveString(window.__adobe_cep__.getSystemPath("extension"));
if (fs.existsSync(result)) return result;
else if (fs.existsSync(decodeURI(result))) return decodeURI(result);
else if (fs.existsSync(result.replace(/%20/gm, " ")))
return result.replace.replace(/%20/gm, " ");
else if (fs.existsSync(path.resolve(result))) return path.resolve(result);
else {
console.log("ROOT RESOLUTION FAILED:", result);
return result;
}
}
/**
*
* @param {String} root - Base extension path
* @param {String} file - Name of file to read
* @param {String} key - When a parsed JSON, return as this key value
* @param {Boolean} asJSON - If data should return as parsed JSON
*/
function tryReadingFile(root, file, key = "", asJSON = false) {
root = root && root.length ? root : getRoot();
let target = resolveString(`${root}/${file}`);
if (fs.existsSync(target)) {
let data = fs.readFileSync(target, "utf-8");
return asJSON
? key || key.length
? JSON.parse(data)[key]
? JSON.parse(data)[key]
: ""
: JSON.parse(data)
: data;
} else if (fs.existsSync(target.replace(/%20/gm, " "))) {
let data = fs.readFileSync(target.replace(/%20/gm, " "), "utf-8");
return asJSON
? key || key.length
? JSON.parse(data)[key]
? JSON.parse(data)[key]
: ""
: JSON.parse(data)
: data;
} else if (fs.existsSync(decodeURI(target))) {
console.log("DecodeURI does work");
let data = fs.readFileSync(decodeURI(target), "utf-8");
return asJSON
? key || key.length
? JSON.parse(data)[key]
? JSON.parse(data)[key]
: ""
: JSON.parse(data)
: data;
} else {
console.error("Target not found:", file, target);
return null;
}
}
/**
* Should be a platform independent way to get localhost
*/
function getLocalHost() {
let data = tryReadingFile("", "/.debug");
if (!data) return "http://localhost:8081";
return `http://localhost:${
data.match(
new RegExp(
`\\<Host\\sName\\=\\"${
JSON.parse(window.__adobe_cep__.getHostEnvironment()).appName
}\\"\\sPort\\=\\"(\\d*)`
)
)[1]
}`;
}
/**
* Should be a platform independent way to get manifest
*/
function getManifestVersion() {
let data = tryReadingFile("", "/CSXS/manifest.xml");
if (!data) return "1.0.0";
return data
.match(/ExtensionBundleVersion\=\"(\d|\.)*(?=\")/)[0]
.replace(/\w*\=\"/, "");
}
//
//
//
function doubleCheckPathIntegrity(spy) {
if (!window.__adobe_cep__) return spy;
let root = resolveString(window.__adobe_cep__.getSystemPath("extension"));
let target = resolveString(`${root}/package.json`);
if (fs.existsSync(target) || fs.readFileSync(decodeURI(target), "utf-8")) {
if (navigator.platform.indexOf("Mac") < 1) {
Object.keys(spy.path).forEach((item) => {
if (item == "root") spy.path[item] = getRoot();
else if (fs.existsSync(spy.path[item].replace(/\%20/gm, " ")))
spy.path[item] = spy.path[item].replace(/\%20/gm, " ");
else if (fs.existsSync(decodeURI(spy.path[item])))
spy.path[item] = decodeURI(spy.path[item]);
else {
console.log("NO MATCH:", item, spy.path[item]);
}
});
}
return spy;
} else if (fs.existsSync(target.replace(/%20/g, " "))) {
Object.keys(spy.path).forEach((item) => {
spy.path[item] = spy.path[item].replace(/%20/g, " ");
});
} else {
console.error("Double check failed.");
return spy;
}
return spy;
}
// If this is browser, return a fake object with static values. Otherwise, be dynamic per host app
let spy = !window.__adobe_cep__
? {
path: {
root:
"C:/Users/TRSch/AppData/Roaming/Adobe/CEP/extensions/panelify-demo",
userData: "C:/Users/TRSch/AppData/Roaming",
commonFiles: "C:/Program Files/Common Files",
myDocuments: "C:/Users/TRSch/OneDrive/Documents",
hostApplication:
"C:/Program Files/Adobe/Adobe Illustrator 2020/Support Files/Contents/Windows/Illustrator.exe",
},
package: {
name: "panelify-demo",
version: "1.0.0",
description: "Bombino-quasar-panelify template",
productName: "Quasar Panelify",
cordovaId: "org.cordova.panelify",
repository: "Inventsable/bombino-quasar-panelify",
author: "Tom Scharstein II <[email protected]>",
homepage: "https://github.com/Inventsable/panelify-demo",
capacitorId: "",
private: true,
scripts: {
serve: "quasar dev",
build: "quasar build",
sign: "bombino-cmd sign",
switch: "bombino-cmd switch",
update: "bombino-cmd update",
register: "bombino-cmd register",
help: "bombino-cmd help",
convert: "node ./bin/convertToPanelify.js",
},
dependencies: {
"@quasar/extras": "^1.0.0",
"cep-spy": "^1.1.1",
cluecumber: "0.0.31",
"lottie-web": "^5.5.9",
quasar: "^1.0.0",
starlette: "^0.4.5",
},
devDependencies: {
"@quasar/app": "^1.0.0",
"@quasar/quasar-app-extension-dotenv": "^1.0.0",
"bombino-commands": "^1.0.1",
chalk: "^3.0.0",
"fs-extra": "^8.1.0",
inquirer: "^7.0.0",
"types-for-adobe": "^1.5.0",
},
engines: {
node: ">= 8.9.0",
npm: ">= 5.6.0",
yarn: ">= 1.6.0",
},
browserslist: ["last 1 version, not dead, ie >= 11"],
},
author: "Tom Scharstein II <[email protected]>",
repository: "Inventsable/bombino-quasar-panelify",
homepage: "https://github.com/Inventsable/panelify-demo",
localhost: "http://localhost:2266",
isDev: true,
extVersion: "1.0.0",
appName: "ILST",
appLocale: "en_US",
appVersion: "24.0.0",
userAgent: "Windows",
cepVersion: "9.4.0",
hostCapabilities: {
DISABLE_FLASH_EXTENSIONS: false,
EXTENDED_PANEL_ICONS: true,
SUPPORT_HTML_EXTENSIONS: true,
DELEGATE_APE_ENGINE: false,
EXTENDED_PANEL_MENU: true,
},
userId: "",
extID: "com.panelify-demo.panel",
exts: [],
ext: {
mainPath:
"C:\\Users\\TRSch\\AppData\\Roaming\\Adobe\\CEP\\extensions\\panelify-demo\\src\\index-dev.html",
maxHeight: 500,
maxWidth: 598,
specialExtensionDataXML: "",
id: "com.panelify-demo.panel",
name: "panelify-demo",
width: 280,
windowType: "Panel",
isAutoVisible: true,
basePath:
"C:\\Users\\TRSch\\AppData\\Roaming\\Adobe\\CEP\\extensions\\panelify-demo",
height: 400,
minWidth: 260,
requiredRuntimeList: [
{
name: "CSXS",
versionRange: {
lowerBound: {
version: {
minor: 0,
micro: 0,
major: 8,
},
inclusive: true,
},
},
},
],
minHeight: 300,
isPluginExtension: false,
defaultExtensionDataXML: "",
},
activeExt: {
mainPath:
"C:\\Users\\TRSch\\AppData\\Roaming\\Adobe\\CEP\\extensions\\panelify-demo\\src\\index-dev.html",
maxHeight: 500,
maxWidth: 598,
specialExtensionDataXML: "",
id: "com.panelify-demo.panel",
name: "panelify-demo",
width: 280,
windowType: "Panel",
isAutoVisible: true,
basePath:
"C:\\Users\\TRSch\\AppData\\Roaming\\Adobe\\CEP\\extensions\\panelify-demo",
height: 400,
minWidth: 260,
requiredRuntimeList: [
{
name: "CSXS",
versionRange: {
lowerBound: {
version: {
minor: 0,
micro: 0,
major: 8,
},
inclusive: true,
},
},
},
],
minHeight: 300,
isPluginExtension: false,
defaultExtensionDataXML: "",
},
extName: "panelify-demo",
getAllExtensions() {
return null;
},
getExtData(id) {
return null;
},
openExtension(ext) {
return null;
},
getVersion(ext) {
return this.extVersion;
},
launchLocalhost(url = null) {
return null;
},
launchInNewTab(url) {
window.open(url);
},
launchHomepage() {
if (this.homepage) this.launchInNewTab(this.homepage || null);
else console.log("Panel has no homepage defined in package.json");
},
launchGitRepo() {
if (this.repository)
this.launchInNewTab("https://github.com/" + this.repository);
else console.log("Panel has no repo defined in package.json");
},
}
: {
path: {
root: resolveString(window.__adobe_cep__.getSystemPath("extension")),
userData: resolveString(window.__adobe_cep__.getSystemPath("userData")),
commonFiles: resolveString(
window.__adobe_cep__.getSystemPath("commonFiles")
),
myDocuments: resolveString(
window.__adobe_cep__.getSystemPath("myDocuments")
),
hostApplication: resolveString(
window.__adobe_cep__.getSystemPath("hostApplication")
),
},
// package: tryReadingFile(
// window.__adobe_cep__.getSystemPath("extension"),
// "/package.json",
// "",
// true
// ),
// author: tryReadingFile(
// window.__adobe_cep__.getSystemPath("extension"),
// "/package.json",
// "author",
// true
// ),
// repository: tryReadingFile(
// window.__adobe_cep__.getSystemPath("extension"),
// "/package.json",
// "repository",
// true
// ),
// homepage: tryReadingFile(
// window.__adobe_cep__.getSystemPath("extension"),
// "/package.json",
// "homepage",
// true
// ),
localhost: getLocalHost(),
isDev: /localhost/.test(document.location.href),
extVersion: getManifestVersion(),
appName: JSON.parse(window.__adobe_cep__.getHostEnvironment()).appName,
appLocale: JSON.parse(window.__adobe_cep__.getHostEnvironment())
.appLocale,
appVersion: JSON.parse(window.__adobe_cep__.getHostEnvironment())
.appVersion,
userAgent:
navigator.platform.indexOf("Win") > -1
? "Windows"
: navigator.platform.indexOf("Mac") > -1
? "Mac"
: "Unknown",
cepVersion: `${
JSON.parse(window.__adobe_cep__.getCurrentApiVersion()).major
}.${JSON.parse(window.__adobe_cep__.getCurrentApiVersion()).minor}.${
JSON.parse(window.__adobe_cep__.getCurrentApiVersion()).micro
}`,
hostCapabilities: JSON.parse(window.__adobe_cep__.getHostCapabilities()),
userId: window.__adobe_cep__.getCurrentImsUserId(),
extID: window.__adobe_cep__.getExtensionId(),
exts: JSON.parse(window.__adobe_cep__.getExtensions()),
ext: JSON.parse(window.__adobe_cep__.getExtensions()).find((ext) => {
return ext.id == window.__adobe_cep__.getExtensionId();
}),
activeExt: JSON.parse(window.__adobe_cep__.getExtensions()).find(
(ext) => {
return ext.id == window.__adobe_cep__.getExtensionId();
}
),
extName: JSON.parse(window.__adobe_cep__.getExtensions()).find((ext) => {
return ext.id == window.__adobe_cep__.getExtensionId();
}).name,
getAllExtensions() {
return JSON.parse(window.__adobe_cep__.getExtensions()).map((ext) => {
let obj = {};
obj["version"] = this.getVersion(ext);
return Object.assign(obj, ext);
});
},
getExtData(id) {
const target = JSON.parse(window.__adobe_cep__.getExtensions()).find(
(ext) => {
return ext.id == id;
}
);
target["version"] = this.getVersion(target);
return target;
},
openExtension(ext) {
window.__adobe_cep__.requestOpenExtension(ext.id);
},
getVersion(ext) {
const xml = window.cep.fs.readFile(`${ext.basePath}/CSXS/manifest.xml`);
const verID = /ExtensionBundleVersion\=\"(\d|\.)*(?=\")/;
const match = xml.data.match(verID);
return match && match.length
? match[0].replace(/\w*\=\"/, "")
: "unknown";
},
launchLocalhost(url = null) {
this.launchInNewTab(url || this.localhost);
},
launchInNewTab(url) {
if (url) cep.util.openURLInDefaultBrowser(url);
},
launchHomepage() {
if (this.homepage) this.launchInNewTab(this.homepage || null);
else console.log(`Panel has no homepage defined in package.json`);
},
launchGitRepo() {
if (this.repository)
this.launchInNewTab(`https://github.com/${this.repository}`);
else console.log(`Panel has no repo defined in package.json.`);
},
};
spy = doubleCheckPathIntegrity(spy);
export default spy;
//
//
// UNUSED
//
//
/**
* @param {String} string - The string to sanitize as Mac equivalent
* @returns {String} - A correctly formatted path regardless of OS
*/
function getRealString(string) {
return navigator.platform.indexOf("Mac") > -1
? `/${string}`.replace(/\s/g, "\\ ")
: string;
}
/**
* @param {Object} parent - The containing object to recurse through
*/
function recheckPathData(parent) {
function fixPath(string) {
return navigator.platform.indexOf("Mac") > -1
? `/${string}`.replace(/\s/g, "\\ ")
: string;
}
Object.keys(parent).forEach((key) => {
if (/object/i.test(typeof parent[key]))
parent[key] = recheckPathData(parent[key]);
else if (
/string/i.test(typeof parent[key]) &&
/(\\|\/)\w{1,}(\\|\/)/.test(parent[key])
)
parent[key] = fixPath(parent[key]);
});
return parent;
}