diff --git a/src/module/api/program.py b/src/module/api/program.py index b4c0f33e..d8cf46c4 100644 --- a/src/module/api/program.py +++ b/src/module/api/program.py @@ -45,8 +45,7 @@ async def start(current_user=Depends(get_current_user)): status_code=status.HTTP_401_UNAUTHORIZED, detail="invalid token" ) try: - program.start() - return {"status": "ok"} + return program.start() except Exception as e: logger.debug(e) logger.warning("Failed to start program") @@ -59,8 +58,7 @@ async def stop(current_user=Depends(get_current_user)): raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="invalid token" ) - program.stop() - return {"status": "ok"} + return program.stop() @router.get("/api/v1/status", tags=["program"]) diff --git a/src/module/core/program.py b/src/module/core/program.py index c3182865..21e37bf4 100644 --- a/src/module/core/program.py +++ b/src/module/core/program.py @@ -35,6 +35,8 @@ class Program(RenameThread, RSSThread): self.start() def start(self): + if self.first_run: + return {"status": "Not ready to start."} self.stop_event.clear() settings.load() if self.enable_renamer: @@ -49,6 +51,7 @@ class Program(RenameThread, RSSThread): self.stop_event.set() self.rename_stop() self.rss_stop() + return {"status": "Program stopped."} else: return {"status": "Program is not running."} diff --git a/src/module/core/status.py b/src/module/core/status.py index 1e2f3fc2..de42599b 100644 --- a/src/module/core/status.py +++ b/src/module/core/status.py @@ -16,7 +16,10 @@ class ProgramStatus(Checker): @property def is_running(self): - return not self.stop_event.is_set() + if self.stop_event.is_set() or self.check_first_run(): + return False + else: + return True @property def is_stopped(self):