diff --git a/backend/pythonMethods/dummyFunction.ts b/backend/pythonMethods/dummyFunction.ts index 196b226..aaf3046 100644 --- a/backend/pythonMethods/dummyFunction.ts +++ b/backend/pythonMethods/dummyFunction.ts @@ -1,4 +1,9 @@ import { server } from "./server"; -export function dummyFunction() { - return server!.callPluginMethod<{}, boolean>("dummy_function", {}); +export async function dummyFunction() { + try { + return await server!.callPluginMethod<{}, boolean>("dummy_function", {}); + } catch { + // If backend is not running, fetch fails + return false; + } } diff --git a/backend/tauriMethods/startBackend.ts b/backend/tauriMethods/startBackend.ts index 858b528..14fafe8 100644 --- a/backend/tauriMethods/startBackend.ts +++ b/backend/tauriMethods/startBackend.ts @@ -1,12 +1,16 @@ import { Command } from "@tauri-apps/api/shell"; +import { dummyFunction } from "backend/pythonMethods"; export async function startBackend(onClose: any = () => {}) { - const command = new Command("startBackend", [ - "Start-Process", - "-FilePath", - "([Environment]::GetFolderPath('Startup')", - "+", - "'\\CssLoader-Standalone-Headless.exe')", - ]); - command.on("close", onClose); - await command.spawn(); + const isRunning = await dummyFunction(); + if (!isRunning) { + const command = new Command("startBackend", [ + "Start-Process", + "-FilePath", + "([Environment]::GetFolderPath('Startup')", + "+", + "'\\CssLoader-Standalone-Headless.exe')", + ]); + command.on("close", onClose); + await command.spawn(); + } } diff --git a/pages/_app.tsx b/pages/_app.tsx index df9a6ea..7d57de9 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -68,7 +68,7 @@ export default function App(AppProps: AppProps) { async function dummyFuncTest() { return dummyFunction() .then((data) => { - if (data.success) { + if (data && data.success) { setDummyResult(data.result); return true; }