PythonBridge: minor code improvements
This commit is contained in:
parent
7d2b85dfda
commit
606e8a25df
|
@ -21,13 +21,11 @@ Python {
|
||||||
py.call(py.getattr(obj, "__setattr__"), [attr, value], callback)
|
py.call(py.getattr(obj, "__setattr__"), [attr, value], callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function callCoro(name, args=[], onSuccess=null, onError=null) {
|
function callCoro(name, args=[], onSuccess=null, onError=null) {
|
||||||
let uuid = name + "." + CppUtils.uuid()
|
const uuid = name + "." + CppUtils.uuid()
|
||||||
|
const future = privates.makeFuture()
|
||||||
|
|
||||||
Globals.pendingCoroutines[uuid] = {onSuccess, onError}
|
Globals.pendingCoroutines[uuid] = {future, onSuccess, onError}
|
||||||
|
|
||||||
let future = privates.makeFuture()
|
|
||||||
|
|
||||||
call("BRIDGE.call_backend_coro", [name, uuid, args], pyFuture => {
|
call("BRIDGE.call_backend_coro", [name, uuid, args], pyFuture => {
|
||||||
future.privates.pythonFuture = pyFuture
|
future.privates.pythonFuture = pyFuture
|
||||||
|
@ -36,18 +34,17 @@ Python {
|
||||||
return future
|
return future
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function callClientCoro(
|
function callClientCoro(
|
||||||
accountId, name, args=[], onSuccess=null, onError=null
|
accountId, name, args=[], onSuccess=null, onError=null
|
||||||
) {
|
) {
|
||||||
let future = privates.makeFuture()
|
const future = privates.makeFuture()
|
||||||
|
|
||||||
callCoro("get_client", [accountId], () => {
|
callCoro("get_client", [accountId], () => {
|
||||||
let uuid = accountId + "." + name + "." + CppUtils.uuid()
|
const uuid = accountId + "." + name + "." + CppUtils.uuid()
|
||||||
|
|
||||||
Globals.pendingCoroutines[uuid] = {onSuccess, onError}
|
Globals.pendingCoroutines[uuid] = {onSuccess, onError}
|
||||||
|
|
||||||
let call_args = [accountId, name, uuid, args]
|
const call_args = [accountId, name, uuid, args]
|
||||||
|
|
||||||
call("BRIDGE.call_client_coro", call_args, pyFuture => {
|
call("BRIDGE.call_client_coro", call_args, pyFuture => {
|
||||||
future.privates.pythonFuture = pyFuture
|
future.privates.pythonFuture = pyFuture
|
||||||
|
@ -57,15 +54,13 @@ Python {
|
||||||
return future
|
return future
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function saveConfig(backend_attribute, data, callback=null) {
|
function saveConfig(backend_attribute, data, callback=null) {
|
||||||
if (! py.ready) { return } // config not loaded yet
|
if (! py.ready) { return } // config not loaded yet
|
||||||
return callCoro(backend_attribute + ".write", [data], callback)
|
return callCoro(backend_attribute + ".write", [data], callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function loadSettings(callback=null) {
|
function loadSettings(callback=null) {
|
||||||
let func = "load_settings"
|
const func = "load_settings"
|
||||||
|
|
||||||
return callCoro(func, [], ([settings, uiState, history, theme]) => {
|
return callCoro(func, [], ([settings, uiState, history, theme]) => {
|
||||||
window.settings = settings
|
window.settings = settings
|
||||||
|
|
Loading…
Reference in New Issue
Block a user