2019-07-08 13:52:41 +10:00
|
|
|
// Copyright 2019 miruka
|
|
|
|
// This file is part of harmonyqml, licensed under LGPLv3.
|
|
|
|
|
2019-06-27 16:31:03 +10:00
|
|
|
import QtQuick 2.7
|
|
|
|
import QtQuick.Controls 2.2
|
|
|
|
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-04 14:24:21 +10:00
|
|
|
function callSync(name, args) {
|
|
|
|
return call_sync("APP.backend." + name, args)
|
|
|
|
}
|
|
|
|
|
2019-07-08 13:38:37 +10:00
|
|
|
function callCoro(name, args, callback) {
|
2019-07-07 15:37:13 +10:00
|
|
|
var uuid = Math.random() + "." + name
|
|
|
|
|
|
|
|
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-08 13:38:37 +10:00
|
|
|
function callClientCoro(account_id, name, args, callback) {
|
2019-07-07 15:37:13 +10:00
|
|
|
var 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-08 13:38:37 +10:00
|
|
|
call("APP.call_client_coro", [account_id, name, uuid, args])
|
2019-06-29 08:12:45 +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:/")
|
|
|
|
importNames("python", ["APP"], function() {
|
|
|
|
call("APP.is_debug_on", [Qt.application.arguments], function(on) {
|
|
|
|
window.debug = on
|
2019-06-27 16:31:03 +10:00
|
|
|
|
2019-07-08 13:38:37 +10:00
|
|
|
callCoro("has_saved_accounts", [], function(has) {
|
2019-06-29 08:12:45 +10:00
|
|
|
py.ready = true
|
2019-07-03 03:59:52 +10:00
|
|
|
willLoadAccounts(has)
|
2019-06-29 08:12:45 +10:00
|
|
|
|
|
|
|
if (has) {
|
2019-07-03 03:59:52 +10:00
|
|
|
py.loadingAccounts = true
|
2019-07-08 13:38:37 +10:00
|
|
|
py.callCoro("load_saved_accounts", [], function() {
|
2019-07-03 03:59:52 +10:00
|
|
|
py.loadingAccounts = false
|
2019-06-29 08:12:45 +10:00
|
|
|
})
|
|
|
|
}
|
2019-06-27 16:31:03 +10:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|