-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathscript.js
More file actions
223 lines (197 loc) · 6.2 KB
/
script.js
File metadata and controls
223 lines (197 loc) · 6.2 KB
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
const { WINE_PREFIX_DIR } = include("engines.wine.engine.constants");
const ShortcutInfoDTOBuilderClass = Java.type("org.phoenicis.library.dto.ShortcutInfoDTO.Builder");
const ShortcutDTOBuilderClass = Java.type("org.phoenicis.library.dto.ShortcutDTO.Builder");
/**
* WineShortcut prototype
*/
// eslint-disable-next-line no-unused-vars
module.default = class WineShortcut {
constructor() {
this._shortcutManager = Bean("shortcutManager");
this._appsManager = Bean("repositoryManager");
this._fileSearcher = Bean("fileSearcher");
this._winePrefixesDirectory =
Bean("propertyReader").getProperty("application.user.containers") + "/" + WINE_PREFIX_DIR + "/";
this._category = "Other";
this._description = "";
}
/**
* Sets the shortcut name
*
* @param {string} name The shortcut name
* @returns {WineShortcut} The WineShortcut object
*/
name(name) {
this._name = name;
return this;
}
/**
* Sets the shortcut type
*
* @param {string} type The shortcut type
* @returns {WineShortcut} The WineShortcut object
*/
type(type) {
this._type = type;
return this;
}
/**
* Sets the shortcut category
*
* @param {string} category The shortcut category
* @returns {WineShortcut} The WineShortcut object
*/
category(category) {
this._category = category;
return this;
}
/**
* Sets the shortcut description
*
* @param {string} description The shortcut description
* @returns {WineShortcut} The WineShortcut object
*/
description(description) {
this._description = description;
return this;
}
/**
* Sets the shortcut arguments
*
* @param {array} args The shortcut arguments
* @returns {WineShortcut} The WineShortcut object
*/
arguments(args) {
this._arguments = args;
return this;
}
/**
* Sets the executable which shall be used
*
* @param {string} search The executable name
* @returns {WineShortcut} The WineShortcut object
*/
search(search) {
this._search = search;
return this;
}
/**
* Sets the shortcut prefix
*
* @param {string} prefix The shortcut prefix
* @returns {WineShortcut} The WineShortcut object
*/
prefix(prefix) {
this._prefix = prefix;
return this;
}
/**
* Sets the miniature for the shortcut
*
* @param {string[]|URI} miniature An array which specifies the application of which the miniature shall be used or URI of the miniature
* @returns {WineShortcut} The WineShortcut object
*/
miniature(miniature) {
if (Array.isArray(miniature)) {
// application of miniature given
const application = this._appsManager.getApplication(miniature);
if (application != null && application.getMainMiniature().isPresent()) {
this._miniature = application.getMainMiniature().get();
}
} else {
// miniature URI given
this._miniature = miniature;
}
return this;
}
/**
* Sets the category icon for the shortcut
*
* @param {string[]|URI} icon An array which specifies the category of which the icon shall be used or URI of the icon
* @returns {WineShortcut} The WineShortcut object
*/
categoryIcon(icon) {
if (Array.isArray(icon)) {
// category of icon given
const category = this._appsManager.getCategory(icon);
if (category != null) {
this._categoryIcon = category.getIcon();
}
} else {
// icon URI given
this._categoryIcon = icon;
}
return this;
}
/**
* Sets the shortcut environment variables
*
* @param {string} environment The environment variables
* @returns {WineShortcut} The WineShortcut object
*/
environment(environment) {
this._environment = environment;
return this;
}
/**
* Sets the trust level
*
* @param {string} trustLevel The trust level
* @returns {WineShortcut} The WineShortcut object
*/
trustLevel(trustLevel) {
this._trustLevel = trustLevel;
return this;
}
/**
* Creates a new shortcut
*
* @returns {void}
*/
create() {
const shortcutPrefixDirectory = this._winePrefixesDirectory + "/" + this._prefix;
const executables = this._fileSearcher.search(shortcutPrefixDirectory, this._search);
if (executables.length == 0) {
throw tr("Executable {0} not found!", this._search);
}
const info = new ShortcutInfoDTOBuilderClass()
.withCategory(this._category)
.withName(this._name)
.withDescription(this._description)
.build();
const myEnv = { WINEDEBUG: "-all" };
if (typeof this._environment !== "undefined") {
var envJSON = JSON.parse(this._environment);
Object.keys(envJSON).forEach((key) => {
myEnv[key] = envJSON[key];
});
}
let trustLevel;
if (typeof this._trustLevel !== "undefined") {
trustLevel = this._trustLevel;
} else {
trustLevel = "0"; //dummy value
}
const builder = new ShortcutDTOBuilderClass()
.withId(this._name)
.withInfo(info)
.withScript(
JSON.stringify({
type: "WINE",
environment: myEnv,
trustLevel: trustLevel,
winePrefix: this._prefix,
arguments: this._arguments,
workingDirectory: executables[0].getParentFile().getAbsolutePath(),
executable: executables[0].getAbsolutePath()
})
);
if (this._miniature) {
builder.withMiniature(this._miniature);
}
if (this._categoryIcon) {
builder.withCategoryIcon(this._categoryIcon);
}
this._shortcutManager.createShortcut(builder.build());
}
}