From 1192283ebf1a83932e0aed9a3359e9233c7b5b57 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sun, 19 Mar 2017 21:35:42 -0500 Subject: [PATCH] Continue UI --- 3rd_party/CEF/depot_tools | 2 +- htdocs/css/general.css | 4 ++-- htdocs/index.html | 13 +++++++++-- htdocs/js/index.js | 32 +++++++++++++++++++++++++++ src/siadrive/siadriveapp.cpp | 43 ++++++++++++++++++++++++++++++++++-- 5 files changed, 87 insertions(+), 7 deletions(-) diff --git a/3rd_party/CEF/depot_tools b/3rd_party/CEF/depot_tools index ecf3dbe..e86f6de 160000 --- a/3rd_party/CEF/depot_tools +++ b/3rd_party/CEF/depot_tools @@ -1 +1 @@ -Subproject commit ecf3dbe49fcf18982c5d8fbfd8a9ed30d6d9e714 +Subproject commit e86f6de84296601c61a3d3e6d7655e596535c4d6 diff --git a/htdocs/css/general.css b/htdocs/css/general.css index d2c3b55..6484331 100644 --- a/htdocs/css/general.css +++ b/htdocs/css/general.css @@ -3,11 +3,11 @@ --h2-font-size: 18px; --h3-font-size: 16px; --default-font-size: 14px; - --h1-color: #70b991; + --h1-color: #64aa82; --app-header-font-size: 25px; --default-animation-time: .5s; --default-font-color: #c2c2c2; - --default-header-color: #a7b6bf; + --default-header-color: #a5b3c0; --default-amount-color: #a5b3c0; --default-padding: 0 0 8px 0; } diff --git a/htdocs/index.html b/htdocs/index.html index 88d5675..2acd6fd 100644 --- a/htdocs/index.html +++ b/htdocs/index.html @@ -10,7 +10,10 @@ -
+
+

 SiaDrive v0.0.1

+
+

Sia Information

@@ -128,10 +131,16 @@

Enter Password

Enter wallet password and click 'Unlock' to continue.

-

+

+
+
+

Please Wait

+

SiaDrive will refresh once unlocking is complete. This may take several minutes, so please be patient.

+
+

Create New Wallet

diff --git a/htdocs/js/index.js b/htdocs/js/index.js index 9ebb53c..9a9abf5 100644 --- a/htdocs/js/index.js +++ b/htdocs/js/index.js @@ -21,6 +21,16 @@ }; })(); + const UiActions = (() => { + function _unlockWallet(pwd, cb) { + return window.uiActions.unlockWallet(pwd, cb); + } + + return { + unlockWallet: _unlockWallet + }; + })(); + function setMainWindow(name) { console.log('Setting main window: ' + name); const elem = document.getElementById(name); @@ -37,12 +47,34 @@ mainWindow.appendChild(elem); } + function displayErrorPopup(title, msg, cb) { + if (cb) { + cb(); + } + } + window.addEventListener('load', ()=> { console.log('Main window load'); if (UiState.isOnline()) { if (UiState.isWalletConfigured()) { if (UiState.isWalletLocked()) { setMainWindow('unlock_window'); + const unlockButton = document.getElementById('ID_UnlockWalletButton'); + unlockButton.onclick = ()=> { + const password = document.getElementById('ID_WalletUnlockPwd'); + if (UiActions.unlockWallet(password.value, (success, reason) => { + password.value = ''; + if (success) { + setMainWindow('app_window'); + } else { + displayErrorPopup('Failed to unlock wallet', reason, ()=> { + window.reload(); + }); + } + })) { + setMainWindow('unlocking_window'); + } + }; } else { setMainWindow('app_window'); } diff --git a/src/siadrive/siadriveapp.cpp b/src/siadrive/siadriveapp.cpp index 7bdbdfa..31b0287 100644 --- a/src/siadrive/siadriveapp.cpp +++ b/src/siadrive/siadriveapp.cpp @@ -13,14 +13,48 @@ using namespace Sia; using namespace Sia::Api; +class FunctionHandler : + public CefV8Handler +{ +public: + FunctionHandler(const CSiaApi& siaApi) : + _siaApi(siaApi) + { + } + +private: + const CSiaApi& _siaApi; + +public: + virtual bool Execute(const CefString& name, + CefRefPtr object, + const CefV8ValueList& arguments, + CefRefPtr& retval, + CefString& exception) OVERRIDE + { + if (name == "unlockWallet") + { + retval = CefV8Value::CreateBool(true); + + return true; + } + + // Function does not exist. + return false; + } + + // Provide the reference counting implementation for this class. + IMPLEMENT_REFCOUNTING(FunctionHandler); +}; + // When using the Views framework this object provides the delegate // implementation for the CefWindow that hosts the Views-based browser. class SimpleWindowDelegate : public CefWindowDelegate { public: - explicit SimpleWindowDelegate(CefRefPtr browserView) - : _browserView(browserView) + explicit SimpleWindowDelegate(CefRefPtr browserView) : + _browserView(browserView) { } @@ -78,6 +112,11 @@ void CSiaDriveApp::OnContextCreated( obj->SetValue("isOnline", CefV8Value::CreateBool(_siaApi->GetWallet()->GetConnected()), V8_PROPERTY_ATTRIBUTE_NONE); global->SetValue("uiState", obj, V8_PROPERTY_ATTRIBUTE_NONE); + CefRefPtr handler(new FunctionHandler(*_siaApi)); + obj = CefV8Value::CreateObject(nullptr, nullptr); + obj->SetValue("unlockWallet", CefV8Value::CreateFunction("unlockWallet", handler), V8_PROPERTY_ATTRIBUTE_NONE); + global->SetValue("uiActions", obj, V8_PROPERTY_ATTRIBUTE_NONE); + _refreshThread.reset(new CAutoThread(*_siaCurl, _siaDriveConfig.get(), [this, context](const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig) { this->SiaApiRefreshCallback(context, siaCurl, siaDriveConfig);