/* * RetroShare Android QML App * Copyright (C) 2016-2017 Gioacchino Mazzurco * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ import QtQuick 2.2 import QtQuick.Controls 2.0 import org.retroshare.qml_components.LibresapiLocalClient 1.0 import "URI.js" as URI ApplicationWindow { id: mainWindow visible: true title: "RetroShare" width: 400 height: 400 property string pgp_name property var tokens: ({}) function registerToken(token, callback) { if (Array.isArray(tokens[token])) tokens[token].push(callback) else tokens[token] = [callback] } function tokenExpire(token) { if(Array.isArray(tokens[token])) { var arrLen = tokens[token].length for(var i=0; i 1) { stackView.pop(); event.accepted = true; } state: "core_down" initialItem: BusyOverlay { message: qsTr("Connecting to core...") } states: [ State { name: "core_down" PropertyChanges { target: stackView; enabled: false } }, State { name: "waiting_account_select" PropertyChanges { target: stackView; enabled: true } StateChangeScript { script: { console.log("StateChangeScript waiting_account_select") stackView.clear() stackView.push("qrc:/qml/Locations.qml") } } }, State { name: "waiting_startup" PropertyChanges { target: stackView; enabled: false } StateChangeScript { script: { console.log("StateChangeScript waiting_startup") stackView.clear() stackView.push("qrc:/qml/BusyOverlay.qml", { message: "Core initializing..."}) } } }, State { name: "running_ok" PropertyChanges { target: stackView; enabled: true } StateChangeScript { script: { console.log("StateChangeScript running_ok") coreStateCheckTimer.stop() stackView.clear() stackView.push("qrc:/qml/Contacts.qml") } } }, State { name: "running_ok_no_full_control" PropertyChanges { target: stackView; state: "running_ok" } } ] } LibresapiLocalClient { id: refreshTokensApi onResponseReceived: { var jsonData = JSON.parse(msg).data var arrayLength = jsonData.length; for (var i = 0; i < arrayLength; i++) mainWindow.tokenExpire(jsonData[i]) } Component.onCompleted: { if(QT_DEBUG) debug = false openConnection(apiSocketPath) refreshTokensTimer.start() } function refreshTokens() { var ret = request("/statetokenservice/*", '['+Object.keys(mainWindow.tokens)+']') if(ret < 1) stackView.state = "core_down" } } Timer { id: refreshTokensTimer interval: 1500 repeat: true triggeredOnStart: true onTriggered: refreshTokensApi.refreshTokens() } Timer { id: coreStateCheckTimer interval: 1000 repeat: true triggeredOnStart: true onTriggered: { var ret = rsApi.request("/control/runstate/", "", runStateCallback) if ( ret < 1 ) { console.log("checkCoreStatus() core is down") stackView.state = "core_down" } } Component.onCompleted: start() function runStateCallback(par) { var jsonReponse = JSON.parse(par.response) var runState = jsonReponse.data.runstate if(typeof(runState) === 'string') stackView.state = runState else { stackView.state = "core_down" console.log("runStateCallback(...) core is down") } } } }