FCLauncher/FCLauncher.old/src/main.js

115 lines
3.8 KiB
JavaScript
Raw Normal View History

2024-06-22 17:17:07 -06:00
const { invoke } = window.__TAURI__.tauri;
2024-06-23 15:07:25 -06:00
const { listen } = window.__TAURI__.event;
2024-09-28 09:12:45 -06:00
const { ask, message } = window.__TAURI__.dialog;
2024-07-14 08:44:16 -06:00
const { exit } = window.__TAURI__.process;
2024-06-23 19:24:04 -06:00
const downBar = document.querySelector(".progressFinished");
2024-06-23 15:07:25 -06:00
//import { listen } from '@tauri-apps/api';
2024-06-22 17:17:07 -06:00
2024-09-28 09:12:45 -06:00
const error = listen("Error", (error) => {
message(error.payload, {title: "Error", type: "error"});
});
2024-06-23 15:07:25 -06:00
const download_progress = listen("download_progress", (progress) => {
console.log("Downloading");
//console.log("Downloaded "+progress.payload.downloaded/(1024*1024) +"MB / " + progress.payload.total/(1024*1024) + "MB");
2024-06-23 17:49:20 -06:00
let downProgress = (progress.payload.downloaded/(1024*1024)).toFixed(2);
let downTotal = (progress.payload.total/(1024*1024)).toFixed(2);
2024-06-23 15:07:25 -06:00
document.getElementById("download_name").textContent = "Downloading "+progress.payload.download_name;
2024-06-23 17:49:20 -06:00
document.getElementById("download_progress").textContent = downProgress + "MB / "+downTotal+"MB";
2024-06-23 15:07:25 -06:00
document.getElementById("launchGame").disabled = true;
2024-06-23 19:24:04 -06:00
downBar.style.width = `${(progress.payload.downloaded / progress.payload.total) * 100}%`;
document.querySelector(".progress").style.visibility = "visible";
2024-06-23 15:07:25 -06:00
});
const download_finished = listen("download_finished", (event) => {
document.getElementById("download_name").textContent = "";
document.getElementById("download_progress").textContent = "";
document.getElementById("launchGame").disabled = false;
2024-06-23 17:49:20 -06:00
document.getElementById("launchGame").textContent ="Launch Minecraft";
2024-06-23 19:24:04 -06:00
downBar.style.width = 0;
document.querySelector(".progress").style.visibility = "hidden";
2024-06-23 15:07:25 -06:00
});
2024-06-22 17:17:07 -06:00
2024-06-23 15:29:35 -06:00
const update_dialog = listen("update_dialog", (event) => {
ask("Do you want to update?", {title: "Update Available", type: "Message"}).then((value) => { if (value) { invoke("update").then(window.close()); } });
});
2024-06-22 17:17:07 -06:00
window.addEventListener("DOMContentLoaded", () => {
2024-06-22 22:12:41 -06:00
2024-06-22 23:12:05 -06:00
document.getElementById("launchGame").addEventListener("click", gameLaunch);
2024-06-26 07:49:31 -06:00
document.getElementById("prism").addEventListener("click", prism);
2024-07-12 21:11:52 -06:00
document.getElementById("settings").addEventListener("click", login);
document.getElementById("back").addEventListener("click", back);
2024-06-22 23:12:05 -06:00
2024-06-22 17:17:07 -06:00
});
2024-06-22 18:36:47 -06:00
function packSelect() {
document.getElementById("myDropdown").classList.toggle("show");
}
2024-07-12 21:11:52 -06:00
function login(){
window.location.href = "Login.html";
}
function back(){
console.log("test");
window.location.href = "index.html";
}
2024-06-22 18:36:47 -06:00
function load() {
console.log("loading");
var dropdown = document.getElementById("Modpacks");
var opt = document.createElement("option");
opt.text = 'something';
opt.value = 'somethings value';
dropdown.options.add(opt);
}
window.onload = async function() {
2024-06-23 15:07:25 -06:00
invoke("install_prism");
2024-06-22 18:36:47 -06:00
invoke("get_modpacks").then(addModpacks);
2024-06-23 19:24:04 -06:00
console.log(downBar.style.width)
2024-06-22 18:36:47 -06:00
}
function addModpacks(modpacks) {
2024-06-22 22:12:41 -06:00
2024-06-22 18:36:47 -06:00
var dropdown = document.getElementById("Modpacks");
//modpacks.sort((a, b) => a.name.localeCompare(b.name));
//modpacks.reverse();
2024-06-22 20:34:38 -06:00
for (let i = 0; i < modpacks.length; i++){
var opt = document.createElement("option");
2024-06-22 22:12:41 -06:00
opt.text = modpacks[i].name;
opt.value = modpacks[i].id;
2024-06-22 20:34:38 -06:00
dropdown.options.add(opt);
}
2024-06-22 18:36:47 -06:00
}
2024-06-23 15:29:35 -06:00
2024-06-22 23:12:05 -06:00
function gameLaunch() {
2024-06-22 22:12:41 -06:00
var packId = document.getElementById("Modpacks");
var selectedId = packId.value;
2024-06-23 15:07:25 -06:00
document.getElementById("launchGame").disabled = true;
2024-06-23 17:49:20 -06:00
document.getElementById("launchGame").textContent ="Launching...";
2024-06-22 23:12:05 -06:00
//TODO Launch Game
2024-07-14 08:44:16 -06:00
invoke("launch_modpack", { id: selectedId}).then(() => { exit(1); });
2024-06-22 23:21:46 -06:00
2024-06-22 23:12:05 -06:00
2024-06-22 22:12:41 -06:00
}
2024-06-26 07:49:31 -06:00
function prism(){
invoke("launch_prism");
}
2024-06-22 18:36:47 -06:00
//window.onclick = function(event) {
//if (!event.target.matches('.dropbtn')) {
//var dropdowns = document.getElementsByClassName("dropdown-content");
//var i;
//for (i = 0; i < dropdowns.length; i++) {
//var openDropdown = dropdowns[i];
//if (openDropdown.classList.contains('show')) {
//openDropdown.classList.remove('show');
//}
//}
//}
2024-06-23 15:07:25 -06:00
//}