Skip to content

Commit

Permalink
Big Protein (150g of protein) (okay i just added a "Open Backend Path…
Browse files Browse the repository at this point in the history
…" button)
  • Loading branch information
beebls committed Sep 9, 2023
1 parent ee65cf7 commit 9dcb303
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
24 changes: 19 additions & 5 deletions pages/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export default function SettingsPage() {

const [ongoingAction, setOngoingAction] = useState<boolean>(false);

const [showBackendInstallModal, setShowBackendInstallModal] = useState<boolean>(false);
const [installText, setInstallText] = useState<string>("");
const [installModalDesc, setInstallModalDesc] = useState<string>("");
// const [showBackendInstallModal, setShowBackendInstallModal] = useState<boolean>(false);
// const [installText, setInstallText] = useState<string>("");
// const [installModalDesc, setInstallModalDesc] = useState<string>("");

function onSaveToken() {
if (token.length !== 12) {
Expand Down Expand Up @@ -140,7 +140,21 @@ export default function SettingsPage() {
>
{ongoingAction ? <ImSpinner5 /> : "Force Start Backend"}
</button>
<AlertDialog
<button
disabled={ongoingAction}
onClick={async () => {
// These have to be async imported here as otherwise NextJS tries to "SSR" them and it errors
const { invoke } = await import("@tauri-apps/api");
const { open } = await import("@tauri-apps/api/shell");
const { resolve } = await import("@tauri-apps/api/path");
const path = await resolve(await invoke("get_string_startup_dir", {}));
open(path);
}}
className="flex h-12 items-center justify-center whitespace-nowrap rounded-xl bg-base-3-dark px-4 focus-visible:ring-4 focus-visible:ring-amber9"
>
Open Backend Location
</button>
{/* <AlertDialog
cancelText="Go Back"
title="Wait A Second!"
description="This feature is meant for developers. If you do not understand exactly what you're doing, cancel this popup. Do not install files from untrusted sources."
Expand Down Expand Up @@ -200,7 +214,7 @@ export default function SettingsPage() {
installText={installText}
dontClose
/>
)}
)} */}
</>
)}
{/* This was a WIP thing that would print out the current app state to a txt file, doesn't seem needed */}
Expand Down
6 changes: 3 additions & 3 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 21 additions & 4 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use winapi::shared::minwindef::DWORD;

fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![download_template,kill_standalone_backend,download_latest_backend,start_backend,install_backend])
.invoke_handler(tauri::generate_handler![download_template,kill_standalone_backend,download_latest_backend,start_backend,install_backend,get_string_startup_dir])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
Expand All @@ -42,19 +42,36 @@ async fn download_template(template_name: String) -> bool {
return !extract.is_err()
}

async fn get_backend_path() -> Option<PathBuf> {
async fn get_startup_dir() -> Option<PathBuf> {
if let Some(base_dirs) = BaseDirs::new() {
let config = base_dirs.config_dir();
let startup_dir: std::path::PathBuf = Path::new(&config).join("Microsoft\\Windows\\Start Menu\\Programs\\Startup");
let backend_file_name: std::path::PathBuf = startup_dir.join("CssLoader-Standalone-Headless.exe");
// TODO: MAKE SURE THE FILE OR DIRECTORY EXISTS
// MAYBE NOT THE FILE AS ON INITIAL INSTALL IT WONT EXIST
// BUT THE FOLDER FOR SURE
return Some(backend_file_name);
return Some(startup_dir);
}
return None;
}

async fn get_backend_path() -> Option<PathBuf> {
let startup_dir = get_startup_dir().await;
if startup_dir.is_none() {
return None;
}
let backend_file_name = startup_dir.unwrap().join("CssLoader-Standalone-Headless.exe");
return Some(backend_file_name);
}

#[tauri::command]
async fn get_string_startup_dir() -> String {
let startup_dir = get_startup_dir().await;
if startup_dir.is_none() {
return "ERROR:".to_owned();
}
return startup_dir.unwrap().to_string_lossy().to_string();
}

#[tauri::command]
async fn install_backend(backend_url: String) -> String {
kill_standalone_backend().await;
Expand Down

0 comments on commit 9dcb303

Please sign in to comment.