This repository has been archived by the owner on Sep 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpreload.ts
84 lines (72 loc) · 3.2 KB
/
preload.ts
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
import fs from "fs";
import path from "path";
import { ipcRenderer } from "electron";
import log from "electron-log";
declare global {
interface Window {
ipcRenderer?: typeof ipcRenderer;
log?: typeof log;
}
}
window.ipcRenderer = ipcRenderer;
log.transports.console.format = "[{d}-{m}-{y}] [{h}:{i}:{s}T{z}] -- [{processType}] -- [{level}] -- {text}";
log.transports.file.format = "[{d}-{m}-{y}] [{h}:{i}:{s}T{z}] -- [{processType}] -- [{level}] -- {text}";
log.transports.file.fileName = "renderer.log";
log.transports.file.maxSize = 10485760;
log.transports.file.getFile();
log.info("Main Window Preload Began.");
window.addEventListener("DOMContentLoaded", () => {
ipcRenderer.send("GetModData", "");
console.log("%cDON'T TYPE ANYTHING IN THIS CONSOLE UNLESS YOU KNOW WHAT YOU ARE DOING!", "background-color:black;border-radius:10px;padding:5px;color:red;font-family:Arial;font-size:25px;font-weight:bold;");
});
// Can't load this before initialization!
window.log = log;
ipcRenderer.on("ShowMods", (event, data) => {
document.getElementById("modlist-updating").remove();
const sidebar = document.getElementById("sidebar");
data.mods.forEach((modentry) => {
if (!modentry.hasOwnProperty("devOnly") || !modentry.devOnly || (modentry.devOnly && data.isDev)) {
const div = document.createElement("div");
div.className = "entry";
sidebar.appendChild(div);
const image = document.createElement("img");
image.src = modentry.icon;
div.appendChild(image);
const divModInfoSidebar = document.createElement("div");
divModInfoSidebar.className = "mod-info-sidebar";
div.appendChild(divModInfoSidebar);
const title = document.createElement("h2");
title.innerText = modentry.name;
divModInfoSidebar.appendChild(title);
const blurb = document.createElement("p");
blurb.innerText = modentry.blurb;
divModInfoSidebar.appendChild(blurb);
div.addEventListener("click", () => {
OnClick_Mod(modentry);
}, false);
}
});
const updateButton_Fail = document.getElementById("update-button-fail");
const launcherVersionBox = document.getElementById("launcher-version");
const config: any = fs.readFileSync(path.join(__dirname, "..", "package.json"));
const currentClientVersion: number = JSON.parse(config).version;
fetch("https://api.github.com/repos/CreatorsTF/Creators.TF-Community-Launcher/releases/latest").then((res) => {
if (res.status === 200) {
res.json().then((data) => {
const version = data.tag_name;
if (currentClientVersion === version) {
launcherVersionBox.remove();
} else {
launcherVersionBox.innerText = "A new update is available for the launcher.";
}
});
} else {
updateButton_Fail.classList.remove("hidden");
console.log("There was a problem! Status Code: " + res.status);
return;
}
})
.catch((err) => {
console.log("Error!", err);
});
});