From 05a8cb7a28a6381cd0de9b1502471bfa08421a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Cort=C3=A9z?= Date: Fri, 5 Aug 2016 15:31:22 -0500 Subject: [PATCH] Added run at startup option for installed version --- src/app-configuration.defaults | 1 + src/controller/settings.py | 12 ++++++++---- src/platform_utils/autostart/windows.py | 4 ++-- src/wxUI/dialogs/configuration.py | 2 ++ 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/app-configuration.defaults b/src/app-configuration.defaults index ea6acecd..fdf20d4e 100644 --- a/src/app-configuration.defaults +++ b/src/app-configuration.defaults @@ -8,6 +8,7 @@ language = string(default="system") hide_gui = boolean(default=False) voice_enabled = boolean(default=False) ask_at_exit = boolean(default=True) +autostart = boolean(default=False) handle_longtweets = boolean(default=True) use_invisible_keyboard_shorcuts = boolean(default=True) play_ready_sound = boolean(default=True) diff --git a/src/controller/settings.py b/src/controller/settings.py index 73e6dfb2..997943fe 100644 --- a/src/controller/settings.py +++ b/src/controller/settings.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- import os import webbrowser -#import pocket import sound_lib import paths import widgetUtils @@ -15,11 +14,10 @@ from extra.autocompletionUsers import settings from pubsub import pub import logging import config_utils -#from pocket_utils import authorisationHandler -import BaseHTTPServer log = logging.getLogger("Settings") import keys from collections import OrderedDict +from platform_utils.autostart import windows as autostart_windows class globalSettingsController(object): def __init__(self): @@ -57,8 +55,11 @@ class globalSettingsController(object): self.dialog.create_general(langs,self.kmfriendlies) self.dialog.general.language.SetSelection(id) self.dialog.general.km.SetSelection(self.kmid) + if paths.mode == "installed": + self.dialog.set_value("general", "autostart", config.app["app-settings"]["autostart"]) + else: + self.dialog.general.autostart.Enable(False) self.dialog.set_value("general", "ask_at_exit", config.app["app-settings"]["ask_at_exit"]) - self.dialog.set_value("general", "play_ready_sound", config.app["app-settings"]["play_ready_sound"]) self.dialog.set_value("general", "speak_ready_msg", config.app["app-settings"]["speak_ready_msg"]) self.dialog.set_value("general", "handle_longtweets", config.app["app-settings"]["handle_longtweets"]) @@ -86,6 +87,9 @@ class globalSettingsController(object): kmFile.close() self.needs_restart = True + if config.app["app-settings"]["autostart"] != self.dialog.get_value("general", "autostart") and paths.mode == "installed": + config.app["app-settings"]["autostart"] = self.dialog.get_value("general", "autostart") + autostart_windows.setAutoStart(application.name, enable=self.dialog.get_value("general", "autostart")) if config.app["app-settings"]["use_invisible_keyboard_shorcuts"] != self.dialog.get_value("general", "use_invisible_shorcuts"): config.app["app-settings"]["use_invisible_keyboard_shorcuts"] = self.dialog.get_value("general", "use_invisible_shorcuts") pub.sendMessage("invisible-shorcuts-changed", registered=self.dialog.get_value("general", "use_invisible_shorcuts")) diff --git a/src/platform_utils/autostart/windows.py b/src/platform_utils/autostart/windows.py index 86fcbe0d..9447540f 100644 --- a/src/platform_utils/autostart/windows.py +++ b/src/platform_utils/autostart/windows.py @@ -31,11 +31,11 @@ def getAutoStart(app_name): def setAutoStart(app_name, enable=True): """Configures automatic startup for the application, if the enable argument is set to True. If set to False, deletes the application AutoStart value.""" - + print paths.get_executable() if getAutoStart(app_name) == enable: return key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, RUN_REGKEY, 0, _winreg.KEY_WRITE) if enable: - _winreg.SetValueEx(key, unicode(app_name), None, _winreg.REG_SZ, sys.argv[0]) + _winreg.SetValueEx(key, unicode(app_name), None, _winreg.REG_SZ, paths.get_executable()) else: _winreg.DeleteValue(key, unicode(app_name)) diff --git a/src/wxUI/dialogs/configuration.py b/src/wxUI/dialogs/configuration.py index 6683b301..7f03131b 100644 --- a/src/wxUI/dialogs/configuration.py +++ b/src/wxUI/dialogs/configuration.py @@ -18,7 +18,9 @@ class general(wx.Panel, baseDialog.BaseWXDialog): langBox.Add(language, 0, wx.ALL, 5) langBox.Add(self.language, 0, wx.ALL, 5) sizer.Add(langBox, 0, wx.ALL, 5) + self.autostart = wx.CheckBox(self, -1, _(u"Run {0} at Windows startup").format(application.name,)) self.ask_at_exit = wx.CheckBox(self, -1, _(U"ask before exiting {0}").format(application.name,)) + sizer.Add(self.autostart, 0, wx.ALL, 5) sizer.Add(self.ask_at_exit, 0, wx.ALL, 5) self.play_ready_sound = wx.CheckBox(self, -1, _(U"Play a sound when {0} launches").format(application.name,)) sizer.Add(self.play_ready_sound, 0, wx.ALL, 5)