-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate-action-list.js
59 lines (45 loc) · 1.93 KB
/
generate-action-list.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
/*
generate-action-list.js
Generates an object containing all the actions and permissions in WFActions.plist and saves it to actions.json.
Permissions with a value of `null` in permissions.json are ignored.
Action listings in overrides.json take precedence over WFActions.plist.
Supports macOS, iOS (direct filesystem access), and iSH on iOS.
*/
const bplist = require('bplist-parser');
const { writeFileSync } = require('fs');
const actionsJSONPath = './actions.json';
const actions = require(actionsJSONPath);
const overrides = require('./overrides.json');
const permissions = require('./permissions.json');
function pushOrNot(arr, item) {
if ((permissions[item] != null) && (!arr.includes(item))) arr.push(item);
}
(async () => {
const actionsDict = await bplist.parseFile(require('./get-wfactions-path.js'))[0];
for (const actionID in actionsDict) {
let perms = [];
if (overrides[actionID]) {
perms = overrides[actionID];
} else {
const resources = actionsDict[actionID].RequiredResources;
if (resources) {
for (const resource of resources) {
if (typeof resource === "string") {
pushOrNot(perms, resource)
} else {
if (resource.WFAccountClass) {
pushOrNot(perms, resource.WFAccountClass);
} else {
pushOrNot(perms, resource.WFResourceClass);
}
}
}
}
if (actionsDict[actionID].AppIdentifier == "com.apple.Preferences") pushOrNot(perms, "Settings");
if (actionsDict[actionID].AppIdentifier == "com.apple.TVRemoteUIService") pushOrNot(perms, "Apple TV Remote");
}
perms.sort();
actions[actionID] = perms;
}
writeFileSync(actionsJSONPath, JSON.stringify(actions, null, 4));
})();