Use @singleton decorator
This commit is contained in:
parent
3db71a08ae
commit
7e5b170f5e
@ -6,24 +6,17 @@
|
|||||||
import vlc # type: ignore
|
import vlc # type: ignore
|
||||||
|
|
||||||
# App imports
|
# App imports
|
||||||
|
from classes import singleton
|
||||||
|
|
||||||
|
|
||||||
|
@singleton
|
||||||
class VLCManager:
|
class VLCManager:
|
||||||
"""
|
"""
|
||||||
Singleton class to ensure we only ever have one vlc Instance
|
Singleton class to ensure we only ever have one vlc Instance
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__instance = None
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
if VLCManager.__instance is None:
|
self.vlc_instance = vlc.Instance()
|
||||||
self.vlc_instance = vlc.Instance()
|
|
||||||
VLCManager.__instance = self
|
|
||||||
else:
|
|
||||||
raise Exception("Attempted to create a second VLCManager instance")
|
|
||||||
|
|
||||||
@staticmethod
|
def get_instance(self) -> vlc.Instance:
|
||||||
def get_instance() -> vlc.Instance:
|
return self.vlc_instance
|
||||||
if VLCManager.__instance is None:
|
|
||||||
VLCManager()
|
|
||||||
return VLCManager.__instance
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user