diff --git a/FCLauncher/src-tauri/Cargo.toml b/FCLauncher/src-tauri/Cargo.toml index 9de253f..66df6fa 100644 --- a/FCLauncher/src-tauri/Cargo.toml +++ b/FCLauncher/src-tauri/Cargo.toml @@ -21,11 +21,8 @@ zip-extract = "0.1.3" dirs = "5.0.1" gethostname = "0.4.3" self_update = "0.40.0" +parking_lot = "0.12.3" [features] # This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!! custom-protocol = ["tauri/custom-protocol"] - -[[bin]] -name = "FCLauncher" -path = "src/main.rs" diff --git a/FCLauncher/src-tauri/src/admin.rs b/FCLauncher/src-tauri/src/admin.rs new file mode 100644 index 0000000..e3cf0e7 --- /dev/null +++ b/FCLauncher/src-tauri/src/admin.rs @@ -0,0 +1,15 @@ +use crate::ftp::{self, test_cred}; + +static USERNAME: parking_lot::Mutex = parking_lot::const_mutex(String::new()); +static PASSWORD: parking_lot::Mutex = parking_lot::const_mutex(String::new()); + +#[tauri::command] +pub fn login(username: String, password: String, window: tauri::Window) { + if(test_cred(username.as_str(), password.as_str())){ + *USERNAME.lock() = username; + *PASSWORD.lock() = password; + window.emit("Login_Success", {}); + }else{ + window.emit("Login_Failed", {}); + } +} \ No newline at end of file diff --git a/FCLauncher/src-tauri/src/ftp.rs b/FCLauncher/src-tauri/src/ftp.rs index 16a3302..2daae13 100644 --- a/FCLauncher/src-tauri/src/ftp.rs +++ b/FCLauncher/src-tauri/src/ftp.rs @@ -12,6 +12,10 @@ fn ftp_connection_anonymous() -> Result{ ftp_connection("anonymous", "anonymous@") } +pub fn test_cred(username: &str, password: &str) -> bool{ + return ftp_connection(username, password).is_ok(); +} + fn ftp_connection(username: &str, password: &str) -> Result{ let ftp_stream = NativeTlsFtpStream::connect("gitea.piwalker.net:21").unwrap_or_else(|err| @@ -20,10 +24,13 @@ fn ftp_connection(username: &str, password: &str) -> Result, file: PathBuf , mut writer: impl Write, mut callback: impl FnMut(Option, usize, usize)) -> Result { let mut ftp_stream = ftp_connection_anonymous().unwrap(); let file = file.to_str().unwrap().replace("\\", "/"); diff --git a/FCLauncher/src-tauri/src/main.rs b/FCLauncher/src-tauri/src/main.rs index 785ce12..2f5b79c 100644 --- a/FCLauncher/src-tauri/src/main.rs +++ b/FCLauncher/src-tauri/src/main.rs @@ -15,6 +15,7 @@ mod prism; mod system_dirs; mod util; mod modpack; +mod admin; #[derive(Serialize, Deserialize)] struct ModpackEntry{ @@ -33,7 +34,7 @@ fn main() { modpack::get_modpacks(); //prism::install_prism(); tauri::Builder::default() - .invoke_handler(tauri::generate_handler![greet, modpack::get_modpacks, modpack::launch_modpack, prism::launch_prism, prism::install_prism]) + .invoke_handler(tauri::generate_handler![greet, modpack::get_modpacks, modpack::launch_modpack, prism::launch_prism, prism::install_prism, admin::login]) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/FCLauncher/src/Admin.html b/FCLauncher/src/Admin.html new file mode 100644 index 0000000..b3cfc72 --- /dev/null +++ b/FCLauncher/src/Admin.html @@ -0,0 +1,30 @@ + + + + + + + Tauri App + + + + + + + + + + +
+
+
+ + +
+

Administration

+
+ + diff --git a/FCLauncher/src/Login.html b/FCLauncher/src/Login.html new file mode 100644 index 0000000..6bfcfe9 --- /dev/null +++ b/FCLauncher/src/Login.html @@ -0,0 +1,33 @@ + + + + + + + Tauri App + + + + + + + + + + + + +
+

Username or Password is incorrect!

