Repository navigation
Expand file tree
/
Copy pathmodpackTools.js
More file actions
50 lines (50 loc) · 1.84 KB
/
Copy pathmodpackTools.js
File metadata and controls
50 lines (50 loc) · 1.84 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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalize = normalize;
exports.importPolyMod = importPolyMod;
exports.isElectron = isElectron;
// function to detect if running on app version
function isElectron() {
// Renderer process
if (typeof window !== 'undefined' && typeof window.process === 'object' && window.process.type === 'renderer') {
return true;
}
// Main process
if (typeof process !== 'undefined' && typeof process.versions === 'object' && !!process.versions.electron) {
return true;
}
// Detect the user agent when the `nodeIntegration` option is set to false
if (typeof navigator === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent.indexOf('Electron') >= 0) {
return true;
}
return false;
}
// normalize url function
function normalize(u) {
return new URL(u).href.replace(/\/+$/, "");
}
function importPolyMod(pml, _a) {
var modurl = _a.url, modversion = _a.version;
console.info("\u23F3 Attempting to import mod: ".concat(modurl, "@").concat(modversion));
// get polyMods object
var raw = pml.getAllMods().toString();
// normalize url
var normUrl = normalize(modurl);
// avoid duplicate mod error
if (raw.includes(normUrl)) {
// skip
console.warn("\u26A0\uFE0F Skipping import; already in polyMods: ".concat(modurl));
}
// import mod if not already present
else {
// import mod
pml.addMod({ base: modurl, version: modversion, loaded: true })
.then(function (mod) {
window.PolyModLoader.setModLoaded(mod, true);
console.info("\u2705 Successfully imported: ".concat(modurl));
})
.catch(function (err) {
console.error("\u274C Failed to import ".concat(modurl, ": "), err);
});
}
}