Use symlink for autostart

merge-requests/64/head
Huluti 2016-12-05 21:49:29 +01:00
parent 045ad8c811
commit fa6bb0814c
1 changed files with 12 additions and 9 deletions

View File

@ -4,7 +4,6 @@ import locale
import gettext import gettext
import os import os
import json import json
import shutil
import webbrowser import webbrowser
import gi import gi
gi.require_version("Gtk", "3.0") gi.require_version("Gtk", "3.0")
@ -12,16 +11,20 @@ from gi.repository import Gtk
class ManjaroHello(Gtk.Window): class ManjaroHello(Gtk.Window):
def __init__(self): def __init__(self):
# App vars
self.app = "manjaro-hello"
# Path vars # Path vars
config_path = "{}/.config/".format(os.path.expanduser("~")) config_path = os.path.expanduser("~") + "/.config/"
self.preferences_path = config_path + "manjaro-hello.json" #share_path = "/usr/share/"
self.autostart_path = config_path + "autostart/manjaro-hello.desktop"
self.icon_path = "manjaro-hello.png" self.preferences_path = config_path + self.app +".json"
self.desktop_path = os.getcwd() + "/" + self.app + ".desktop" # later use share_path
self.autostart_path = config_path + "autostart/" + self.app + ".desktop"
self.icon_path = self.app + ".png"
# Languages vars # Languages vars
self.language = locale.getlocale()[0][:2] self.language = locale.getlocale()[0][:2]
self.default_language = "en" self.default_language = "en"
self.app = "manjaro-hello"
self.locale_dir = "locale" self.locale_dir = "locale"
# Settings vars # Settings vars
@ -60,7 +63,7 @@ class ManjaroHello(Gtk.Window):
for page in ("readme", "release", "involved"): for page in ("readme", "release", "involved"):
self.builder.get_object(page + "text").set_markup(self.read_page(page)) self.builder.get_object(page + "text").set_markup(self.read_page(page))
# Set switcher state # Set autostart switcher state
self.builder.get_object("autostart").set_active(self.preferences["autostart"]) self.builder.get_object("autostart").set_active(self.preferences["autostart"])
self.window.show() self.window.show()
@ -68,13 +71,13 @@ class ManjaroHello(Gtk.Window):
def change_autostart(self, state): def change_autostart(self, state):
if state and not os.path.isfile(self.autostart_path): if state and not os.path.isfile(self.autostart_path):
try: try:
shutil.copyfile("manjaro-hello.desktop", self.autostart_path) os.symlink(self.desktop_path, self.autostart_path)
self.preferences["autostart"] = True self.preferences["autostart"] = True
except OSError as e: except OSError as e:
print(e) print(e)
elif not state and os.path.isfile(self.autostart_path): elif not state and os.path.isfile(self.autostart_path):
try: try:
os.remove(self.autostart_path) os.unlink(self.autostart_path)
self.preferences["autostart"] = False self.preferences["autostart"] = False
except OSError as e: except OSError as e:
print(e) print(e)