-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathappnativefy.js
executable file
·286 lines (249 loc) · 7.39 KB
/
appnativefy.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
#!/usr/bin/env node
const fs = require('fs');
var yargs = require('yargs');
var nativefier = require('nativefier').default;
var process = require('process');
const request = require('request')
const {
exec
} = require("child_process");
var blankstr = ""
const dirname = __dirname;
var style = blankstr.concat(__dirname, "/style.css");
console.log(__dirname);
var argv = require('yargs/yargs')(process.argv.slice(2))
.usage('Make executable AppImages from any Website URL\n\nUsage: $0 [options]')
.help('help').alias('help', 'h')
.version('version', '2.0.0').alias('version', 'V')
.options({
name: {
alias: 'n',
description: "<name> Input website name",
requiresArg: true,
required: true
},
url: {
alias: 'u',
description: "<url> Website url",
requiresArg: true,
required: true
},
internalurls: {
description: "<REGEX> internal urls",
requiresArg: true,
required: false
},
appCopyright: {
description: "<value> Copyright information",
requiresArg: true,
required: false
},
appVersion: {
description: "<value> App version info",
requiresArg: true,
required: false
},
})
.options({
blockexternalurls: {
description: "Block URLs that do not match internal URLs",
},
saveAs: {
description: "Show a 'Save as' dialog, while downloading items",
},
favicon: {
description: "Force use website favicon, as AppImage icon",
},
widevine: {
description: "Widevine support (for sites with DRM protected content)",
},
services: {
description: "Google/Microsoft 365 sign-in support",
},
noOverwrite: {
description: "Specifies if destination directory should not be overwritten",
},
conceal: {
description: "Conceals the source code within the AppImage into an archive",
},
counter: {
description: "Use a counter that persists even with window focus for the application badge",
},
singleinstance: {
description: "Single instance of application",
},
disablegpu: {
description: "Disable hardware acceleration"
}
})
.argv;
str = argv.name
var name = str.replace(/\s+/g, '-')
var url = argv.url
var appnativefydir = blankstr.concat(process.env['HOME'], "/appnativefy");
try {
if (!fs.existsSync(appnativefydir)) {
fs.mkdirSync(appnativefydir);
}
} catch (err) {
console.log(err);
}
if (argv.appCopyright === undefined) {
var appcopyright = "";
} else {
var appcopyright = argv.appCopyright
}
if (argv.appVersion === undefined) {
var appversion = "1.0.0";
} else {
var appversion = argv.appVersion
}
if (argv.widevine === true) {
var widevine = true
} else {
var widevine = false
}
const download = (favicongen, icon, callback) => {
request.head(favicongen, (err, res, body) => {
request(favicongen)
.pipe(fs.createWriteStream(icon))
.on('close', callback)
})
}
if (argv.favicon === true) {
var favicon = "true"
} else {
var favicon = "false"
}
if (argv.services === true) {
var honest = false
var services = '"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:85.0) Gecko/20100101 Firefox/85.0"';
if (argv.internalurls === undefined) {
var internalurls = '(.*)';
if (argv.blockexternalurls === true) {
var blockexternalurls = true;
} else {
var blockexternalurls = false
}
} else {
var internalurls = argv.internalurls
}
} else {
var honest = true
var services = ""
if (argv.internalurls === undefined) {
var internalurls = ".*?";
} else {
var internalurls = argv.internalurls
}
}
if (argv.saveAs === true) {
var downloaddialog = true;
} else {
var downloaddialog = false;
}
if (argv.noOverwrite === true) {
var overwrite = false;
} else {
var overwrite = true
}
if (argv.conceal === true) {
var conceal = true;
} else {
var conceal = false
}
if (argv.counter === true) {
var counter = true;
} else {
var counter = false
}
if (argv.singleinstance === true) {
var singleinstance = true;
} else {
var singleinstance = false
}
var options = {
name: name, // will be inferred if not specified
targetUrl: url, // required
platform: 'linux', // defaults to the current system
arch: 'x64', // defaults to the current system
copyright: appcopyright,
version: appversion,
inject: style,
out: appnativefydir,
overwrite: overwrite,
asar: conceal, // see conceal
counter: counter,
bounce: false,
width: 1280,
height: 800,
showMenuBar: false,
fastQuit: false,
userAgent: services, // will infer a default for your current system
ignoreCertificate: false,
ignoreGpuBlacklist: false,
enableEs3Apis: false,
internalUrls: internalurls, // defaults to URLs on same second-level domain as app
blockExternalUrls: blockexternalurls,
insecure: false,
honest: honest,
widevine: widevine,
zoom: 1.0,
singleInstance: singleinstance,
verbose: false,
clearCache: false,
fileDownloadOptions: {
saveAs: downloaddialog, // always show "Save As" dialog
},
};
nativefier(options, function (error, appPath) {
if (error) {
console.error(error);
return;
}
var apptempdir = appnativefydir.concat("/.appimage-temp");
var appimagetooldir = appnativefydir.concat("/.appimagetool");
console.log(appnativefydir);
try {
if (!fs.existsSync(apptempdir)) {
fs.mkdirSync(apptempdir);
} else {}
} catch (err) {
console.log(err);
}
try {
if (!fs.existsSync(appimagetooldir)) {
fs.mkdirSync(appimagetooldir);
} else {}
} catch (err) {
console.log(err);
}
var oldPath = appnativefydir.concat("/", name, "-linux-x64")
var newPath = apptempdir.concat("/", name, ".AppDir")
fs.rename(oldPath, newPath, function (err) {
if (err) throw err
console.log('Successfully moved file.')
})
var scriptsource = blankstr.concat(__dirname, "/script.sh")
var scriptout = blankstr.concat(appnativefydir, "/.script.sh")
fs.copyFile(scriptsource, scriptout, (err) => {
if (err) throw err;
console.log(scriptsource, 'was copied to', scriptout);
process.chdir(appnativefydir);
commandscript = blankstr.concat("chmod 755 ~/appnativefy/.script.sh && ~/appnativefy/.script.sh", " ", name, " ", dirname, " ", favicon, " ", url, "&& rm -rf ~/appnativefy/.script.sh && rm -rf ~/appnativefy/.icon.png"); {
exec(commandscript, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
};
});
var appPath = appnativefydir.concat("/", name, "-x86_64.AppImage")
console.log('AppImage has been made to', appPath);
});