Skip to content

Commit

Permalink
fix: dummyFunction properly fails when backend isn't running
Browse files Browse the repository at this point in the history
  • Loading branch information
beebls committed Jun 30, 2023
1 parent 1e23f5c commit 953e4eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
9 changes: 7 additions & 2 deletions backend/pythonMethods/dummyFunction.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
22 changes: 13 additions & 9 deletions backend/tauriMethods/startBackend.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
2 changes: 1 addition & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 953e4eb

Please sign in to comment.