From 7361086da5cad6f0c539be207983d09c00efd2b5 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Thu, 20 Mar 2025 17:44:33 +0000 Subject: [PATCH] Use @singleton decorator --- app/vlcmanager.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/app/vlcmanager.py b/app/vlcmanager.py index 8ae882d..40d95fc 100644 --- a/app/vlcmanager.py +++ b/app/vlcmanager.py @@ -6,24 +6,17 @@ import vlc # type: ignore # App imports +from classes import singleton +@singleton class VLCManager: """ Singleton class to ensure we only ever have one vlc Instance """ - __instance = None - def __init__(self) -> None: - if VLCManager.__instance is None: - self.vlc_instance = vlc.Instance() - VLCManager.__instance = self - else: - raise Exception("Attempted to create a second VLCManager instance") + self.vlc_instance = vlc.Instance() - @staticmethod - def get_instance() -> vlc.Instance: - if VLCManager.__instance is None: - VLCManager() - return VLCManager.__instance + def get_instance(self) -> vlc.Instance: + return self.vlc_instance