diff --git a/IoTuring/Configurator/AutostartConfigurator.py b/IoTuring/Configurator/AutostartConfigurator.py new file mode 100644 index 000000000..ccb47c633 --- /dev/null +++ b/IoTuring/Configurator/AutostartConfigurator.py @@ -0,0 +1,56 @@ +import sys +import autostarter # works only with https://github.com/richibrics/autostarter.git at the moment, waiting for PR to be merged +from IoTuring.MyApp.App import App + +# todo check if autostart is enabled or disabled (need autostarter creator to add this feature) +class AutostartConfigurator(): + def run(): + selection = False + while selection is False: + print("\nConfiguring autostart...") + print("1 - Enable autostart [system-wide]") + print("2 - Disable autostart [system-wide]") + print("3 - Enable autostart [user-wide]") + print("4 - Disable autostart [user-wide]") + selection = input("Select an option: ") + + if selection == "1": + AutostartConfigurator.enable(True) + elif selection == "2": + AutostartConfigurator.disable(True) + elif selection == "3": + AutostartConfigurator.enable(False) + elif selection == "4": + AutostartConfigurator.disable(False) + else: + selection = False + + def enable(system_wide): + try: + app_name = App.getName() + script_location = f"-m {app_name}" + interpreter=sys.executable + + autostarter.add( + script_location, + identifier=app_name, + system_wide=system_wide, + interpreter=interpreter + ) + print("Autostart enabled successfully") + except Exception as e: + print("Autostart could not be enabled") + print("Error: " + str(e)) + + def disable(system_wide): + try: + app_name = App.getName() + result = autostarter.remove(app_name, system_wide=system_wide) + + if result is True: + print("Autostart disabled successfully") + else: + print("Autostart could not be disabled") + except Exception as e: + print("Autostart could not be disabled") + print("Error: " + str(e)) diff --git a/IoTuring/Configurator/Configurator.py b/IoTuring/Configurator/Configurator.py index 91a69bb05..d6217a571 100644 --- a/IoTuring/Configurator/Configurator.py +++ b/IoTuring/Configurator/Configurator.py @@ -8,6 +8,8 @@ from IoTuring.Configurator.MenuPreset import MenuPreset +from IoTuring.Configurator.AutostartConfigurator import AutostartConfigurator + BLANK_CONFIGURATION = {'active_entities': [ {"type": "AppInfo"}], 'active_warehouses': []} @@ -41,6 +43,7 @@ def Menu(self) -> None: self.PrintSeparator() print("1 - Manage entities") print("2 - Manage warehouses") + print("A - Configure autostart") print("C - Start IoTuring") print("Q - Quit\n") @@ -58,6 +61,8 @@ def Menu(self) -> None: run_app = True # Will start the program exiting from here print("") #  Blank line self.WriteConfigurations() + elif choice == "a" or choice == "A": + AutostartConfigurator.run() elif choice == "q" or choice == "Q": self.WriteConfigurations() exit(0) diff --git a/IoTuring/Entity/Deployments/Monitor/Monitor.py b/IoTuring/Entity/Deployments/Monitor/Monitor.py index 254a3a771..20cebaa1a 100644 --- a/IoTuring/Entity/Deployments/Monitor/Monitor.py +++ b/IoTuring/Entity/Deployments/Monitor/Monitor.py @@ -6,6 +6,8 @@ from IoTuring.Entity.EntityData import EntityCommand + + KEY_TURN_ALL_OFF = 'turn_all_off' KEY_TURN_ALL_ON = 'turn_all_on' diff --git a/pyproject.toml b/pyproject.toml index 091e8b07d..3e63037fd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,8 @@ dependencies = [ "psutil", "notify2", "PyYAML", - "importlib_metadata" + "importlib_metadata", + "autostarter @ git+https://github.com/richibrics/autostarter.git" ] [project.optional-dependencies]