-
Notifications
You must be signed in to change notification settings - Fork 12
/
core.js
1080 lines (1040 loc) · 33.9 KB
/
core.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
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Pluto
(async () => {
const semver = (await import("./assets/semver.min.js")).default;
try {
const coreDetails = {
version: "v1.6.2",
codename: "Elysium",
};
// for compatibility
coreDetails.versionString = coreDetails.version;
coreDetails.minSupported = `<=${coreDetails.version}`;
const knownLibraries = [];
const GlobalLib = {
getString,
semver,
escapeHtml: escapeHtml,
html: class Html {
/** The HTML element referenced in this instance. Change using `.swapRef()`, or remove using `.cleanup()`. */
elm;
/**
* Create a new instance of the Html class.
* @param elm The HTML element to be created or classified from.
*/
constructor(elm) {
if (elm instanceof HTMLElement) {
this.elm = elm;
} else {
this.elm = document.createElement(elm || "div");
}
}
/**
* Sets the text of the current element.
* @param val The text to set to.
* @returns Html
*/
text(val) {
this.elm.innerText = val;
return this;
}
/**
* Sets the text of the current element.
* @param val The text to set to.
* @returns Html
*/
html(val) {
this.elm.innerHTML = val;
return this;
}
/**
* Safely remove the element. Can be used in combination with a `.swapRef()` to achieve a "delete & swap" result.
* @returns Html
*/
cleanup() {
this.elm.remove();
return this;
}
/**
* querySelector something.
* @param selector The query selector.
* @returns The HTML element (not as Html)
*/
query(selector) {
return this.elm.querySelector(selector);
}
/**
* An easier querySelector method.
* @param query The string to query
* @returns a new Html
*/
qs(query) {
if (this.elm.querySelector(query)) {
return Html.from(this.elm.querySelector(query));
} else {
return null;
}
}
/**
* An easier querySelectorAll method.
* @param query The string to query
* @returns a new Html
*/
qsa(query) {
if (this.elm.querySelector(query)) {
return Array.from(this.elm.querySelectorAll(query)).map((e) =>
Html.from(e)
);
} else {
return null;
}
}
/**
* Sets the ID of the element.
* @param val The ID to set.
* @returns Html
*/
id(val) {
this.elm.id = val;
return this;
}
/**
* Toggle on/off a class.
* @param val The class to toggle.
* @returns Html
*/
class(...val) {
for (let i = 0; i < val.length; i++) {
this.elm.classList.toggle(val[i]);
}
return this;
}
/**
* Toggles ON a class.
* @param val The class to enable.
* @returns Html
*/
classOn(...val) {
for (let i = 0; i < val.length; i++) {
this.elm.classList.add(val[i]);
}
return this;
}
/**
* Toggles OFF a class.
* @param val The class to disable.
* @returns Html
*/
classOff(...val) {
for (let i = 0; i < val.length; i++) {
this.elm.classList.remove(val[i]);
}
return this;
}
/**
* Apply CSS styles (dashed method.) Keys use CSS syntax, e.g. `background-color`.
* @param obj The styles to apply (as an object of `key: value;`.)
* @returns Html
*/
style(obj) {
for (const key of Object.keys(obj)) {
this.elm.style.setProperty(key, obj[key]);
}
return this;
}
/**
* Apply CSS styles (JS method.) Keys use JS syntax, e.g. `backgroundColor`.
* @param obj The styles to apply (as an object of `key: value;`)
* @returns Html
*/
styleJs(obj) {
for (const key of Object.keys(obj)) {
//@ts-ignore No other workaround I could find.
this.elm.style[key] = obj[key];
}
return this;
}
/**
* Apply an event listener.
* @param ev The event listener type to add.
* @param cb The event listener callback to add.
* @returns Html
*/
on(ev, cb) {
this.elm.addEventListener(ev, cb);
return this;
}
/**
* Remove an event listener.
* @param ev The event listener type to remove.
* @param cb The event listener callback to remove.
* @returns Html
*/
un(ev, cb) {
this.elm.removeEventListener(ev, cb);
return this;
}
/**
* Append this element to another element. Uses `appendChild()` on the parent.
* @param parent Element to append to. HTMLElement, Html, and string (as querySelector) are supported.
* @returns Html
*/
appendTo(parent) {
if (parent instanceof HTMLElement) {
parent.appendChild(this.elm);
} else if (parent instanceof Html) {
parent.elm.appendChild(this.elm);
} else if (typeof parent === "string") {
document.querySelector(parent)?.appendChild(this.elm);
}
return this;
}
/**
* Prepend this element to another element. Uses `prepend()` on the parent.
* @param parent Element to append to. HTMLElement, Html, and string (as querySelector) are supported.
* @returns Html
*/
prependTo(parent) {
if (parent instanceof HTMLElement) {
parent.prepend(this.elm);
} else if (parent instanceof Html) {
parent.elm.prepend(this.elm);
} else if (typeof parent === "string") {
document.querySelector(parent)?.prepend(this.elm);
}
return this;
}
/**
* Append an element. Typically used as a `.append(new Html(...))` call.
* @param elem The element to append.
* @returns Html
*/
append(elem) {
if (elem instanceof HTMLElement) {
this.elm.appendChild(elem);
} else if (elem instanceof Html) {
this.elm.appendChild(elem.elm);
} else if (typeof elem === "string") {
const newElem = document.createElement(elem);
this.elm.appendChild(newElem);
return new Html(newElem.tagName);
}
return this;
}
/**
* Prepend an element. Typically used as a `.prepend(new Html(...))` call.
* @param elem The element to prepend.
* @returns Html
*/
prepend(elem) {
if (elem instanceof HTMLElement) {
this.elm.prepend(elem);
} else if (elem instanceof Html) {
this.elm.prepend(elem.elm);
} else if (typeof elem === "string") {
const newElem = document.createElement(elem);
this.elm.prepend(newElem);
return new Html(newElem.tagName);
}
return this;
}
/**
* Append multiple elements. Typically used as a `.appendMany(new Html(...), new Html(...)` call.
* @param elements The elements to append.
* @returns Html
*/
appendMany(...elements) {
for (const elem of elements) {
this.append(elem);
}
return this;
}
/**
* Prepend multiple elements. Typically used as a `.prependMany(new Html(...), new Html(...)` call.
* @param elements The elements to prepend.
* @returns Html
*/
prependMany(...elements) {
for (const elem of elements) {
this.prepend(elem);
}
return this;
}
/**
* Clear the innerHTML of the element.
* @returns Html
*/
clear() {
this.elm.innerHTML = "";
return this;
}
/**
* Set attributes (object method.)
* @param obj The attributes to set (as an object of `key: value;`)
* @returns Html
*/
attr(obj) {
for (let key in obj) {
if (obj[key] !== null && obj[key] !== undefined) {
this.elm.setAttribute(key, obj[key]);
} else {
this.elm.removeAttribute(key);
}
}
return this;
}
/**
* Set the text value of the element. Only works if element is `input` or `textarea`.
* @param str The value to set.
* @returns Html
*/
val(str) {
var x = this.elm;
x.value = str;
return this;
}
/**
* Retrieve text content from the element. (as innerText, not trimmed)
* @returns string
*/
getText() {
return this.elm.innerText;
}
/**
* Retrieve HTML content from the element.
* @returns string
*/
getHtml() {
return this.elm.innerHTML;
}
/**
* Retrieve the value of the element. Only applicable if it is an `input` or `textarea`.
* @returns string
*/
getValue() {
return this.elm.value;
}
/**
* Swap the local `elm` with a new HTMLElement.
* @param elm The element to swap with.
* @returns Html
*/
swapRef(elm) {
this.elm = elm;
return this;
}
/**
* An alternative method to create an Html instance.
* @param elm Element to create from.
* @returns Html
*/
static from(elm) {
if (typeof elm === "string") {
const element = Html.qs(elm);
if (element === null) return null;
else return element;
} else {
return new Html(elm);
}
}
/**
* An easier querySelector method.
* @param query The string to query
* @returns a new Html
*/
static qs(query) {
if (document.querySelector(query)) {
return Html.from(document.querySelector(query));
} else {
return null;
}
}
/**
* An easier querySelectorAll method.
* @param query The string to query
* @returns a new Html
*/
static qsa(query) {
if (document.querySelector(query)) {
return Array.from(document.querySelectorAll(query)).map((e) =>
Html.from(e)
);
} else {
return null;
}
}
},
randomString: () => {
if (crypto && crypto.randomUUID) return crypto.randomUUID();
else {
var d = new Date().getTime();
var d2 =
(typeof performance !== "undefined" &&
performance.now &&
performance.now() * 1000) ||
0;
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
/[xy]/g,
function (c) {
var r = Math.random() * 16;
if (d > 0) {
r = (d + r) % 16 | 0;
d = Math.floor(d / 16);
} else {
r = (d2 + r) % 16 | 0;
d2 = Math.floor(d2 / 16);
}
return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
}
);
}
},
loadLibrary: async function (lib) {
if (lib.includes(":")) return false;
knownLibraries.push(lib);
return await Core.startPkg("lib:" + lib);
},
loadComponent: async (cmp) => {
if (cmp.includes(":")) return false;
knownLibraries.push(cmp);
return await Core.startPkg("components:" + cmp);
},
};
GlobalLib.icons = (await import("./assets/icons.js")).default;
const strings = (await import("./assets/strings.js")).default;
function replaceString(string, replacements) {
let str = string;
for (let rpl in replacements) {
str = str.replace(`{${rpl}}`, replacements[rpl]);
}
return str;
}
function getString(str, replacements = null, source) {
function getStr() {
if (source && source[language] && source[language][str])
return source[language][str];
else if (source && source["en_US"][str]) return source["en_US"][str];
else if (strings[language] && strings[language][str])
return strings[language][str];
else return strings["en_US"][str];
}
const newStr = escapeHtml(getStr());
if (replacements !== null) {
return replaceString(newStr, replacements);
} else {
if (newStr === undefined) return str;
return newStr;
}
}
function escapeHtml(str) {
if (str !== undefined)
return str
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">");
}
// Similar name to procLib but is not actually ProcLib
const processLib = class ProcessAvailableLibrary {
constructor(url, pid, token, strs) {
var Url = url;
var Pid = pid;
var Token = token;
this.escapeHtml = escapeHtml;
this.getString = function (str, replacements = null) {
broadcastEventToProcs({
type: "procEvent",
data: {
type: "getString",
pid: Pid,
url: Url,
data: arguments,
},
});
return getString(str, replacements, strs);
};
this.html = GlobalLib.html;
this.randomString = GlobalLib.randomString;
this.icons = GlobalLib.icons;
this.systemInfo = coreDetails;
this.semver = GlobalLib.semver;
this.updateProcTitle = function (newTitle) {
broadcastEventToProcs({
type: "procEvent",
data: {
type: "updateProcTitle",
pid: Pid,
url: Url,
data: arguments,
},
});
if (Core.processList[Pid].proc !== null) {
Core.processList[Pid].proc.name = newTitle;
}
};
this.updateProcDesc = function (newDescription) {
broadcastEventToProcs({
type: "procEvent",
data: {
type: "updateProcDesc",
pid: Pid,
url: Url,
data: arguments,
},
});
if (Core.processList[Pid].proc !== null) {
Core.processList[Pid].proc.description = newDescription;
}
};
this.langs = supportedLangs;
this.launch = async (app, parent = "body") => {
broadcastEventToProcs({
type: "procEvent",
data: {
type: "launch",
pid: Pid,
url: Url,
data: arguments,
},
});
let appName = "";
if (Core.processList[Pid].proc !== null) {
appName = Core.processList[Pid].proc.name;
} else {
appName = "???";
}
if (
(await Modal.prompt(
getString("notice"),
getString("core_appLaunch_notification", {
suspectedApp: appName,
targetApp: app.split(":").pop(),
}),
parent
)) === true
) {
return await Core.startPkg(app);
} else {
return false;
}
};
this.getProcessList = () => {
broadcastEventToProcs({
type: "procEvent",
data: {
type: "getProcessList",
pid: Pid,
url: Url,
data: arguments,
},
});
return Core.processList
.filter((m) => m !== null)
.map((m) => {
return {
name: m.name,
pid: m.pid,
};
});
};
this.loadLibrary = async (lib) => {
if (lib.includes(":")) return false;
broadcastEventToProcs({
type: "procEvent",
data: {
type: "loadLibrary",
pid: Pid,
url: Url,
data: [lib],
},
});
return await Core.startPkg("lib:" + lib);
};
this.loadComponent = async (cmp) => {
if (cmp.includes(":")) return false;
broadcastEventToProcs({
type: "procEvent",
data: {
type: "loadComponent",
pid: Pid,
url: Url,
data: [cmp],
},
});
return await Core.startPkg("components:" + cmp);
};
this.cleanup = function (pid, token) {
broadcastEventToProcs({
type: "procEvent",
data: {
type: "cleanup",
pid: Pid,
url: Url,
data: [pid],
},
});
// Token is required for the pid to verify that it is the one willing to clean up
console.log("Checking..");
const proc = Core.processList
.filter((p) => p !== null)
.findIndex((p) => p.pid === pid && p.token === token);
if (proc !== -1) {
console.log(Core.processList[proc]);
ProcLib.cleanupProcess(pid);
return true;
} else {
return false;
}
};
this.setOnEnd = function (onEndCallback) {
broadcastEventToProcs({
type: "procEvent",
data: {
type: "setOnEnd",
pid: Pid,
url: Url,
data: [onEndCallback],
},
});
this.onEndCallback = onEndCallback;
this.onEnd = () => {
console.log("Example process ended, attempting clean up...");
const result = this.cleanup(Pid, Token);
if (result === true) {
this.onEndCallback && this.onEndCallback();
console.log("Cleanup Success! Token:", Token);
} else {
console.log("Cleanup Failure. Token:", Token);
}
};
};
this.setupReturns = function (onMessage, trayInfo = null) {
broadcastEventToProcs({
type: "procEvent",
data: {
type: "setOnEnd",
pid: Pid,
url: Url,
data: [onMessage, trayInfo],
},
});
// the idea is a standardized .proc on processes
return {
end: this.onEnd,
trayInfo,
send: async (m) => {
if (
m &&
m.type &&
m.type === "refresh" &&
m.data &&
typeof m.data === "function"
) {
this.getString = m.data;
}
return await onMessage(m);
},
};
};
}
};
const ProcLib = {
findEmptyPID: function () {
let r = Core.processList.findIndex((p) => p === null);
return r !== -1 ? r : Core.processList.length;
},
cleanupProcess: function (pid) {
let proc = Core.processList
.filter((p) => p !== null)
.find((p) => p.pid === pid);
console.group("Process cleanup (" + pid, proc.name + ")");
console.debug(
`%cProcess ${proc.name} (${proc.pid}) was ended.`,
"color:green;font-weight:bold"
);
let x = procsListeningToEvents.findIndex((p) => p === pid);
if (x !== undefined || x !== null) {
// console.log("removing", x, "from broadcast list");
procsListeningToEvents[x] = null;
}
broadcastEventToProcs({
type: "coreEvent",
data: {
type: "pkgEnd",
data: Core.processList[pid],
},
});
Core.processList[pid] = null;
console.groupEnd();
},
};
let Modal, Toast;
const corePrivileges = {
startPkg: { description: "core_appAccessControl_privilege_startPkg" },
processList: {
description: "core_appAccessControl_privilege_processList",
},
knownPackageList: {
description: "core_appAccessControl_privilege_knownPackageList",
},
services: { description: "core_appAccessControl_privilege_services" },
setLanguage: {
description: "core_appAccessControl_privilege_setLanguage",
},
host: {
description:
"core_appAccessControl_privilege_desktopOnlyHostPermission",
},
full: {
description: "core_appAccessControl_privilege_full",
},
};
const permittedApps = ["lib:ThemeLib"];
const procsListeningToEvents = [];
function broadcastEventToProcs(eventData) {
// console.log("procsListeningToEvents", procsListeningToEvents);
procsListeningToEvents
.filter((m) => m !== null)
.forEach((e) => {
Core.processList[e] !== null &&
Core.processList[e].proc !== null &&
Core.processList[e].proc.send(eventData);
});
}
const supportedLangs = [
"en_US",
"en_GB",
"de_DE",
"es_ES",
"pt_BR",
"fil_PH",
];
let language = "en_US";
const Core = {
version: coreDetails.version,
codename: coreDetails.codename,
processList: [],
knownPackageList: [],
setLanguage(lang) {
console.log("setting language to", lang);
if (supportedLangs.includes(lang)) language = lang;
// kindly ask all processes to restart
Core.processList
.filter((n) => n !== null)
.forEach((p) => {
p.proc &&
p.proc.send &&
p.proc.send({
type: "refresh",
data: function (
str,
replacements = null,
source = p.proc.strings
) {
return getString(str, replacements, source);
},
});
});
},
startPkg: async function (url, isUrl = true, force = false) {
try {
// This should be safe as startPkg can only be called by admin packages and trusted libraries
let pkg;
if (isUrl === false) {
// treat this package as a raw uri
pkg = await import(url);
url = "none:<Imported as URI>";
} else {
pkg = await import("./pkgs/" + url.replace(":", "/") + ".js");
}
if (!pkg.default)
throw new Error('No "default" specified in package');
pkg = pkg.default;
if (!Core.knownPackageList.find((m) => m.url === url))
Core.knownPackageList.push({ url, pkg });
// system:BootLoader
// fixed semver support
let pkgSatisfies = false;
if (pkg.ver !== undefined) {
if (typeof pkg.ver === "number" || typeof pkg.ver === "string") {
if (semver.satisfies(Core.version, `>=${pkg.ver}`)) {
pkgSatisfies = true;
}
}
}
if (pkg.name && pkg.type === "process" && pkgSatisfies === true) {
console.group("Running " + url);
console.log(
`Core version: ${Core.version}\nPackage version: ${pkg.ver}`
);
// Matching Core version and type is set
console.log("Good package data");
// Check if this package is a process and call exec
if (pkg.type === "process" && typeof pkg.exec === "function") {
const PID = ProcLib.findEmptyPID();
// console.log(pkg.exec.toString());
Core.processList[PID] = {
name: url,
pid: PID,
proc: null,
};
const Token = GlobalLib.randomString();
const newLib = new processLib(url, PID, Token, pkg.strings);
if (Core.processList[PID]) Core.processList[PID].token = Token;
let result;
// console.log(pkg.privileges);
if (
url.startsWith("system:") ||
url.startsWith("ui:") ||
url.startsWith("components:") ||
url.startsWith("services:") ||
permittedApps.includes(url)
) {
result = await pkg.exec({
Lib: newLib,
Core,
PID,
Token,
Modal,
Services: Core.services,
// Provide access to GlobalLib just in case.
GlobalLib,
});
} else if (
pkg.privileges === undefined ||
pkg.privileges === false ||
pkg.optInToEvents === false
) {
result = await pkg.exec({
Lib: newLib,
Core: null,
PID,
Token,
Modal,
Services: null,
});
} else {
let privileges = {};
if (!Array.isArray(pkg.privileges)) {
throw new Error("pkg.privileges must be an array");
}
for (const item of pkg.privileges) {
if (!item || typeof item !== "object" || !item.privilege)
continue;
if (item.privilege in corePrivileges) {
privileges[item.privilege] = corePrivileges[item.privilege];
if (!item.description)
item.description =
'<span class="danger">No author note</span>';
// dangerous
if (item.privilege === "full") {
privileges[
item.privilege
].description = `<span class=\"danger\">${getString(
privileges[item.privilege].description
)}</span>`;
}
privileges[item.privilege].authorNote = item.description;
}
}
let modalResult = "";
if (force === false)
modalResult = await new Promise((resolve, reject) => {
setTimeout(() => {
let x = new Audio("./assets/alert.wav");
x.volume = 0.75;
x.play();
}, 100);
Modal.modal(
getString("core_appAccessControl_title"),
`${getString("core_appAccessControl_description", {
appName:
url === "none:<Imported as URI>"
? pkg.name
: url.split(":").pop(),
})}<br><br><ul>${Object.keys(privileges)
.map(
(m) =>
`<li>${getString(
privileges[m].description
)}<br><span class="label">${
privileges[m].authorNote !== undefined
? `${getString(
"core_appAccessControl_authorNote",
{
note: escapeHtml(
privileges[m].authorNote
),
}
)}</li>`
: `<span style="color:var(--negative-light)">${getString(
"core_appAccessControl_noAuthorNote"
)}</span>`
}</span>`
)
.join("")}</ul>`,
"body",
false,
{
text: getString("allow"),
type: "primary",
callback: (_) => resolve("allow"),
},
{
text: getString("deny"),
callback: (_) => resolve("deny"),
},
{
text: getString("cancel"),
callback: (_) => resolve(false),
}
);
});
else modalResult = "allow";
if (modalResult === "allow") {
let coreObj = {
...(privileges.startPkg ? { startPkg: Core.startPkg } : {}),
...(privileges.processList
? { processList: Core.processList }
: {}),
...(privileges.knownPackageList
? { knownPackageList: Core.knownPackageList }
: {}),
...(privileges.host ? { host: GlobalLib.host } : {}),
...(privileges.setLanguage
? { setLanguage: Core.setLanguage }
: {}),
...(privileges.services ? { services: Core.services } : {}),
};
if (privileges.full) {
coreObj = Core;
}
result = await pkg.exec({
Lib: newLib,
Core: coreObj,
PID,
Token,
Modal,
Services: Core.services,
});
} else if (modalResult === "deny") {
result = await pkg.exec({
Lib: newLib,
Core: null,
PID,
Token,
Modal,
Services: Core.services,
});
} else if (modalResult === false) {
result = null;
// Report the app was improperly quit
broadcastEventToProcs({
type: "coreEvent",
data: {
type: "pkgEnd",
detail: "forceStop",
data: Core.processList[PID],
},
});
// End the process
Core.processList[PID] = null;
return;
}
}
if (
Core.processList[PID] &&
typeof Core.processList[PID]["proc"] !== "undefined"
) {
Core.processList[PID].proc = Object.assign(
{
name: pkg?.name,
description: pkg?.description,
strings: pkg?.strings,
},
result
);
if (
typeof pkg?.optInToEvents !== "undefined" &&
pkg?.optInToEvents === true
) {
console.log("Core: adding", PID, "to optInToEvents");
procsListeningToEvents.push(PID);
}
broadcastEventToProcs({
type: "coreEvent",
data: {
type: "pkgStart",
data: Core.processList[PID],
},
});