Refactor user_files module & add live reloading

- Cleaner design for the backend user_files classes and simplified
  interaction with QML
- Config and theme files will now automatically reload when changed on
  disk
- Removed manual reload keybind and button
This commit is contained in:
miruka
2020-10-05 03:06:07 -04:00
parent 00c468384a
commit 75fbf23b21
13 changed files with 249 additions and 230 deletions

View File

@@ -65,6 +65,19 @@ QtObject {
py.showError(type, traceback, "", message)
}
function onUserFileChanged(type, newData) {
if (type === "Theme") {
window.theme = Qt.createQmlObject(newData, window, "theme")
utils.theme = window.theme
return
}
type === "Settings" ? window.settings = newData :
type === "UIState" ? window.uiState = newData :
type === "History" ? window.history = newData :
null
}
function onModelItemSet(syncId, indexThen, indexNow, changedFields) {
const model = ModelStore.get(syncId)

View File

@@ -47,23 +47,9 @@ Python {
call("BRIDGE.cancel_coro", [uuid])
}
function saveConfig(backend_attribute, data, callback=null) {
if (! py.ready) { return } // config not loaded yet
return callCoro(backend_attribute + ".write", [data], callback)
}
function loadSettings(callback=null) {
const func = "load_settings"
return callCoro(func, [], ([settings, uiState, history, theme]) => {
window.settings = settings
window.uiState = uiState
window.history = history
window.theme = Qt.createQmlObject(theme, window, "theme")
utils.theme = window.theme
if (callback) { callback(settings, uiState, theme) }
})
function saveConfig(backend_attribute, data) {
if (! py.ready) { return } // config not done loading yet
callCoro(backend_attribute + ".set_data", [data])
}
function showError(type, traceback, sourceIndication="", message="") {

View File

@@ -22,7 +22,13 @@ PythonBridge {
addImportPath("qrc:/src")
importNames("backend.qml_bridge", ["BRIDGE"], () => {
loadSettings(() => {
callCoro("get_settings", [], ([settings, state, hist, theme]) => {
window.settings = settings
window.uiState = state
window.history = hist
window.theme = Qt.createQmlObject(theme, window, "theme")
utils.theme = window.theme
callCoro("saved_accounts.any_saved", [], any => {
if (any) { callCoro("load_saved_accounts", []) }