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:
@@ -40,12 +40,6 @@ Rectangle {
|
||||
py.callCoro("get_theme_dir", [], Qt.openUrlExternally)
|
||||
}
|
||||
|
||||
HMenuItem {
|
||||
icon.name: "reload-config-files"
|
||||
text: qsTr("Reload config & theme")
|
||||
onTriggered: mainUI.reloadSettings()
|
||||
}
|
||||
|
||||
HMenuItem {
|
||||
icon.name: "debug"
|
||||
text: qsTr("Developer console")
|
||||
|
@@ -41,7 +41,7 @@ HFlickableColumnPage {
|
||||
py.callCoro(
|
||||
rememberAccount.checked ?
|
||||
"saved_accounts.add":
|
||||
"saved_accounts.delete",
|
||||
"saved_accounts.forget",
|
||||
|
||||
[receivedUserId]
|
||||
)
|
||||
|
@@ -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)
|
||||
|
||||
|
@@ -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="") {
|
||||
|
@@ -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", []) }
|
||||
|
||||
|
@@ -28,41 +28,18 @@ Item {
|
||||
readonly property alias debugConsole: debugConsole
|
||||
readonly property alias mainPane: mainPane
|
||||
readonly property alias pageLoader: pageLoader
|
||||
readonly property alias pressAnimation: pressAnimation
|
||||
readonly property alias fontMetrics: fontMetrics
|
||||
readonly property alias idleManager: idleManager
|
||||
|
||||
function reloadSettings() {
|
||||
py.loadSettings(() => {
|
||||
image.reload()
|
||||
mainUI.pressAnimation.start()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
focus: true
|
||||
Component.onCompleted: window.mainUI = mainUI
|
||||
|
||||
SequentialAnimation {
|
||||
id: pressAnimation
|
||||
HNumberAnimation {
|
||||
target: mainUI; property: "scale"; from: 1.0; to: 0.9
|
||||
}
|
||||
HNumberAnimation {
|
||||
target: mainUI; property: "scale"; from: 0.9; to: 1.0
|
||||
}
|
||||
}
|
||||
|
||||
HShortcut {
|
||||
sequences: window.settings.keys.startPythonDebugger
|
||||
onActivated: py.call("BRIDGE.pdb")
|
||||
}
|
||||
|
||||
HShortcut {
|
||||
sequences: window.settings.keys.reloadConfig
|
||||
onActivated: reloadSettings()
|
||||
}
|
||||
|
||||
HShortcut {
|
||||
sequences: window.settings.keys.zoomIn
|
||||
onActivated: {
|
||||
|
@@ -88,7 +88,7 @@ ApplicationWindow {
|
||||
|
||||
// NOTE: For JS object variables, the corresponding method to notify
|
||||
// key/value changes must be called manually, e.g. settingsChanged().
|
||||
onSettingsChanged: py.saveConfig("ui_settings", settings)
|
||||
onSettingsChanged: py.saveConfig("settings", settings)
|
||||
onUiStateChanged: py.saveConfig("ui_state", uiState)
|
||||
onHistoryChanged: py.saveConfig("history", history)
|
||||
|
||||
|
Reference in New Issue
Block a user