Browse Source

Merge branch '15-settings-manager-to-load-and-write-to-settings-json' into 'master'

Resolve "settings manager to load and write to settings.json"

Closes #15

See merge request troebs/pycs!26
Eric Tröbs 4 years ago
parent
commit
00e53aea46
1 changed files with 8 additions and 1 deletions
  1. 8 1
      pycs/ApplicationStatus.py

+ 8 - 1
pycs/ApplicationStatus.py

@@ -1,4 +1,4 @@
-from json import load
+from json import load, dump
 from os.path import exists
 
 from pycs.observable import ObservableDict
@@ -24,3 +24,10 @@ class ApplicationStatus(ObservableDict):
             'projects': [],
             'jobs': []
         })
+
+        # subscribe to settings change to write it to file
+        self['settings'].subscribe(self.__write_settings_to_file)
+
+    def __write_settings_to_file(self, settings):
+        with open(self.__path_to_settings_json, 'w') as settings_json:
+            dump(settings, settings_json, indent=4)