1
0

Continue UI

This commit is contained in:
Scott E. Graves
2017-03-19 21:35:42 -05:00
parent fff3ac0eb8
commit 1192283ebf
5 changed files with 87 additions and 7 deletions

Submodule 3rd_party/CEF/depot_tools updated: ecf3dbe49f...e86f6de842

View File

@@ -3,11 +3,11 @@
--h2-font-size: 18px; --h2-font-size: 18px;
--h3-font-size: 16px; --h3-font-size: 16px;
--default-font-size: 14px; --default-font-size: 14px;
--h1-color: #70b991; --h1-color: #64aa82;
--app-header-font-size: 25px; --app-header-font-size: 25px;
--default-animation-time: .5s; --default-animation-time: .5s;
--default-font-color: #c2c2c2; --default-font-color: #c2c2c2;
--default-header-color: #a7b6bf; --default-header-color: #a5b3c0;
--default-amount-color: #a5b3c0; --default-amount-color: #a5b3c0;
--default-padding: 0 0 8px 0; --default-padding: 0 0 8px 0;
} }

View File

@@ -10,7 +10,10 @@
<script src="js/index.js"></script> <script src="js/index.js"></script>
</head> </head>
<body> <body>
<div class="padded" id="main_window"></div> <div class="padded" style="padding-bottom: 0;">
<h1 style="font-size: 24px;padding-bottom: 0;">&nbsp;SiaDrive v0.0.1</h1>
</div>
<div class="padded" id="main_window" style="padding-top: 0;"></div>
<div class="hidden-element" id="app_window"> <div class="hidden-element" id="app_window">
<div class="box" id="general_info"> <div class="box" id="general_info">
<h1>Sia Information</h1> <h1>Sia Information</h1>
@@ -128,10 +131,16 @@
<div class="box"> <div class="box">
<h1>Enter Password</h1> <h1>Enter Password</h1>
<p>Enter wallet password and click 'Unlock' to continue.</p> <p>Enter wallet password and click 'Unlock' to continue.</p>
<input type="password" id="ID_WalletUnlockPwd" style="width: inherit"/><br/><br/> <input type="password" id="ID_WalletUnlockPwd" style="width: 100%"/><br/><br/>
<button id="ID_UnlockWalletButton">Unlock</button> <button id="ID_UnlockWalletButton">Unlock</button>
</div> </div>
</div> </div>
<div class="hidden-element" id="unlocking_window">
<div class="box">
<h1>Please Wait</h1>
<p>SiaDrive will refresh once unlocking is complete. This may take several minutes, so please be patient.</p>
</div>
</div>
<div class="hidden-element" id="create_window"> <div class="hidden-element" id="create_window">
<div class="box"> <div class="box">
<h1>Create New Wallet</h1> <h1>Create New Wallet</h1>

View File

@@ -21,6 +21,16 @@
}; };
})(); })();
const UiActions = (() => {
function _unlockWallet(pwd, cb) {
return window.uiActions.unlockWallet(pwd, cb);
}
return {
unlockWallet: _unlockWallet
};
})();
function setMainWindow(name) { function setMainWindow(name) {
console.log('Setting main window: ' + name); console.log('Setting main window: ' + name);
const elem = document.getElementById(name); const elem = document.getElementById(name);
@@ -37,12 +47,34 @@
mainWindow.appendChild(elem); mainWindow.appendChild(elem);
} }
function displayErrorPopup(title, msg, cb) {
if (cb) {
cb();
}
}
window.addEventListener('load', ()=> { window.addEventListener('load', ()=> {
console.log('Main window load'); console.log('Main window load');
if (UiState.isOnline()) { if (UiState.isOnline()) {
if (UiState.isWalletConfigured()) { if (UiState.isWalletConfigured()) {
if (UiState.isWalletLocked()) { if (UiState.isWalletLocked()) {
setMainWindow('unlock_window'); 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 { } else {
setMainWindow('app_window'); setMainWindow('app_window');
} }

View File

@@ -13,14 +13,48 @@
using namespace Sia; using namespace Sia;
using namespace Sia::Api; 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<CefV8Value> object,
const CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& 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 // When using the Views framework this object provides the delegate
// implementation for the CefWindow that hosts the Views-based browser. // implementation for the CefWindow that hosts the Views-based browser.
class SimpleWindowDelegate : class SimpleWindowDelegate :
public CefWindowDelegate public CefWindowDelegate
{ {
public: public:
explicit SimpleWindowDelegate(CefRefPtr<CefBrowserView> browserView) explicit SimpleWindowDelegate(CefRefPtr<CefBrowserView> browserView) :
: _browserView(browserView) _browserView(browserView)
{ {
} }
@@ -78,6 +112,11 @@ void CSiaDriveApp::OnContextCreated(
obj->SetValue("isOnline", CefV8Value::CreateBool(_siaApi->GetWallet()->GetConnected()), V8_PROPERTY_ATTRIBUTE_NONE); obj->SetValue("isOnline", CefV8Value::CreateBool(_siaApi->GetWallet()->GetConnected()), V8_PROPERTY_ATTRIBUTE_NONE);
global->SetValue("uiState", obj, V8_PROPERTY_ATTRIBUTE_NONE); global->SetValue("uiState", obj, V8_PROPERTY_ATTRIBUTE_NONE);
CefRefPtr<FunctionHandler> 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) _refreshThread.reset(new CAutoThread(*_siaCurl, _siaDriveConfig.get(), [this, context](const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig)
{ {
this->SiaApiRefreshCallback(context, siaCurl, siaDriveConfig); this->SiaApiRefreshCallback(context, siaCurl, siaDriveConfig);