Skip to content

Commit

Permalink
Events!
Browse files Browse the repository at this point in the history
  • Loading branch information
RedstoneWizard08 committed Mar 10, 2023
1 parent 127fa94 commit 7df8bc6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
7 changes: 3 additions & 4 deletions app/src/mocks/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ export const downloadBepInEx = async () => {

const resp = await axios.get<Blob>(url, {
onDownloadProgress: (ev) => {
emit("download_progress_bepinex", {
current: ev.loaded,
emit("download_progress", {
received: ev.loaded,
total: ev.total,
progress: ev.progress,
});
},

Expand All @@ -39,6 +38,6 @@ export const downloadBepInEx = async () => {

document.body.appendChild(a);

a.click();
// a.click();
a.remove();
};
20 changes: 18 additions & 2 deletions app/src/routes/InstallProgress.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
import "./InstallProgress.scss";
import banner from "../assets/background_banner.png";
import { useState } from "preact/hooks";
import { useEffect, useState } from "preact/hooks";
import { invoke_proxy } from "../invoke";
import { route } from "preact-router";
import { listen } from "@tauri-apps/api/event";

let _listening = false;

export const InstallProgress = () => {
const [status, setStatus] = useState({
percent: "0%",
message: "Waiting for start button...",
});

useEffect(() => {
if (!_listening) {
listen("download_progress", (ev) => {
setStatus({
percent: ((100 * (ev.payload as any).received) / (ev.payload as any).total) + "%",
message: status.message,
});
});

_listening = true;
}
});

const [installed, setInstalled] = useState(false);

const getInstallDir = async (): Promise<Error | null> => {
setStatus({ percent: "0%", message: "Finding KSP2 location..." });

const _dir = await invoke_proxy("get_install_dir");

if (/[A-Z]:(?:\\|\/).+/gm.test(_dir)) {
if (/(?:(:?[A-Z]:(?:\\|\/).+)|(:?\/.+))/gm.test(_dir)) {
return null;
}

Expand Down
9 changes: 7 additions & 2 deletions src-tauri/src/finder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::{path::PathBuf, fs};

pub mod pdlauncher;
pub mod resolver;
Expand All @@ -22,5 +22,10 @@ pub fn find_install_dir() -> PathBuf {
return dir;
}

return None.expect("No KSP2 install found!");
let p = PathBuf::from("/home/jacob/.local/share/steam/root/steamapps/common/Kerbal Space Program 2");

fs::create_dir_all(p.clone()).unwrap();

return p;
// return None.expect("No KSP2 install found!");
}

0 comments on commit 7df8bc6

Please sign in to comment.