2019-07-08 13:52:41 +10:00
|
|
|
// Copyright 2019 miruka
|
|
|
|
// This file is part of harmonyqml, licensed under LGPLv3.
|
|
|
|
|
2019-07-13 19:39:01 +10:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.12
|
2019-06-27 16:31:03 +10:00
|
|
|
import io.thp.pyotherside 1.5
|
|
|
|
import "EventHandlers/includes.js" as EventHandlers
|
|
|
|
|
|
|
|
Python {
|
|
|
|
id: py
|
|
|
|
|
2019-06-29 08:12:45 +10:00
|
|
|
property bool ready: false
|
2019-06-27 16:31:03 +10:00
|
|
|
property var pendingCoroutines: ({})
|
|
|
|
|
2019-07-03 03:59:52 +10:00
|
|
|
signal willLoadAccounts(bool will)
|
2019-06-29 08:12:45 +10:00
|
|
|
property bool loadingAccounts: false
|
|
|
|
|
2019-07-18 17:35:30 +10:00
|
|
|
function callSync(name, args=[]) {
|
2019-07-04 14:24:21 +10:00
|
|
|
return call_sync("APP.backend." + name, args)
|
|
|
|
}
|
|
|
|
|
2019-07-18 17:35:30 +10:00
|
|
|
function callCoro(name, args=[], callback=null) {
|
2019-07-18 19:18:13 +10:00
|
|
|
let uuid = Math.random() + "." + name
|
2019-07-07 15:37:13 +10:00
|
|
|
|
|
|
|
pendingCoroutines[uuid] = callback || function() {}
|
2019-07-08 13:38:37 +10:00
|
|
|
call("APP.call_backend_coro", [name, uuid, args])
|
2019-06-27 16:31:03 +10:00
|
|
|
}
|
|
|
|
|
2019-07-18 18:46:37 +10:00
|
|
|
function callClientCoro(accountId, name, args=[], callback=null) {
|
2019-07-18 19:18:13 +10:00
|
|
|
let uuid = Math.random() + "." + name
|
2019-06-29 08:12:45 +10:00
|
|
|
|
2019-07-07 15:37:13 +10:00
|
|
|
pendingCoroutines[uuid] = callback || function() {}
|
2019-07-18 18:46:37 +10:00
|
|
|
call("APP.call_client_coro", [accountId, name, uuid, args])
|
2019-06-29 08:12:45 +10:00
|
|
|
}
|
|
|
|
|
2019-07-21 21:14:16 +10:00
|
|
|
function saveConfig(backend_attribute, data, callback=null) {
|
2019-07-19 11:58:21 +10:00
|
|
|
if (! py.ready) { return } // config not loaded yet
|
2019-07-21 21:14:16 +10:00
|
|
|
callCoro(backend_attribute + ".write", [data], callback)
|
2019-07-19 11:58:21 +10:00
|
|
|
}
|
|
|
|
|
2019-06-27 16:31:03 +10:00
|
|
|
Component.onCompleted: {
|
|
|
|
for (var func in EventHandlers) {
|
|
|
|
if (EventHandlers.hasOwnProperty(func)) {
|
|
|
|
setHandler(func.replace(/^on/, ""), EventHandlers[func])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-03 03:59:52 +10:00
|
|
|
addImportPath("src")
|
|
|
|
addImportPath("qrc:/")
|
2019-07-18 17:13:34 +10:00
|
|
|
importNames("python", ["APP"], () => {
|
|
|
|
call("APP.is_debug_on", [Qt.application.arguments], on => {
|
2019-07-03 03:59:52 +10:00
|
|
|
window.debug = on
|
2019-06-27 16:31:03 +10:00
|
|
|
|
2019-07-21 21:14:16 +10:00
|
|
|
callCoro("load_settings", [], ([settings, uiState]) => {
|
2019-07-19 11:58:21 +10:00
|
|
|
window.settings = settings
|
2019-07-21 21:14:16 +10:00
|
|
|
window.uiState = uiState
|
2019-07-19 11:58:21 +10:00
|
|
|
|
|
|
|
callCoro("saved_accounts.any_saved", [], any => {
|
|
|
|
py.ready = true
|
|
|
|
willLoadAccounts(any)
|
2019-06-29 08:12:45 +10:00
|
|
|
|
2019-07-19 11:58:21 +10:00
|
|
|
if (any) {
|
|
|
|
py.loadingAccounts = true
|
|
|
|
py.callCoro("load_saved_accounts", [], () => {
|
|
|
|
py.loadingAccounts = false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2019-06-27 16:31:03 +10:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|