diff --git a/TODO.md b/TODO.md index 3b93c531..3fb357e8 100644 --- a/TODO.md +++ b/TODO.md @@ -40,7 +40,6 @@ - Missing room keybinds (invite, etc), and don't put all the binds in one central file (else we can only rely on uiState properties) - Use QML states -- Use a singleton for utils.js - Try gel for the models and stop being lazy in python - Room Sidepane save/load size & keybinds diff --git a/src/qml/EventHandlers.qml b/src/qml/EventHandlers.qml new file mode 100644 index 00000000..08018619 --- /dev/null +++ b/src/qml/EventHandlers.qml @@ -0,0 +1,48 @@ +import QtQuick 2.12 + +QtObject { + function onExitRequested(exitCode) { + Qt.exit(exitCode) + } + + + function onAlertRequested() { + if (Qt.application.state !== Qt.ApplicationActive) { + window.alert(window.settings.alertOnMessageForMsec) + } + } + + + function onCoroutineDone(uuid, result, error, traceback) { + 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") + + type === "CancelledError" ? + console.warn(`python: cancelled: ${uuid}`) : + + onError ? + onError(type, args, error, traceback) : + + console.error(`python: ${uuid}\n${traceback}`) + + } else if (onSuccess) { onSuccess(result) } + + delete pendingCoroutines[uuid] + } + + + function onModelUpdated(syncId, data, serializedSyncId) { + if (serializedSyncId === "Account" || serializedSyncId[0] === "Room") { + py.callCoro("get_flat_mainpane_data", [], data => { + window.mainPaneModelSource = data + }) + } + + window.modelSources[serializedSyncId] = data + window.modelSourcesChanged() + } +} diff --git a/src/qml/Python.qml b/src/qml/Python.qml index 240ec0c0..f68f2ea3 100644 --- a/src/qml/Python.qml +++ b/src/qml/Python.qml @@ -1,6 +1,5 @@ import QtQuick 2.12 import io.thp.pyotherside 1.5 -import "event_handlers.js" as EventHandlers Python { id: py @@ -10,6 +9,8 @@ Python { property bool startupAnyAccountsSaved: false property var pendingCoroutines: ({}) + property EventHandlers eventHandlers: EventHandlers {} + function newQmlFuture() { return { @@ -96,9 +97,9 @@ Python { } Component.onCompleted: { - for (var func in EventHandlers) { - if (EventHandlers.hasOwnProperty(func)) { - setHandler(func.replace(/^on/, ""), EventHandlers[func]) + for (var func in eventHandlers) { + if (eventHandlers.hasOwnProperty(func)) { + setHandler(func.replace(/^on/, ""), eventHandlers[func]) } } diff --git a/src/qml/event_handlers.js b/src/qml/event_handlers.js deleted file mode 100644 index 39a8b61c..00000000 --- a/src/qml/event_handlers.js +++ /dev/null @@ -1,47 +0,0 @@ -"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, traceback) { - 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") - - type === "CancelledError" ? - console.warn(`python: cancelled: ${uuid}`) : - - onError ? - onError(type, args, error, traceback) : - - console.error(`python: ${uuid}\n${traceback}`) - - } else if (onSuccess) { onSuccess(result) } - - delete pendingCoroutines[uuid] -} - - -function onModelUpdated(syncId, data, serializedSyncId) { - if (serializedSyncId === "Account" || serializedSyncId[0] === "Room") { - py.callCoro("get_flat_mainpane_data", [], data => { - window.mainPaneModelSource = data - }) - } - - window.modelSources[serializedSyncId] = data - window.modelSourcesChanged() -}