From 87b014886529659aabda77c70121bc60a7ce76e0 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Tue, 21 Mar 2017 18:33:33 -0500 Subject: [PATCH] Ui changes --- build_debug_x64.cmd | 2 +- build_release_x64.cmd | 2 +- htdocs/js/index.js | 12 +++---- include/siadrive/siadriveapp.h | 2 ++ run_debug.cmd | 4 +-- run_release.cmd | 4 +-- src/siadrive/siadriveapp.cpp | 57 +++++++++++++--------------------- 7 files changed, 34 insertions(+), 49 deletions(-) diff --git a/build_debug_x64.cmd b/build_debug_x64.cmd index aa6e0eb..6954b11 100644 --- a/build_debug_x64.cmd +++ b/build_debug_x64.cmd @@ -3,7 +3,7 @@ set ROOT=%~dp0% pushd "%ROOT%" set CUR_PATH=%PATH% -call 3rd_party\CEF\create_debug.cmd +REM call 3rd_party\CEF\create_debug.cmd set PATH=%CUR_PATH% mkdir build diff --git a/build_release_x64.cmd b/build_release_x64.cmd index 8f2c905..976583a 100644 --- a/build_release_x64.cmd +++ b/build_release_x64.cmd @@ -3,7 +3,7 @@ set ROOT=%~dp0% pushd "%ROOT%" set CUR_PATH=%PATH% -call 3rd_party\CEF\create_release.cmd +REM call 3rd_party\CEF\create_release.cmd set PATH=%CUR_PATH% mkdir build diff --git a/htdocs/js/index.js b/htdocs/js/index.js index fdb47ff..57629b4 100644 --- a/htdocs/js/index.js +++ b/htdocs/js/index.js @@ -59,6 +59,9 @@ Wallet: _wallet, setBlockHeight: (height) => { setInnerText('ID_BlockHeight', height); + }, + setServerVersion: (version) => { + setInnerText('ID_ServerVersion', version); } }; })(); @@ -81,16 +84,11 @@ return window.uiState.isWalletLocked; } - function _serverVersion() { - return window.uiState.serverVersion; - } - return { clientVersion: _clientVersion, isOnline: _isOnline, isWalletConfigured: _isWalletConfigured, - isWalletLocked: _isWalletLocked, - serverVersion: _serverVersion + isWalletLocked: _isWalletLocked }; })(); @@ -202,7 +200,7 @@ console.log('Main window load'); AppActions.stopApp(); document.getElementById('ID_SiaDrive').innerText = 'SiaDrive ' + UiState.clientVersion(); - document.getElementById('ID_ServerVersion').innerText = UiState.serverVersion(); + document.getElementById('ID_ServerVersion').innerText = '...'; if (UiState.isOnline()) { if (UiState.isWalletConfigured()) { if (UiState.isWalletLocked()) { diff --git a/include/siadrive/siadriveapp.h b/include/siadrive/siadriveapp.h index fdf7d6f..5753725 100644 --- a/include/siadrive/siadriveapp.h +++ b/include/siadrive/siadriveapp.h @@ -27,6 +27,7 @@ private: std::unique_ptr _siaCurl; std::unique_ptr _siaDriveConfig; bool _appStarted = false; + SString _walletReceiveAddress; public: // CefApp methods: @@ -46,6 +47,7 @@ public: virtual void OnContextReleased(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) OVERRIDE; private: + static void ExecuteSetter(CefRefPtr context, CefRefPtr obj, const SString& method, const SString& value); void SiaApiRefreshCallback(CefRefPtr context, const Api::CSiaCurl& siaCurl, Api::CSiaDriveConfig* siaDriveConfig); private: diff --git a/run_debug.cmd b/run_debug.cmd index 36abfb8..6df2502 100644 --- a/run_debug.cmd +++ b/run_debug.cmd @@ -1,5 +1,5 @@ @echo off set ROOT=%~dp0% -set PATH=%ROOT%3rd_party\CEF\chromium_git\chromium\src\out\Debug_GN_x64;%PATH% -start build\debug\Debug\siadrive.exe \ No newline at end of file +pushd "%ROOT%build\debug\dist\" +start siadrive.exe \ No newline at end of file diff --git a/run_release.cmd b/run_release.cmd index 70088f2..b7aaf47 100644 --- a/run_release.cmd +++ b/run_release.cmd @@ -1,5 +1,5 @@ @echo off set ROOT=%~dp0% -set PATH=%ROOT%3rd_party\CEF\chromium_git\chromium\src\out\Release_GN_x64;%PATH% -start build\release\Release\siadrive.exe \ No newline at end of file +pushd "%ROOT%build\release\dist\" +start siadrive.exe \ No newline at end of file diff --git a/src/siadrive/siadriveapp.cpp b/src/siadrive/siadriveapp.cpp index 40bd0f5..e36b38e 100644 --- a/src/siadrive/siadriveapp.cpp +++ b/src/siadrive/siadriveapp.cpp @@ -154,6 +154,14 @@ CSiaDriveApp::CSiaDriveApp() _siaApi.reset(new CSiaApi(hostConfig, _siaDriveConfig.get())); } +void CSiaDriveApp::ExecuteSetter(CefRefPtr context, CefRefPtr obj, const SString& method, const SString& value) +{ + CefRefPtr setConfirmed = obj->GetValue(method.str()); + CefV8ValueList args; + args.push_back(CefV8Value::CreateString(value.str())); + setConfirmed->ExecuteFunctionWithContext(context, nullptr, args); +} + void CSiaDriveApp::OnContextCreated( CefRefPtr browser, CefRefPtr frame, @@ -167,6 +175,7 @@ void CSiaDriveApp::OnContextCreated( obj->SetValue("isWalletConfigured", CefV8Value::CreateBool(_siaApi->GetWallet()->GetCreated()), V8_PROPERTY_ATTRIBUTE_NONE); obj->SetValue("isOnline", CefV8Value::CreateBool(_siaApi->GetWallet()->GetConnected()), V8_PROPERTY_ATTRIBUTE_NONE); obj->SetValue("clientVersion", CefV8Value::CreateString(SIDRIVE_VERSION_STRING), V8_PROPERTY_ATTRIBUTE_NONE); + obj->SetValue("serverVersion", CefV8Value::CreateString("..."), V8_PROPERTY_ATTRIBUTE_NONE); global->SetValue("uiState", obj, V8_PROPERTY_ATTRIBUTE_NONE); CefRefPtr handler(new FunctionHandler(*_siaApi, _appStarted)); @@ -258,54 +267,30 @@ void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr context, const } else if (_appStarted) { - CefRefPtr uiActions = global->GetValue("uiUpdate"); + auto uiActions = global->GetValue("uiUpdate"); + ExecuteSetter(context, uiActions, "setServerVersion", _siaApi->GetServerVersion()); + + auto renterActions = uiActions->GetValue("Renter"); + auto walletActions = uiActions->GetValue("Wallet"); // Display wallet data - CefRefPtr walletActions = uiActions->GetValue("Wallet"); - auto confirmedBalance = _siaApi->GetWallet()->GetConfirmedBalance(); auto unconfirmedBalance = _siaApi->GetWallet()->GetUnconfirmedBalance(); auto totalBalance = confirmedBalance + unconfirmedBalance; + ExecuteSetter(context, walletActions, "setConfirmedBalance", SiaCurrencyToString(confirmedBalance)); + ExecuteSetter(context, walletActions, "setUnconfirmedBalance", SiaCurrencyToString(unconfirmedBalance)); + ExecuteSetter(context, walletActions, "setTotalBalance", SiaCurrencyToString(totalBalance)); + if (_walletReceiveAddress.IsNullOrEmpty()) { - CefRefPtr setConfirmed = walletActions->GetValue("setConfirmedBalance"); - CefV8ValueList args; - args.push_back(CefV8Value::CreateString(SiaCurrencyToString(confirmedBalance).str())); - CefRefPtr retval; - setConfirmed->ExecuteFunctionWithContext(context, nullptr, args); - } - - { - CefRefPtr setUnconfirmed = walletActions->GetValue("setUnconfirmedBalance"); - CefV8ValueList args; - args.push_back(CefV8Value::CreateString(SiaCurrencyToString(unconfirmedBalance).str())); - setUnconfirmed->ExecuteFunctionWithContext(context, nullptr, args); - } - - { - CefRefPtr setTotalBal = walletActions->GetValue("setTotalBalance"); - CefV8ValueList args; - args.push_back(CefV8Value::CreateString(SiaCurrencyToString(totalBalance).str())); - setTotalBal->ExecuteFunctionWithContext(context, nullptr, args); - } - - { - CefRefPtr setReceiveAddress = walletActions->GetValue("setReceiveAddress"); - CefV8ValueList args; - args.push_back(CefV8Value::CreateString(_siaApi->GetWallet()->GetReceiveAddress().str())); - setReceiveAddress->ExecuteFunctionWithContext(context, nullptr, args); + _walletReceiveAddress = _siaApi->GetWallet()->GetReceiveAddress(); + ExecuteSetter(context, walletActions, "setReceiveAddress", _walletReceiveAddress); } // Display renter data - auto renterActions = uiActions->GetValue("Renter"); // Display block height - { - auto setBlockHeight = uiActions->GetValue("setBlockHeight"); - CefV8ValueList args; - args.push_back(CefV8Value::CreateString(SString::FromUInt64(_siaApi->GetConsensus()->GetHeight()).str())); - setBlockHeight->ExecuteFunctionWithContext(context, nullptr, args); - } + ExecuteSetter(context, uiActions, "setBlockHeight", SString::FromUInt64(_siaApi->GetConsensus()->GetHeight())); } context->Exit(); }