+ + +
+ + +
+
+ + diff --git a/FCLauncher/src/admin.js b/FCLauncher/src/admin.js new file mode 100644 index 0000000..d9f5c3b --- /dev/null +++ b/FCLauncher/src/admin.js @@ -0,0 +1,36 @@ +const { invoke } = window.__TAURI__.tauri; +const { listen } = window.__TAURI__.event; +const { ask } = window.__TAURI__.dialog; +const downBar = document.querySelector(".progressFinished"); +//import { listen } from '@tauri-apps/api'; + +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"); + let downProgress = (progress.payload.downloaded/(1024*1024)).toFixed(2); + let downTotal = (progress.payload.total/(1024*1024)).toFixed(2); + document.getElementById("download_name").textContent = "Downloading "+progress.payload.download_name; + document.getElementById("download_progress").textContent = downProgress + "MB / "+downTotal+"MB"; + document.getElementById("launchGame").disabled = true; + downBar.style.width = `${(progress.payload.downloaded / progress.payload.total) * 100}%`; + document.querySelector(".progress").style.visibility = "visible"; +}); + +const download_finished = listen("download_finished", (event) => { + document.getElementById("download_name").textContent = ""; + document.getElementById("download_progress").textContent = ""; + document.getElementById("launchGame").disabled = false; + document.getElementById("launchGame").textContent ="Launch Minecraft"; + downBar.style.width = 0; + document.querySelector(".progress").style.visibility = "hidden"; +}); + +window.addEventListener("DOMContentLoaded", () => { + + document.getElementById("back").addEventListener("click", back); + +}); + +function back(){ + window.location.href = "index.html"; +} \ No newline at end of file diff --git a/FCLauncher/src/assets/back.png b/FCLauncher/src/assets/back.png new file mode 100644 index 0000000..32cd377 Binary files /dev/null and b/FCLauncher/src/assets/back.png differ diff --git a/FCLauncher/src/assets/settings.jpg b/FCLauncher/src/assets/settings.jpg new file mode 100644 index 0000000..304202f Binary files /dev/null and b/FCLauncher/src/assets/settings.jpg differ diff --git a/FCLauncher/src/assets/settings.png b/FCLauncher/src/assets/settings.png new file mode 100644 index 0000000..5403108 Binary files /dev/null and b/FCLauncher/src/assets/settings.png differ diff --git a/FCLauncher/src/index.html b/FCLauncher/src/index.html index a7b97d8..d342cf5 100644 --- a/FCLauncher/src/index.html +++ b/FCLauncher/src/index.html @@ -15,6 +15,7 @@
diff --git a/FCLauncher/src/login.js b/FCLauncher/src/login.js new file mode 100644 index 0000000..f959680 --- /dev/null +++ b/FCLauncher/src/login.js @@ -0,0 +1,37 @@ +const { invoke } = window.__TAURI__.tauri; +const { listen } = window.__TAURI__.event; +const { ask } = window.__TAURI__.dialog; +const downBar = document.querySelector(".progressFinished"); +//import { listen } from '@tauri-apps/api'; + +window.addEventListener("DOMContentLoaded", () => { + + document.getElementById("back").addEventListener("click", back); + document.getElementById("Cancel").addEventListener("click", back); + document.getElementById("Login").addEventListener("click", login); + document.getElementById("Password").addEventListener("keypress", keypress); + +}); + +function back(){ + window.location.href = "index.html"; +} + +function login(){ + invoke("login", { username: document.getElementById("Username").value, password: document.getElementById("Password").value}); +} + +function keypress(e){ + if(e.keyCode === 13){ + e.preventDefault(); + login(); + } +} + +const failed = listen("Login_Failed", (event) => { + document.getElementById("Incorrect").style.visibility = "visible"; +}) + +const success = listen("Login_Success", (event) => { + window.location.href = "Admin.html"; +}) \ No newline at end of file diff --git a/FCLauncher/src/main.js b/FCLauncher/src/main.js index 7f7808e..9c73265 100644 --- a/FCLauncher/src/main.js +++ b/FCLauncher/src/main.js @@ -33,6 +33,8 @@ window.addEventListener("DOMContentLoaded", () => { document.getElementById("launchGame").addEventListener("click", gameLaunch); document.getElementById("prism").addEventListener("click", prism); + document.getElementById("settings").addEventListener("click", login); + document.getElementById("back").addEventListener("click", back); }); function packSelect() { @@ -40,6 +42,15 @@ function packSelect() { } +function login(){ + window.location.href = "Login.html"; +} + +function back(){ + console.log("test"); + window.location.href = "index.html"; +} + function load() { console.log("loading"); var dropdown = document.getElementById("Modpacks"); diff --git a/FCLauncher/src/styles.css b/FCLauncher/src/styles.css index 969ac31..c704f69 100644 --- a/FCLauncher/src/styles.css +++ b/FCLauncher/src/styles.css @@ -228,3 +228,49 @@ button { display: block; margin: 0.5em; } + +#settings{ + width: 2em; + height: 2.5em; + top: 5px; + left: 5px; + float: right; + position: absolute; + background-image: url('assets/settings.png'); + background-size:cover; + background-repeat: no-repeat; +} + +#back{ + width: 2em; + height: 2.5em; + top: 5px; + left: 5px; + float: right; + position: absolute; + background-image: url('assets/back.png'); + background-size:cover; + background-repeat: no-repeat; +} + +.container input{ + margin: 0.5em; + width: 45% +} + +.loginButtons{ + display: flex; + margin: 0.5em; + flex-direction: row; + margin-left: auto; + margin-right: auto; + width: 50%; + gap: .5em; +} + +.Error{ + color: black; + background-color: red; + margin: 0; + visibility: hidden; +} \ No newline at end of file