moment/src/qml/event_handlers.js
miruka 5894481dc5 Python exceptions can now be handled via QML
callCoro/callBackendCoro can now take onSuccess(result) and
onError(type, args, errorObject) callbacks.
2019-10-28 06:26:02 -04:00

44 lines
1.0 KiB
JavaScript

"use strict"
function onExitRequested(exitCode) {
Qt.exit(exitCode)
}
function onAlertRequested() {
if (Qt.application.state != Qt.ApplicationActive) {
window.alert(window.settings.alertOnMessageForMsec)
}
}
function onCoroutineDone(uuid, result, error) {
let onSuccess = py.pendingCoroutines[uuid].onSuccess
let onError = py.pendingCoroutines[uuid].onError
if (error) {
let type = py.getattr(py.getattr(error, "__class__"), "__name__")
let args = py.getattr(error, "args")
onError ?
onError(type, args, error) :
console.error(uuid + ": " + type + ": " + args)
} else if (onSuccess) { onSuccess(result) }
delete pendingCoroutines[uuid]
}
function onModelUpdated(syncId, data, serializedSyncId) {
if (serializedSyncId == ["Account"] || serializedSyncId[0] == "Room") {
py.callCoro("get_flat_sidepane_data", [], data => {
window.sidePaneModelSource = data
})
}
window.modelSources[serializedSyncId] = data
window.modelSourcesChanged()
}