utility: add force option to create_startup_entry
This commit is contained in:
parent
49ce955303
commit
60622b9cfd
|
@ -391,18 +391,40 @@ def initialize_safeeyes():
|
|||
shutil.copy2(SYSTEM_STYLE_SHEET_PATH, STYLE_SHEET_PATH)
|
||||
os.chmod(STYLE_SHEET_PATH, 0o777)
|
||||
|
||||
# initialize_safeeyes gets called when the configuration file is not present, which happens just after installation or reset. In these cases, we want to force the creation of a startup entry
|
||||
create_startup_entry(force=True)
|
||||
|
||||
def create_startup_entry():
|
||||
def create_startup_entry(force=False):
|
||||
"""
|
||||
Create start up entry.
|
||||
"""
|
||||
startup_dir_path = os.path.join(HOME_DIRECTORY, '.config/autostart')
|
||||
startup_entry = os.path.join(startup_dir_path, 'io.github.slgobinath.SafeEyes.desktop')
|
||||
|
||||
# a FileNotFoundError will get thrown if the startup symlink is missing or is broken
|
||||
try:
|
||||
os.stat(startup_entry)
|
||||
except FileNotFoundError:
|
||||
# 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_link = False
|
||||
|
||||
if force:
|
||||
# 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
|
||||
|
||||
if os.path.islink(obsolete_entry):
|
||||
# if a link with the old naming exists, delete it and create a new one
|
||||
create_link = True
|
||||
delete(obsolete_entry)
|
||||
|
||||
if create_link:
|
||||
# Create the folder if not exist
|
||||
mkdir(startup_dir_path)
|
||||
|
||||
|
|
Loading…
Reference in New Issue