add startup management

main
mirkobrombin 2 years ago
parent 744c81bcce
commit 587dbeea12

@ -1,3 +1,5 @@
import os
import time
import logging
from ubuntu_smoother.utils import checks
@ -20,15 +22,16 @@ class Configurator:
self.__enable_flatpak() if self.config.flatpak else self.__disable_flatpak()
self.__enable_apport() if self.config.apport else self.__disable_apport()
def __fake(self, msg: str):
time.sleep(1)
logger.info(f"Fake: {msg}")
def __enable_snap(self):
if self.fake:
logger.info("Fake: Snap enabled")
return
return self.__fake("Fake: Snap enabled")
pkgs = []
if not checks.is_snap_installed():
pkgs += ['snapd', 'gnome-software-plugin-snap']
Apt.install(pkgs)
Apt.install(['snapd', 'gnome-software-plugin-snap'])
Apt.update()
if not self.config.flatpak:
@ -36,34 +39,30 @@ class Configurator:
def __disable_snap(self):
if self.fake:
logger.info("Fake: Snap disabled")
return
return self.__fake("Fake: Snap disabled")
if checks.is_snap_installed():
Apt.purge(['snapd'])
def __enable_flatpak(self):
if self.fake:
logger.info("Fake: Flatpak enabled")
return
return self.__fake("Fake: Flatpak enabled")
if not checks.is_flatpak_installed():
Apt.install(['flatpak'])
Flatpak.add_repo("https://flathub.org/repo/flathub.flatpakrepo")
Apt.update()
Flatpak.add_repo("https://flathub.org/repo/flathub.flatpakrepo")
def __disable_flatpak(self):
if self.fake:
logger.info("Fake: Flatpak disabled")
return
return self.__fake("Fake: Flatpak disabled")
if checks.is_flatpak_installed():
Apt.purge(['flatpak'])
def __enable_apport(self):
if self.fake:
logger.info("Fake: Apport enabled")
return
return self.__fake("Fake: Apport enabled")
if not checks.is_apport_installed():
Apt.install(['apport'])
@ -71,8 +70,30 @@ class Configurator:
def __disable_apport(self):
if self.fake:
logger.info("Fake: Apport disabled")
return
return self.__fake("Fake: Apport disabled")
if checks.is_apport_installed():
Apt.purge(['apport'])
def __disable_on_startup(self):
if self.fake:
return self.__fake("Fake: Disable on startup")
autostart_file = os.path.expanduser("~/.config/autostart/ubuntu-smoother.desktop")
if os.path.exists(autostart_file):
os.remove(autostart_file)
def __enable_on_startup(self):
if self.fake:
return self.__fake("Fake: Enable on startup")
autostart_file = os.path.expanduser("~/.config/autostart/ubuntu-smoother.desktop")
if not os.path.exists(autostart_file):
with open(autostart_file, "w") as f:
f.write("[Desktop Entry]")
f.write("Type=Application")
f.write("Name=Ubuntu Smoother")
f.write("Exec=ubuntu-smoother")
f.write("Terminal=false")
f.write("X-GNOME-Autostart-enabled=true")
Loading…
Cancel
Save