ui: control autostart feature exceptions

Display a warning if it fails.
This commit is contained in:
Gustavo Iñiguez Goia 2023-07-26 14:55:11 +02:00
parent 138b8d0c33
commit 6d65eb6f53
Failed to generate hash of commit
2 changed files with 9 additions and 9 deletions

View file

@ -200,7 +200,13 @@ class UIService(ui_pb2_grpc.UIServicer, QtWidgets.QGraphicsObject):
self._menu.aboutToShow.connect(self._on_show_menu)
def _on_switch_autostart(self):
self._autostart.enable(self._menu_autostart.isChecked())
try:
self._autostart.enable(self._menu_autostart.isChecked())
except Exception as e:
self._desktop_notifications.show(
QC.translate("stats", "Warning"),
QC.translate("stats", str(e))
)
def _on_show_menu(self):
self._menu_autostart.setChecked(self._autostart.isEnabled())

View file

@ -88,16 +88,10 @@ class Autostart():
if os.path.isfile(self.systemAutostart) and os.path.isfile(self.userAutostart):
os.remove(self.userAutostart)
elif os.path.isfile(self.systemDesktop):
try:
shutil.copyfile(self.systemDesktop, self.userAutostart)
except shutil.SameFileError:
pass
shutil.copyfile(self.systemDesktop, self.userAutostart)
else:
if os.path.isfile(self.systemAutostart):
try:
shutil.copyfile(self.systemAutostart, self.userAutostart)
except shutil.SameFileError:
pass
shutil.copyfile(self.systemAutostart, self.userAutostart)
with open(self.userAutostart, 'a') as f:
f.write('Hidden=true\n')
elif os.path.isfile(self.userAutostart):