mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Only write to gui.json once during shutdown
This commit is contained in:
parent
382248eff1
commit
cf06ad7e67
@ -702,6 +702,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
||||
self.read_layout_settings()
|
||||
|
||||
def write_settings(self):
|
||||
with gprefs: # Only write to gprefs once
|
||||
config.set('main_window_geometry', self.saveGeometry())
|
||||
dynamic.set('sort_history', self.library_view.model().sort_history)
|
||||
self.save_layout_state()
|
||||
|
@ -240,6 +240,7 @@ class XMLConfig(dict):
|
||||
|
||||
def __init__(self, rel_path_to_cf_file):
|
||||
dict.__init__(self)
|
||||
self.no_commit = False
|
||||
self.defaults = {}
|
||||
self.file_path = os.path.join(config_dir,
|
||||
*(rel_path_to_cf_file.split('/')))
|
||||
@ -304,6 +305,7 @@ class XMLConfig(dict):
|
||||
self.commit()
|
||||
|
||||
def commit(self):
|
||||
if self.no_commit: return
|
||||
if hasattr(self, 'file_path') and self.file_path:
|
||||
dpath = os.path.dirname(self.file_path)
|
||||
if not os.path.exists(dpath):
|
||||
@ -314,6 +316,13 @@ class XMLConfig(dict):
|
||||
f.truncate()
|
||||
f.write(raw)
|
||||
|
||||
def __enter__(self):
|
||||
self.no_commit = True
|
||||
|
||||
def __exit__(self, *args):
|
||||
self.no_commit = False
|
||||
self.commit()
|
||||
|
||||
def to_json(obj):
|
||||
if isinstance(obj, bytearray):
|
||||
return {'__class__': 'bytearray',
|
||||
|
Loading…
x
Reference in New Issue
Block a user