aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Weth <git@jonathanweth.de>2021-07-01 12:51:16 +0200
committerJonathan Weth <git@jonathanweth.de>2021-07-01 12:54:24 +0200
commitb960080e50b73fc13cb69471750dd62260ef327e (patch)
tree5ce2d1f9eae1b35fdf9cda69bef35e31b90830d5
parent78e14ca8043814c5816a10756fed31e075f87b03 (diff)
downloadRWA.Support.SessionService-b960080e50b73fc13cb69471750dd62260ef327e.tar.gz
RWA.Support.SessionService-b960080e50b73fc13cb69471750dd62260ef327e.tar.bz2
RWA.Support.SessionService-b960080e50b73fc13cb69471750dd62260ef327e.zip
Move user settings to service and save settings after changing data instead of before
-rw-r--r--rwa/support/sessionservice/config.py6
-rwxr-xr-xrwa/support/sessionservice/service.py27
2 files changed, 16 insertions, 17 deletions
diff --git a/rwa/support/sessionservice/config.py b/rwa/support/sessionservice/config.py
index de5518d..f334e81 100644
--- a/rwa/support/sessionservice/config.py
+++ b/rwa/support/sessionservice/config.py
@@ -22,9 +22,3 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-import usersettings
-
-user_settings = usersettings.Settings("org.ArcticaProject.RWASupportSessionService")
-user_settings.add_setting("web_app_hosts", list, ["http://127.0.0.1:8000"])
-user_settings.load_settings()
diff --git a/rwa/support/sessionservice/service.py b/rwa/support/sessionservice/service.py
index 23fd660..d205056 100755
--- a/rwa/support/sessionservice/service.py
+++ b/rwa/support/sessionservice/service.py
@@ -35,10 +35,10 @@ import click
import dbus
import dbus.mainloop.glib
import dbus.service
+import usersettings
import validators
from gi.repository import GLib
-from .config import user_settings
from .lock import is_locked, lock, unlock
from .log import logging
from .session import Session
@@ -74,6 +74,11 @@ class RWASupportSessionService(dbus.service.Object):
self.update_service_running = False
self.sessions = {}
+
+ self.settings = usersettings.Settings("org.ArcticaProject.RWASupportSessionService")
+ self.settings.add_setting("web_app_hosts", list, ["http://127.0.0.1:8000"])
+ self.settings.load_settings()
+
super().__init__(name, "/RWASupportSessionService")
logging.info("D-Bus service has been started.")
@@ -93,7 +98,7 @@ class RWASupportSessionService(dbus.service.Object):
Helper function: No D-Bus API.
"""
- hosts = user_settings.web_app_hosts
+ hosts = self.settings.web_app_hosts
return json.dumps(hosts)
@dbus.service.method("org.ArcticaProject.RWASupportSessionService", out_signature="s")
@@ -133,8 +138,8 @@ class RWASupportSessionService(dbus.service.Object):
logging.info('D-Bus method call: %s("%s")', "add_web_app_host", host)
if self._is_url(host):
- user_settings.save_settings()
- user_settings.web_app_hosts.append(host)
+ self.settings.save_settings()
+ self.settings.web_app_hosts.append(host)
logging.debug('Added "%s" to "web_app_hosts" in user_settings', host)
else:
logging.warning("Given URL is not valid!")
@@ -158,15 +163,15 @@ class RWASupportSessionService(dbus.service.Object):
"""
logging.info("D-Bus method call: %s(%d)", "remove_web_app_host", host_idx)
- if host_idx >= 0 and host_idx < len(user_settings.web_app_hosts):
- host = user_settings.web_app_hosts[host_idx]
- del user_settings.web_app_hosts[host_idx]
- user_settings.save_settings()
- logging.debug('Removed web_app_hosts[%d]="%s" in user_settings', host_idx, host)
+ if host_idx >= 0 and host_idx < len(self.settings.web_app_hosts):
+ host = self.settings.web_app_hosts[host_idx]
+ del self.settings.web_app_hosts[host_idx]
+ self.settings.save_settings()
+ logging.debug('Removed web_app_hosts[%d]="%s" in user settings', host_idx, host)
else:
logging.warning("Given host index is not valid!")
logging.debug(
- "Did not remove web_app_hosts[%d] (not existent!) in " "user_settings", host_idx
+ "Did not remove web_app_hosts[%d] (not existent!) in " "user settings", host_idx
)
return self._get_web_app_hosts()
@@ -209,7 +214,7 @@ class RWASupportSessionService(dbus.service.Object):
return response
try:
- host = user_settings.web_app_hosts[host_idx]
+ host = self.settings.web_app_hosts[host_idx]
logging.debug('web_app_hosts[%d] is the following host: "%s"', host_idx, host)
except IndexError:
logging.error("web_app_hosts[%d] does not exist!", host_idx)