Always write config files to disk on first start.
This commit is contained in:
parent
1c919967bb
commit
9b1729c77e
@ -24,6 +24,7 @@ OrderedDict. This is because we read them from a file at start and write them
|
|||||||
to a file on shutdown, so it makes sense to keep them as strings here.
|
to a file on shutdown, so it makes sense to keep them as strings here.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os.path
|
||||||
import functools
|
import functools
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
@ -61,8 +62,10 @@ class QuickmarkManager(QObject):
|
|||||||
message.error(0, "Invalid quickmark '{}'".format(line))
|
message.error(0, "Invalid quickmark '{}'".format(line))
|
||||||
else:
|
else:
|
||||||
self.marks[key] = url
|
self.marks[key] = url
|
||||||
|
filename = os.path.join(confdir, 'quickmarks')
|
||||||
objreg.get('save-manager').add_saveable('quickmark-manager', self.save,
|
objreg.get('save-manager').add_saveable('quickmark-manager', self.save,
|
||||||
self.changed)
|
self.changed,
|
||||||
|
filename=filename)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
"""Save the quickmarks to disk."""
|
"""Save the quickmarks to disk."""
|
||||||
|
@ -140,9 +140,11 @@ def init(args):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
objreg.register('config', config_obj)
|
objreg.register('config', config_obj)
|
||||||
|
filename = os.path.join(confdir, 'qutebrowser.conf')
|
||||||
save_manager.add_saveable('config', config_obj.save,
|
save_manager.add_saveable('config', config_obj.save,
|
||||||
config_obj.changed,
|
config_obj.changed,
|
||||||
config_opt=('general', 'auto-save-config'))
|
config_opt=('general', 'auto-save-config'),
|
||||||
|
filename=filename)
|
||||||
try:
|
try:
|
||||||
key_config = keyconf.KeyConfigParser(confdir, 'keys.conf')
|
key_config = keyconf.KeyConfigParser(confdir, 'keys.conf')
|
||||||
except (keyconf.KeyConfigError, UnicodeDecodeError) as e:
|
except (keyconf.KeyConfigError, UnicodeDecodeError) as e:
|
||||||
@ -158,9 +160,11 @@ def init(args):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
objreg.register('key-config', key_config)
|
objreg.register('key-config', key_config)
|
||||||
|
filename = os.path.join(confdir, 'keys.conf')
|
||||||
save_manager.add_saveable('key-config', key_config.save,
|
save_manager.add_saveable('key-config', key_config.save,
|
||||||
key_config.changed,
|
key_config.changed,
|
||||||
config_opt=('general', 'auto-save-config'))
|
config_opt=('general', 'auto-save-config'),
|
||||||
|
filename=filename)
|
||||||
|
|
||||||
datadir = standarddir.get(QStandardPaths.DataLocation, args)
|
datadir = standarddir.get(QStandardPaths.DataLocation, args)
|
||||||
state_config = ini.ReadWriteConfigParser(datadir, 'state')
|
state_config = ini.ReadWriteConfigParser(datadir, 'state')
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
"""Saving things to disk periodically."""
|
"""Saving things to disk periodically."""
|
||||||
|
|
||||||
|
import os.path
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSlot, QObject, QTimer
|
from PyQt5.QtCore import pyqtSlot, QObject, QTimer
|
||||||
@ -39,9 +40,11 @@ class Saveable:
|
|||||||
_save_on_exit: Whether to always save this saveable on exit.
|
_save_on_exit: Whether to always save this saveable on exit.
|
||||||
_config_opt: A (section, option) tuple of a config option which decides
|
_config_opt: A (section, option) tuple of a config option which decides
|
||||||
whether to autosave or not. None if no such option exists.
|
whether to autosave or not. None if no such option exists.
|
||||||
|
_filename: The filename of the underlying file.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, name, save_handler, changed=None, config_opt=None):
|
def __init__(self, name, save_handler, changed=None, config_opt=None,
|
||||||
|
filename=None):
|
||||||
self._name = name
|
self._name = name
|
||||||
self._dirty = False
|
self._dirty = False
|
||||||
self._save_handler = save_handler
|
self._save_handler = save_handler
|
||||||
@ -51,12 +54,17 @@ class Saveable:
|
|||||||
self._save_on_exit = False
|
self._save_on_exit = False
|
||||||
else:
|
else:
|
||||||
self._save_on_exit = True
|
self._save_on_exit = True
|
||||||
|
self._filename = filename
|
||||||
|
if filename is not None and not os.path.exists(filename):
|
||||||
|
self._dirty = True
|
||||||
|
self.save()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return utils.get_repr(self, name=self._name, dirty=self._dirty,
|
return utils.get_repr(self, name=self._name, dirty=self._dirty,
|
||||||
save_handler=self._save_handler,
|
save_handler=self._save_handler,
|
||||||
config_opt=self._config_opt,
|
config_opt=self._config_opt,
|
||||||
save_on_exit=self._save_on_exit)
|
save_on_exit=self._save_on_exit,
|
||||||
|
filename=self._filename)
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def mark_dirty(self):
|
def mark_dirty(self):
|
||||||
@ -128,7 +136,8 @@ class SaveManager(QObject):
|
|||||||
self._save_timer.setInterval(interval)
|
self._save_timer.setInterval(interval)
|
||||||
self._save_timer.start()
|
self._save_timer.start()
|
||||||
|
|
||||||
def add_saveable(self, name, save, changed=None, config_opt=None):
|
def add_saveable(self, name, save, changed=None, config_opt=None,
|
||||||
|
filename=None):
|
||||||
"""Add a new saveable.
|
"""Add a new saveable.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -136,11 +145,14 @@ class SaveManager(QObject):
|
|||||||
save: The function to call to save this saveable.
|
save: The function to call to save this saveable.
|
||||||
changed: The signal emitted when this saveable changed.
|
changed: The signal emitted when this saveable changed.
|
||||||
config_opt: A (section, option) tuple deciding whether to autosave
|
config_opt: A (section, option) tuple deciding whether to autosave
|
||||||
or not.
|
or not.
|
||||||
|
filename: The filename of the underlying file, so we can force
|
||||||
|
saving if it doesn't exist.
|
||||||
"""
|
"""
|
||||||
if name in self.saveables:
|
if name in self.saveables:
|
||||||
raise ValueError("Saveable {} already registered!".format(name))
|
raise ValueError("Saveable {} already registered!".format(name))
|
||||||
self.saveables[name] = Saveable(name, save, changed, config_opt)
|
self.saveables[name] = Saveable(name, save, changed, config_opt,
|
||||||
|
filename)
|
||||||
|
|
||||||
def save(self, name, is_exit=False, explicit=False, silent=False):
|
def save(self, name, is_exit=False, explicit=False, silent=False):
|
||||||
"""Save a saveable by name.
|
"""Save a saveable by name.
|
||||||
|
Loading…
Reference in New Issue
Block a user