Fix broken startup symlinks (#531)
* utility: create_startup_entry check link health * model: init always run create_startup_entry * utility: initialize_safeeyes don't call create_startup_entry * utility: add force option to create_startup_entry * model: do not create autostart, only repair broken * utility: fix comment
This commit is contained in:
parent
068771d5fd
commit
5a993a4d60
|
@ -303,6 +303,8 @@ class Config:
|
||||||
# self.__force_upgrade = ['long_breaks', 'short_breaks']
|
# self.__force_upgrade = ['long_breaks', 'short_breaks']
|
||||||
|
|
||||||
if init:
|
if init:
|
||||||
|
# if create_startup_entry finds a broken autostart symlink, it will repair it
|
||||||
|
utility.create_startup_entry(force=False)
|
||||||
if self.__user_config is None:
|
if self.__user_config is None:
|
||||||
utility.initialize_safeeyes()
|
utility.initialize_safeeyes()
|
||||||
self.__user_config = self.__system_config
|
self.__user_config = self.__system_config
|
||||||
|
|
|
@ -391,27 +391,51 @@ def initialize_safeeyes():
|
||||||
shutil.copy2(SYSTEM_STYLE_SHEET_PATH, STYLE_SHEET_PATH)
|
shutil.copy2(SYSTEM_STYLE_SHEET_PATH, STYLE_SHEET_PATH)
|
||||||
os.chmod(STYLE_SHEET_PATH, 0o777)
|
os.chmod(STYLE_SHEET_PATH, 0o777)
|
||||||
|
|
||||||
create_startup_entry()
|
# initialize_safeeyes gets called when the configuration file is not present, which happens just after installation or manual deletion of .config/safeeyes/safeeyes.json file. In these cases, we want to force the creation of a startup entry
|
||||||
|
create_startup_entry(force=True)
|
||||||
|
|
||||||
|
def create_startup_entry(force=False):
|
||||||
def create_startup_entry():
|
|
||||||
"""
|
"""
|
||||||
Create start up entry.
|
Create start up entry.
|
||||||
"""
|
"""
|
||||||
startup_dir_path = os.path.join(HOME_DIRECTORY, '.config/autostart')
|
startup_dir_path = os.path.join(HOME_DIRECTORY, '.config/autostart')
|
||||||
startup_entry = os.path.join(startup_dir_path, 'io.github.slgobinath.SafeEyes.desktop')
|
startup_entry = os.path.join(startup_dir_path, 'io.github.slgobinath.SafeEyes.desktop')
|
||||||
|
# until SafeEyes 2.1.5 the startup entry had another name
|
||||||
|
# https://github.com/slgobinath/SafeEyes/commit/684d16265a48794bb3fd670da67283fe4e2f591b#diff-0863348c2143a4928518a4d3661f150ba86d042bf5320b462ea2e960c36ed275L398
|
||||||
|
obsolete_entry = os.path.join(startup_dir_path, 'safeeyes.desktop')
|
||||||
|
|
||||||
# Create the folder if not exist
|
create_link = False
|
||||||
mkdir(startup_dir_path)
|
|
||||||
|
|
||||||
# Remove existing files
|
if force:
|
||||||
delete(startup_entry)
|
# if force is True, just create the link
|
||||||
|
create_link = True
|
||||||
|
else:
|
||||||
|
# if force is False, we want to avoid creating the startup symlink if it was manually deleted by the user, we want to create it only if a broken one is found
|
||||||
|
if os.path.islink(startup_entry):
|
||||||
|
# if the link exists, check if it is broken
|
||||||
|
try:
|
||||||
|
os.stat(startup_entry)
|
||||||
|
except FileNotFoundError:
|
||||||
|
# a FileNotFoundError will get thrown if the startup symlink is broken
|
||||||
|
create_link = True
|
||||||
|
|
||||||
# Create the new startup entry
|
if os.path.islink(obsolete_entry):
|
||||||
try:
|
# if a link with the old naming exists, delete it and create a new one
|
||||||
os.symlink(SYSTEM_DESKTOP_FILE, startup_entry)
|
create_link = True
|
||||||
except OSError:
|
delete(obsolete_entry)
|
||||||
logging.error("Failed to create startup entry at %s" % startup_entry)
|
|
||||||
|
if create_link:
|
||||||
|
# Create the folder if not exist
|
||||||
|
mkdir(startup_dir_path)
|
||||||
|
|
||||||
|
# Remove existing files
|
||||||
|
delete(startup_entry)
|
||||||
|
|
||||||
|
# Create the new startup entry
|
||||||
|
try:
|
||||||
|
os.symlink(SYSTEM_DESKTOP_FILE, startup_entry)
|
||||||
|
except OSError:
|
||||||
|
logging.error("Failed to create startup entry at %s" % startup_entry)
|
||||||
|
|
||||||
|
|
||||||
def initialize_platform():
|
def initialize_platform():
|
||||||
|
|
Loading…
Reference in New Issue