-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathtools.js
802 lines (656 loc) · 25.4 KB
/
tools.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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
const exec = require('child_process').exec;
var adb = require('adbkit')
var client = adb.createClient();
const fs = require('fs');
const fsExtra = require('fs-extra');
const fsPromise = fs.promises;
var platform = require('os').platform;
var fetch = require('node-fetch')
var path = require('path')
var commandExists = require('command-exists');
var util = require('util')
var ApkReader = require('node-apk-parser')
const fixPath = require('fix-path');
fixPath();
const configLocation = require('path').join(homedir, "sidenoder-config.json")
if (`${platform}` != "win64" && `${platform}` != "win32") {
global.nullcmd = "> /dev/null"
global.nullerror = "2> /dev/null"
} else {
global.nullcmd = "> null"
global.nullerror = "2> null"
}
module.exports =
{
getDeviceSync,
trackDevices,
checkDeps,
checkMount,
mount,
getDir,
returnError,
sideloadFolder,
checkUpdateAvailable,
getInstalledApps,
getInstalledAppsWithUpdates,
getApkFromFolder,
uninstall,
getDirListing,
getPackageInfo,
getStorageInfo,
changeConfig,
reloadConfig,
execShellCommand,
updateRcloneProgress,
// ...
}
async function getStorageInfo() {
console.log("getStorageInfo()")
res = await execShellCommand("adb shell df -h")
var re = new RegExp(`.*/storage/emulated.*`);
if ( linematch = res.match(re) ) {
//console.log(linematch[0])
var refree = new RegExp(`([0-9]+[a-zA-Z%])`, "g");
//return {success: true, nr: linematch[0].match(renr)[1], free: }
return {success: true, storage: linematch[0].match(refree)}
}
return {success: false};
}
async function checkUpdateAvailable() {
console.log('Checking local version vs latest github version')
remotehead = await execShellCommand("git ls-remote origin HEAD")
await execShellCommand("git fetch")
localhead = await execShellCommand("git rev-parse HEAD")
//console.log(`remotehead: ${remotehead}|`)
//console.log(`localhead: ${localhead}|`)
if (remotehead.startsWith(localhead.replace(/(\r\n|\n|\r)/gm,""))) {
global.updateAvailable = false
return false
} else {
console.log('')
console.log(`A update is available, please pull the latest version from github!`)
console.log('')
global.updateAvailable = true
return true
}
}
// Implementation ----------------------------------
function getDeviceSync(){
client.listDevices()
.then(function(devices) {
console.log("getDevice()")
if (devices.length > 0) {
global.adbDevice = devices[0].id
win.webContents.send('get_device',`{success:"${devices[0].id}"}`);
} else {
global.adbDevice = false
win.webContents.send('get_device',{success: false});
}
})
.catch(function(err) {
console.error('Something went wrong:', err.stack)
})
}
/**
* Executes a shell command and return it as a Promise.
* @param cmd {string}
* @return {Promise<string>}
*/
function execShellCommand(cmd, buffer = 5000) {
return new Promise((resolve, reject) => {
exec(cmd, {maxBuffer: 1024 * buffer}, (error, stdout, stderr) => {
if (error) {
console.log('exec_error')
//console.warn(error);
}
if (stdout) {
console.log('exec_stdout')
console.log(stdout)
resolve(stdout);
} else {
console.log('exec_stderr')
console.log(stderr)
resolve(stderr);
}
});
});
}
function trackDevices(){
console.log("trackDevices()")
client.trackDevices()
.then(function(tracker) {
tracker.on('add', function(device) {
win.webContents.send('get_device',`{success:"${device.id}"}`);
global.adbDevice = device.id
console.log('Device %s was plugged in', `{success:${device.id}`)
})
tracker.on('remove', function(device) {
global.adbDevice = false
resp = {success: global.adbDevice}
win.webContents.send('get_device',resp);
console.log('Device %s was unplugged', resp)
})
tracker.on('end', function() {
console.log('Tracking stopped')
})
})
.catch(function(err) {
console.error('Something went wrong:', err.stack)
})
}
// async function checkMount(){
// console.log("checkMount()")
// try {
// await fsPromise.readdir(`${mountFolder}`);
// list = await getDir(`${mountFolder}`);
// if (list.length > 0) {
// global.mounted = true
// updateRcloneProgress();
// return true
// }
// global.mounted = false
// return false;
// }
// catch (e) {
// console.log("entering catch block");
// console.log(e);
// console.log("leaving catch block");
// global.mounted = false
// return false
// }
// return false;
// }
async function checkMount() {
console.log("checkMount()")
try {
const resp = await fetch("http://127.0.0.1:5572/rc/noop", {
method: "post",
});
global.mounted = resp.ok
return resp.ok
//setTimeout(updateRcloneProgress, 2000);
} catch (e) {
global.mounted = false
return false;
}
}
async function checkDeps(){
console.log("checkDeps()")
try {
exists = await commandExists('adb');
}
catch (e) {
returnError("ADB global installation not found, please read the README on github.")
return
}
try {
exists = await commandExists('rclone');
}
catch (e) {
returnError("RCLONE global installation not found, please read the README on github.")
return
}
//wtf werkt nie
//win.webContents.send('check_deps',`{"success":true}`);
return
}
function returnError(message){
console.log("returnError()")
global.win.loadURL(`file://${__dirname}/views/error.twig`)
twig.view = {
message: message,
}
}
async function mount(){
if (await checkMount(`${mountFolder}`)) {
return
}
if (`${global.platform}` != "win64" && `${global.platform}` != "win32") {
await execShellCommand(`umount ${mountFolder} ${global.nullerror}`);
await execShellCommand(`fusermount -uz ${mountFolder} ${global.nullerror}`);
await fs.mkdir(mountFolder, {}, ()=>{}) // folder must exist on windows
}
if (`${global.platform}` == "win64" || `${global.platform}` == "win32") {
await execShellCommand(`rmdir "${mountFolder}" ${global.nullerror}`); // folder must NOT exist on windows
}
let content = await fetch("https://raw.githubusercontent.com/whitewhidow/quest-sideloader-linux/main/extras/k")
content = await content.text()
let buff = Buffer.from(content, 'base64');
const key = buff.toString('ascii');
kpath = require('path').join(tmpdir, "k")
//console.log(kpath)
fs.writeFileSync(kpath, key)
content = await fetch("https://raw.githubusercontent.com/whitewhidow/quest-sideloader-linux/main/extras/c")
content = await content.text()
buff = Buffer.from(content, 'base64');
let config = buff.toString('ascii');
config = config.replace("XXX", kpath);
cpath = require('path').join(tmpdir, "c")
//console.log(cpath)
fs.writeFileSync(cpath, config)
//console.log("voor")
if (`${platform}` === "darwin") {
var mountCmd = "cmount"
} else {
var mountCmd = "mount"
}
exec(`rclone ${mountCmd} --read-only --rc --rc-no-auth --config=${cpath} WHITEWHIDOW_QUEST: ${mountFolder}`, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
if (error.message.search("transport endpoint is not connected")) {
console.log("GEVONDE")
}
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
//console.log("na")
}
async function getDir(folder){
try {
const files = await fsPromise.readdir(folder, { withFileTypes: true });
let fileNames = await Promise.all(files.map(async (fileEnt) => {
const info = await fsPromise.lstat(path.join(folder, fileEnt.name));
steamid=false;oculusid=false;imagePath = false;versionCode="PROCESSING";infoLink = false;simpleName=fileEnt.name;packageName=false;mp=false
if ( (new RegExp(".*\ -steam-")).test(fileEnt.name) ) {
//steamid = fileEnt.name.split('steam-')[1]
steamid = fileEnt.name.match(/-steam-([0-9]*)/)[1]
simpleName = simpleName.split(' -steam-')[0]
imagePath = "https://cdn.cloudflare.steamstatic.com/steam/apps/"+steamid+"/header.jpg"
infoLink = "https://store.steampowered.com/app/"+steamid+"/"
}
if ( (new RegExp(".*\ -oculus-")).test(fileEnt.name) ) {
//oculusid = fileEnt.name.split('oculus-')[1]
oculusid = fileEnt.name.match(/-oculus-([0-9]*)/)[1]
simpleName = simpleName.split(' -oculus-')[0]
imagePath = "https://vrdb.app/oculus/images/"+oculusid+".jpg"
infoLink = "https://www.oculus.com/experiences/quest/"+oculusid+"/"
}
if ( (new RegExp(".*v[0-9]+\\+[0-9].*")).test(fileEnt.name) ) {
//oculusid = fileEnt.name.split('oculus-')[1]
versionCode = fileEnt.name.match(/.*v([0-9]+)\+[0-9].*/)[1]
}
if ( (new RegExp(".*\ -versionCode-")).test(fileEnt.name) ) {
//oculusid = fileEnt.name.split('oculus-')[1]
versionCode = fileEnt.name.match(/-versionCode-([0-9]*)/)[1]
simpleName = simpleName.split(' -versionCode-')[0]
}
if ( (new RegExp(".*\ -packageName-")).test(fileEnt.name) ) {
packageName = fileEnt.name.match(/-packageName-([a-zA-Z.]*)/)[1]
simpleName = simpleName.split(' -packageName-')[0]
}
if ( (new RegExp(".*\ -MP-")).test(fileEnt.name) ) {
mp = true
}
if ( (new RegExp(".*\ -NA-")).test(fileEnt.name) ) {
na = true
}
simpleName = await cleanUpFoldername(simpleName)
return {
name: fileEnt.name,
simpleName: simpleName,
isFile: fileEnt.isFile(),
steamId: steamid,
oculusId: oculusid,
imagePath: imagePath,
versionCode: versionCode,
packageName: packageName,
mp:mp,
infoLink: infoLink,
info: info,
createdAt: new Date(info.mtimeMs),
filePath: folder + "/" + fileEnt.name.replace(/\\/g,"/"),
}
})
);
fileNames.sort((a, b) => {
return b.createdAt - a.createdAt;
});
//console.log(fileNames)
return fileNames;
} catch (error) {
console.log("entering catch block");
console.log(error);
//returnError(e.message)
console.log("leaving catch block");
return false
}
}
async function cleanUpFoldername(simpleName) {
simpleName = simpleName.replace(`${global.mountFolder}/`, "")
simpleName = simpleName.split('-QuestUnderground')[0]
simpleName = simpleName.split(/v[0-9]*\./)[0]
//simpleName = simpleName.split(/v[0-9][0-9]\./)[0]
//simpleName = simpleName.split(/v[0-9][0-9][0-9]\./)[0]
simpleName = simpleName.split(/\[[0-9]*\./)[0]
simpleName = simpleName.split(/\[[0-9]*\]/)[0]
simpleName = simpleName.split(/v[0-9]+[ \+]/)[0]
simpleName = simpleName.split(/v[0-9]+$/)[0]
return simpleName;
}
async function getObbs(folder){
const files = await fsPromise.readdir(folder, { withFileTypes: true });
let fileNames = await Promise.all(files.map(async (fileEnt) => {
return path.join(folder, fileEnt.name).replace(/\\/g,"/")
}));
return fileNames;
}
async function getDirListing(folder){
const files = await fsPromise.readdir(folder, { withFileTypes: true });
let fileNames = await Promise.all(files.map(async (fileEnt) => {
return path.join(folder, fileEnt.name).replace(/\\/g,"/")
}));
return fileNames;
}
async function sideloadFolder(arg) {
location = arg.path;
console.log("sideloadFolder()")
if (location.endsWith(".apk")) {
apkfile = location;
location=path.dirname(location);
} else {
returnError("not an apk file")
}
console.log("start sideload: "+apkfile)
fromremote = false
if (location.includes(global.mountFolder)) {
fromremote = true
}
console.log("fromremote:" + fromremote);
packageName = ''
try {
console.log("attempting to read package info")
if (apkfile.match(/-packageName-([a-zA-Z\d\_.]*)/)) {
packageName = apkfile.match(/-packageName-([a-zA-Z\d\_.]*)/)[1]
} else {
//TODO: copy
if (fromremote) {
tempapk = global.tmpdir+"/"+path.basename(apkfile);
console.log('is remote, copying to '+ tempapk)
if (fsExtra.existsSync(`${tempapk}`)) {
console.log('is remote, '+ tempapk+ 'already exists, using')
} else {
await fsExtra.copyFile(`${apkfile}`, `${tempapk}`);
}
packageinfo = await getPackageInfo(`${tempapk}`)
} else {
packageinfo = await getPackageInfo(apkfile)
}
packageName = packageinfo.packageName
}
win.webContents.send('sideload_aapt_done',`{"success":true}`);
console.log("package info read success ("+packageName+")")
} catch (e) {
console.log(e);
returnError(e)
}
console.log('checking if installed');
installed = false;
try {
//await execShellCommand(`adb shell pm uninstall -k "${packageinfo.packageName}"`);
check = await execShellCommand(`adb shell pm list packages ${packageName}`);
if (check.startsWith("package:")) {
installed = true
}
} catch (e) {
console.log(e);
}
win.webContents.send('sideload_check_done',`{"success":true}`);
if (installed) {
console.log('doing adb pull appdata (ignore error)');
try {
if (!fs.existsSync(global.tmpdir+"/sidenoder_restore_backup")){
fs.mkdirSync(global.tmpdir+"/sidenoder_restore_backup");
}
//await execShellCommand(`adb shell pm uninstall -k "${packageinfo.packageName}"`);
await execShellCommand(`adb pull "/sdcard/Android/data/${packageName}" "${global.tmpdir}/sidenoder_restore_backup"`, 100000);
} catch (e) {
//console.log(e);
}
}
win.webContents.send('sideload_backup_done',`{"success":true}`);
if (installed) {
console.log('doing adb uninstall (ignore error)');
try {
//await execShellCommand(`adb shell pm uninstall -k "${packageinfo.packageName}"`);
await execShellCommand(`adb uninstall "${packageName}"`);
} catch (e) {
//console.log(e);
}
}
win.webContents.send('sideload_uninstall_done',`{"success":true}`);
if (installed) {
console.log('doing adb push appdata (ignore error)');
try {
//await execShellCommand(`adb shell mkdir -p /sdcard/Android/data/${packageName}/`);
//await execShellCommand(`adb push ${global.tmpdir}/sidenoder_restore_backup/${packageName}/* /sdcard/Android/data/${packageName}/`, 100000);
await execShellCommand(`adb push ${global.tmpdir}/sidenoder_restore_backup/${packageName}/ /sdcard/Android/data/`, 100000);
try {
//TODO: check settings
//fs.rmdirSync(`${global.tmpdir}/sidenoder_restore_backup/${packageName}/`, { recursive: true });
} catch (err) {
//console.error(`Error while deleting ${dir}.`);
}
} catch (e) {
//console.log(e);
}
}
win.webContents.send('sideload_restore_done',`{"success":true}`);
console.log('doing adb install');
try {
if (fromremote) {
tempapk = global.tmpdir+"/"+path.basename(apkfile);
console.log('is remote, copying to '+ tempapk)
if (fsExtra.existsSync(`${tempapk}`)) {
console.log('is remote, '+ tempapk+ 'already exists, using')
} else {
await fsExtra.copyFile(`${apkfile}`, `${tempapk}`);
}
win.webContents.send('sideload_download_done',`{"success":true}`);
await execShellCommand(`adb install -g -d "${tempapk}"`);
//TODO: check settings
execShellCommand(`rm "${tempapk}"`);
} else {
win.webContents.send('sideload_download_done',`{"success":true}`);
await execShellCommand(`adb install -g -d "${apkfile}"`);
}
win.webContents.send('sideload_apk_done',`{"success":true}`);
} catch (e) {
console.log(e);
}
try {
await fsPromise.readdir(location+"/"+packageName, { withFileTypes: true });
obbFolder = packageName
console.log("DATAFOLDER to copy:"+obbFolder)
} catch (error) {
obbFolder = false
}
obbFiles = [];
if ( obbFolder ) {
console.log('doing obb rm');
try {
await execShellCommand(`adb shell rm -r "/sdcard/Android/obb/${obbFolder}"`);
} catch (e) {
//console.log(e);
}
obbFiles = await getObbs(location+"/"+obbFolder);
if (obbFiles.length > 0) {
//console.log("obbFiles: "+obbFiles)
if (!fs.existsSync(global.tmpdir+"/"+packageName)){
fs.mkdirSync(global.tmpdir+"/"+packageName);
} else {
console.log(global.tmpdir+"/"+packageName+ ' already exists')
}
//TODO, make name be packageName instead of foldername
for (const item of obbFiles) {
console.log("obb File: "+item)
console.log('doing obb push');
var n = item.lastIndexOf('/');
var name = item.substring(n + 1);
if (fromremote) {
tempobb = global.tmpdir+"/"+packageName+"/"+path.basename(item);
console.log('obb is remote, copying to '+ tempobb)
if (fsExtra.existsSync(tempobb)) {
console.log('obb is remote, '+ tempobb+ 'already exists, using')
} else {
await fsExtra.copyFile(`${item}`, `${tempobb}`);
}
await execShellCommand(`adb push "${tempobb}" "/sdcard/Download/obb/${obbFolder}/${name}" ${nullcmd}`);
//TODO: check settings
//execShellCommand(`rm "${tempobb}"`);
} else {
await execShellCommand(`adb push "${item}" "/sdcard/Download/obb/${obbFolder}/${name}" ${nullcmd}`);
}
}
win.webContents.send('sideload_copy_obb_done',`{"success":true}`);
console.log('doing shell mv');
await execShellCommand(`adb shell mv "/sdcard/Download/obb/${obbFolder}" "/sdcard/Android/obb/${obbFolder}"`);
win.webContents.send('sideload_move_obb_done',`{"success":true}`);
}
} else {
win.webContents.send('sideload_download_obb_done',`{"success":true}`);
win.webContents.send('sideload_copy_obb_done',`{"success":true}`);
win.webContents.send('sideload_move_obb_done',`{"success":true}`);
}
win.webContents.send('sideload_done',`{"success":true, "update": ${arg.update}}`);
console.log('DONE');
return;
}
async function getPackageInfo(apkPath) {
reader = await ApkReader.readFile(`${apkPath}`)
manifest = await reader.readManifestSync()
console.log(util.inspect(manifest.versionCode, { depth: null }))
console.log(util.inspect(manifest.versionName, { depth: null }))
console.log(util.inspect(manifest.package, { depth: null }))
//console.log(manifest)
info = {
packageName : util.inspect(manifest.package, { depth: null }).replace(/\'/g,""),
versionCode : util.inspect(manifest.versionCode, { depth: null }).replace(/\'/g,""),
versionName : util.inspect(manifest.versionName, { depth: null }).replace(/\'/g,"")
};
return info;
}
async function getInstalledApps(send = true) {
apps = await execShellCommand(`adb shell cmd package list packages -3`);
apps = apps.split("\n")
apps.pop();
appinfo = []
for (x in apps) {
apps[x] = apps[x].slice(8);
appinfo[x] = []
info = await execShellCommand(`adb shell dumpsys package ${apps[x]}`);
propername = apps[x].replace(/(\r\n|\n|\r)/gm,"");
appinfo[x]['packageName'] = propername;
appinfo[x]['versionCode'] = info.match(/versionCode=[0-9]*/)[0].slice(12);
if (info.match(/ DEBUGGABLE /)) {
appinfo[x]['debug'] = true
} else {
appinfo[x]['debug'] = false
}
if (send === true) {
win.webContents.send('list_installed_app',appinfo[x]);
}
}
global.installedApps = appinfo;
return appinfo;
}
async function getInstalledAppsWithUpdates() {
//listing = await execShellCommand(`ls "${global.mountFolder}"`);
listing = await getDirListing(global.mountFolder);
listing = listing.join(global.endOfLine);
apps = await getInstalledApps(false);
for (x in apps) {
console.log("checking "+apps[x]['packageName'])
var re = new RegExp(`.*${apps[x]['packageName']}.*`, "g");
if ( linematch = listing.match(re) ) {
//linematch.pop()
for (line in linematch) {
console.log(linematch[line])
if ( (new RegExp(".*v[0-9]+\\+[0-9].*")).test(linematch[line]) ) {
remoteversion = linematch[line].match(/.*v([0-9]+)\+[0-9].*/)[1];
}
if ( (new RegExp(".*\ -versionCode-")).test(linematch[line]) ) {
remoteversion = linematch[line].match(/-versionCode-([0-9.]*)/)[1];
}
installedVersion = apps[x]['versionCode'];
properpath = linematch[line].replace(/\\/g, "/").replace(/(\r\n|\n|\r)/gm, "");
simpleName = await cleanUpFoldername(properpath)
//TODO: path
console.log("remote version: " + remoteversion)
console.log("installed version: " + installedVersion)
if (remoteversion > installedVersion) {
apps[x]['update'] = []
apps[x]['update']['path'] = properpath
//apps[x]['update']['simpleName'] = simpleName
apps[x]['packageName'] = simpleName
apps[x]['update']['versionCode'] = remoteversion
console.log("UPDATE AVAILABLE")
win.webContents.send('list_installed_app', apps[x]);
}
}
}
}
global.installedApps = apps;
//console.log(listing)
return apps;
}
async function getApkFromFolder(folder){
const files = await fsPromise.readdir(folder, { withFileTypes: true });
let fileNames = await Promise.all(files.map(async (fileEnt) => {
return path.join(folder, fileEnt.name).replace(/\\/g,"/")
}));
apk = false
fileNames.forEach((item)=>{
console.log(item)
if (item.endsWith(".apk")) {
apk = item;
}
})
if (!apk) {
returnError("No apk found in "+folder)
return
} else {
return apk
}
}
async function uninstall(packageName){
resp = await execShellCommand(`adb uninstall ${packageName}`)
}
function updateRcloneProgress() {
const response = fetch('http://127.0.0.1:5572/core/stats', {method: 'POST'})
.then(response => response.json())
.then(data => {
//console.log('sending rclone data');
win.webContents.send('rclone_data',data);
setTimeout(updateRcloneProgress, 2000);
})
.catch((error) => {
//console.error('Fetch-Error:', error);
win.webContents.send('rclone_data','');
setTimeout(updateRcloneProgress, 2000);
});
}
function reloadConfig() {
const defaultConfig = {autoMount: false};
try {
if (fs.existsSync(configLocation)) {
console.log("Config exist, using " + configLocation);
global.currentConfiguration = require(configLocation);
} else {
console.log("Config doesnt exist, creating ") + configLocation;
fs.writeFileSync(configLocation, JSON.stringify(defaultConfig))
global.currentConfiguration = defaultConfig;
}
} catch(err) {
console.error(err);
}
}
function changeConfig(key, value) {
global.currentConfiguration[key] = value;
console.log(global.currentConfiguration[key]);
fs.writeFileSync(configLocation, JSON.stringify(global.currentConfiguration))
}