1
0

Startup changes

This commit is contained in:
Scott E. Graves
2017-04-29 20:21:46 -05:00
parent 7c0144f308
commit 4226095bd7
5 changed files with 137 additions and 126 deletions

View File

@@ -138,8 +138,13 @@
</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>
<h1>Unlocking Wallet</h1>
<p>This may take several minutes, so please be patient.</p>
</div>
<div class="box" style="padding: 0; margin-bottom: 0;">
<div class="fill">
<img style="opacity: 0.35; max-width: 181px; max-height: 103px; border-radius: 10px; display: inline-block; margin: auto auto;" src="./images/startup.gif">
</div>
</div>
</div>
<div class="hidden-element" id="create_window">
@@ -151,7 +156,7 @@
</div>
<div class="hidden-element" id="offline_window">
<div class="box">
<h1>Offline</h1>
<h1>Connecting</h1>
<p>Waiting to establish connection to Sia...</p>
</div>
<div class="box" style="padding: 0; margin-bottom: 0;">

View File

@@ -243,14 +243,6 @@
return window.appActions.mountDrive(mountLocation, cb);
}
function _startApp() {
window.appActions.startApp();
}
function _stopApp() {
window.appActions.stopApp();
}
function _unlockWallet(pwd, cb) {
return window.appActions.unlockWallet(pwd, cb);
}
@@ -279,8 +271,6 @@
return {
createWallet: _createWallet,
mountDrive: _mountDrive,
startApp: _startApp,
stopApp: _stopApp,
unlockWallet: _unlockWallet,
unmountDrive: _unmountDrive,
shutdown: _shutdown,
@@ -370,7 +360,6 @@
}
function beginMainApplication() {
AppActions.startApp();
setMainWindow('app_window');
const settingsEditLink = document.getElementById('ID_Sia_Settings_Edit');
settingsEditLink.onclick = () => {
@@ -529,7 +518,6 @@
}
function reloadApplication() {
AppActions.stopApp();
document.getElementById('ID_SiaDrive').innerText = 'SiaDrive ' + UiState.clientVersion();
document.getElementById('ID_ServerVersion').innerText = '...';
if (UiState.isOnline()) {

View File

@@ -1,5 +1,12 @@
@echo off
set ROOT=%~dp0%
pushd "%ROOT%dist\Debug"
start siadrive.exe
pushd "%ROOT%"
call build_debug_x64.cmd
pushd "%ROOT%dist\Debug"
start siadrive.exe
popd
popd

View File

@@ -1,5 +1,12 @@
@echo off
set ROOT=%~dp0%
pushd "%ROOT%dist\Release"
start siadrive.exe
pushd "%ROOT%"
call build_release_x64.cmd
pushd "%ROOT%dist\Release"
start siadrive.exe
popd
popd

View File

@@ -69,6 +69,7 @@ private:
{
args.push_back(CefV8Value::CreateString("Failed to unlock wallet"));
}
_refreshCallback(context);
cb->ExecuteFunctionWithContext(context, nullptr, args);
}
@@ -122,7 +123,15 @@ public:
// Don't hang UI while unlocking
std::thread([this, context, password, cb]()
{
CefPostTask(TID_RENDERER, base::Bind(&FunctionHandler::UnlockCallback, this, _siaApi.GetWallet()->Unlock(password), context, cb, password));
auto ret = _siaApi.GetWallet()->Unlock(password);
if (ApiSuccess(ret))
{
while (_appStarted && _siaApi.GetWallet()->GetLocked())
{
::Sleep(10);
}
}
CefPostTask(TID_RENDERER, base::Bind(&FunctionHandler::UnlockCallback, this, ret, context, cb, password));
}).detach();
return true;
@@ -135,17 +144,6 @@ public:
CefPostTask(TID_RENDERER, base::Bind(&FunctionHandler::CreateWalletCallback, this, context, cb));
return true;
}
else if (name == "startApp")
{
_appStarted = true;
_refreshCallback(context);
return true;
}
else if (name == "stopApp")
{
_appStarted = false;
return true;
}
else if (name == "mountDrive")
{
CEventSystem::EventSystem.AddOneShotEventConsumer([this, context](const CEvent& event) -> bool
@@ -319,6 +317,7 @@ void CSiaDriveApp::OnContextCreated(
CefRefPtr<CefV8Context> context)
{
CEF_REQUIRE_RENDERER_THREAD();
_appStarted = true;
_siaDriveConfig.reset(new CSiaDriveConfig(true));
@@ -469,111 +468,116 @@ void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const
auto uiActions = global->GetValue("uiUpdate");
auto renterActions = uiActions->GetValue("Renter");
auto walletActions = uiActions->GetValue("Wallet");
bool locked = _siaApi->GetWallet()->GetLocked();
bool created = _siaApi->GetWallet()->GetCreated();
// Update UI state, server version and settings
ExecuteSetter(context, uiActions, "setServerVersion", _siaApi->GetServerVersion());
uiState->SetValue("isWalletLocked", CefV8Value::CreateBool(_siaApi->GetWallet()->GetLocked()), V8_PROPERTY_ATTRIBUTE_NONE);
uiState->SetValue("isWalletConfigured", CefV8Value::CreateBool(_siaApi->GetWallet()->GetCreated()), V8_PROPERTY_ATTRIBUTE_NONE);
uiState->SetValue("allocatedRenterFunds", CefV8Value::CreateString(_siaApi->GetRenter()->GetFunds().ToString()), V8_PROPERTY_ATTRIBUTE_NONE);
ExecuteSetter(context, uiActions, "setAutoStartOnLogon", CefV8Value::CreateBool(_siaDriveConfig->GetAutoStartOnLogon()));
ExecuteSetter(context, uiActions, "setLaunchBundledSiad", CefV8Value::CreateBool(_siaDriveConfig->GetLaunchBundledSiad()));
ExecuteSetter(context, uiActions, "setLaunchFileManager", CefV8Value::CreateBool(_siaDriveConfig->GetLaunchFileMgrOnMount()));
ExecuteSetter(context, uiActions, "setApiPort", CefV8Value::CreateUInt(_siaDriveConfig->GetApiPort()));
ExecuteSetter(context, uiActions, "setHostPort", CefV8Value::CreateUInt(_siaDriveConfig->GetHostPort()));
ExecuteSetter(context, uiActions, "setRpcPort", CefV8Value::CreateUInt(_siaDriveConfig->GetRpcPort()));
// Display wallet data
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));
ExecuteSetter(context, walletActions, "setLockWalletOnExit", CefV8Value::CreateBool(_siaDriveConfig->GetLockWalletOnExit()));
if (_walletReceiveAddress.IsNullOrEmpty())
uiState->SetValue("isWalletLocked", CefV8Value::CreateBool(locked), V8_PROPERTY_ATTRIBUTE_NONE);
uiState->SetValue("isWalletConfigured", CefV8Value::CreateBool(created), V8_PROPERTY_ATTRIBUTE_NONE);
if (created && !locked)
{
_walletReceiveAddress = _siaApi->GetWallet()->GetReceiveAddress();
ExecuteSetter(context, walletActions, "setReceiveAddress", _walletReceiveAddress);
}
uiState->SetValue("allocatedRenterFunds", CefV8Value::CreateString(_siaApi->GetRenter()->GetFunds().ToString()), V8_PROPERTY_ATTRIBUTE_NONE);
ExecuteSetter(context, uiActions, "setAutoStartOnLogon", CefV8Value::CreateBool(_siaDriveConfig->GetAutoStartOnLogon()));
ExecuteSetter(context, uiActions, "setLaunchBundledSiad", CefV8Value::CreateBool(_siaDriveConfig->GetLaunchBundledSiad()));
ExecuteSetter(context, uiActions, "setLaunchFileManager", CefV8Value::CreateBool(_siaDriveConfig->GetLaunchFileMgrOnMount()));
ExecuteSetter(context, uiActions, "setApiPort", CefV8Value::CreateUInt(_siaDriveConfig->GetApiPort()));
ExecuteSetter(context, uiActions, "setHostPort", CefV8Value::CreateUInt(_siaDriveConfig->GetHostPort()));
ExecuteSetter(context, uiActions, "setRpcPort", CefV8Value::CreateUInt(_siaDriveConfig->GetRpcPort()));
// Funding
SiaCurrency allocatedFunds = _siaApi->GetRenter()->GetFunds();
SiaCurrency unspentFunds = _siaApi->GetRenter()->GetUnspent();
ExecuteSetter(context, renterActions, "setAllocatedFunds", SiaCurrencyToString(allocatedFunds));
ExecuteSetter(context, renterActions, "setUsedFunds", SiaCurrencyToString(allocatedFunds - unspentFunds));
ExecuteSetter(context, renterActions, "setAvailableFunds", SiaCurrencyToString(unspentFunds));
ExecuteSetter(context, renterActions, "setHostCount", SString::FromUInt64(_siaApi->GetRenter()->GetHosts()));
global->GetValue("uiState")->SetValue("allocatedRenterFunds", CefV8Value::CreateString(SiaCurrencyToString(allocatedFunds).str()), V8_PROPERTY_ATTRIBUTE_NONE);
// Space
SiaCurrency totalUsed = _siaApi->GetRenter()->GetTotalUsedBytes() ? _siaApi->GetRenter()->GetTotalUsedBytes() : 0.0;
SiaCurrency totalAvailable;
_siaApi->GetRenter()->CalculateEstimatedStorage(allocatedFunds, totalAvailable);
SiaCurrency estCost;
_siaApi->GetRenter()->CalculateEstimatedStorageCost(estCost);
SiaCurrency estDlCost;
_siaApi->GetRenter()->CalculateEstimatedDownloadCost(estDlCost);
SiaCurrency estUlCost;
_siaApi->GetRenter()->CalculateEstimatedUploadCost(estUlCost);
auto totalRemain = totalAvailable > 0 ? totalAvailable - totalUsed : 0;
ExecuteSetter(context, renterActions, "setEstimatedSpace", BytesToFriendlyDisplay(totalAvailable));
ExecuteSetter(context, renterActions, "setEstimatedCost", SiaCurrencyToString(estCost));
ExecuteSetter(context, renterActions, "setEstimatedDownloadCost", SiaCurrencyToString(estDlCost));
ExecuteSetter(context, renterActions, "setEstimatedUploadCost", SiaCurrencyToString(estUlCost));
ExecuteSetter(context, renterActions, "setAvailableSpace", BytesToFriendlyDisplay(totalRemain));
ExecuteSetter(context, renterActions, "setUsedSpace", BytesToFriendlyDisplay(totalUsed));
// Upload Progress
/*
SetRenterTotalUploadProgress(_siaApi->GetRenter()->GetTotalUploadProgress());
*/
// Mount
auto uiUpdate = global->GetValue("uiUpdate");
auto drives = GetAvailableDrives();
auto driveList = CefV8Value::CreateArray(drives.size());
for (size_t i = 0; i < drives.size(); i++)
{
driveList->SetValue(i, CefV8Value::CreateString((drives[i] + ":\\").str()));
}
ExecuteSetter(context, uiUpdate, "setAvailableDriveLetters", driveList);
// Renter settings
auto allowance = _siaApi->GetRenter()->GetAllowance();
auto obj = global->CreateObject(nullptr, nullptr);
obj->SetValue("Funds", CefV8Value::CreateString(SiaCurrencyToString(allowance.Funds).str()), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("Hosts", CefV8Value::CreateString(SString::FromUInt64(allowance.Hosts).str()), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("Period", CefV8Value::CreateString(SString::FromUInt64(allowance.Period).str()), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("RenewWindowInBlocks", CefV8Value::CreateString(SString::FromUInt64(allowance.RenewWindowInBlocks).str()), V8_PROPERTY_ATTRIBUTE_NONE);
ExecuteSetter(context, renterActions, "setAllowance", obj);
// Display block height
ExecuteSetter(context, uiActions, "setBlockHeight", SString::FromUInt64(_siaApi->GetConsensus()->GetHeight()));
// Upload status
auto uploadFileList = _siaDrive->GetUploadFileList();
if (uploadFileList)
{
auto list = CefV8Value::CreateArray(uploadFileList->size());
int idx = 0;
for (const auto& file : *uploadFileList)
// Display wallet data
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));
ExecuteSetter(context, walletActions, "setLockWalletOnExit", CefV8Value::CreateBool(_siaDriveConfig->GetLockWalletOnExit()));
if (_walletReceiveAddress.IsNullOrEmpty())
{
auto f = CefV8Value::CreateObject(nullptr, nullptr);
f->SetValue("SiaPath", CefV8Value::CreateString(file->GetSiaPath().str()), V8_PROPERTY_ATTRIBUTE_NONE);
f->SetValue("Progress", CefV8Value::CreateUInt(min(100u, file->GetUploadProgress())), V8_PROPERTY_ATTRIBUTE_NONE);
list->SetValue(idx++, f);
_walletReceiveAddress = _siaApi->GetWallet()->GetReceiveAddress();
ExecuteSetter(context, walletActions, "setReceiveAddress", _walletReceiveAddress);
}
ExecuteSetter(context, renterActions, "setUploadProgress", list);
}
if (!_siaDrive)
{
// Funding
SiaCurrency allocatedFunds = _siaApi->GetRenter()->GetFunds();
SiaCurrency unspentFunds = _siaApi->GetRenter()->GetUnspent();
ExecuteSetter(context, renterActions, "setAllocatedFunds", SiaCurrencyToString(allocatedFunds));
ExecuteSetter(context, renterActions, "setUsedFunds", SiaCurrencyToString(allocatedFunds - unspentFunds));
ExecuteSetter(context, renterActions, "setAvailableFunds", SiaCurrencyToString(unspentFunds));
ExecuteSetter(context, renterActions, "setHostCount", SString::FromUInt64(_siaApi->GetRenter()->GetHosts()));
global->GetValue("uiState")->SetValue("allocatedRenterFunds", CefV8Value::CreateString(SiaCurrencyToString(allocatedFunds).str()), V8_PROPERTY_ATTRIBUTE_NONE);
// Space
SiaCurrency totalUsed = _siaApi->GetRenter()->GetTotalUsedBytes() ? _siaApi->GetRenter()->GetTotalUsedBytes() : 0.0;
SiaCurrency totalAvailable;
_siaApi->GetRenter()->CalculateEstimatedStorage(allocatedFunds, totalAvailable);
SiaCurrency estCost;
_siaApi->GetRenter()->CalculateEstimatedStorageCost(estCost);
SiaCurrency estDlCost;
_siaApi->GetRenter()->CalculateEstimatedDownloadCost(estDlCost);
SiaCurrency estUlCost;
_siaApi->GetRenter()->CalculateEstimatedUploadCost(estUlCost);
auto totalRemain = totalAvailable > 0 ? totalAvailable - totalUsed : 0;
ExecuteSetter(context, renterActions, "setEstimatedSpace", BytesToFriendlyDisplay(totalAvailable));
ExecuteSetter(context, renterActions, "setEstimatedCost", SiaCurrencyToString(estCost));
ExecuteSetter(context, renterActions, "setEstimatedDownloadCost", SiaCurrencyToString(estDlCost));
ExecuteSetter(context, renterActions, "setEstimatedUploadCost", SiaCurrencyToString(estUlCost));
ExecuteSetter(context, renterActions, "setAvailableSpace", BytesToFriendlyDisplay(totalRemain));
ExecuteSetter(context, renterActions, "setUsedSpace", BytesToFriendlyDisplay(totalUsed));
// Upload Progress
/*
SetRenterTotalUploadProgress(_siaApi->GetRenter()->GetTotalUploadProgress());
*/
// Mount
auto uiUpdate = global->GetValue("uiUpdate");
auto drives = GetAvailableDrives();
auto driveList = CefV8Value::CreateArray(drives.size());
for (size_t i = 0; i < drives.size(); i++)
{
driveList->SetValue(i, CefV8Value::CreateString((drives[i] + ":\\").str()));
}
ExecuteSetter(context, uiUpdate, "setAvailableDriveLetters", driveList);
// Renter settings
auto allowance = _siaApi->GetRenter()->GetAllowance();
auto obj = global->CreateObject(nullptr, nullptr);
obj->SetValue("Funds", CefV8Value::CreateString(SiaCurrencyToString(allowance.Funds).str()), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("Hosts", CefV8Value::CreateString(SString::FromUInt64(allowance.Hosts).str()), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("Period", CefV8Value::CreateString(SString::FromUInt64(allowance.Period).str()), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("RenewWindowInBlocks", CefV8Value::CreateString(SString::FromUInt64(allowance.RenewWindowInBlocks).str()), V8_PROPERTY_ATTRIBUTE_NONE);
ExecuteSetter(context, renterActions, "setAllowance", obj);
// Display block height
ExecuteSetter(context, uiActions, "setBlockHeight", SString::FromUInt64(_siaApi->GetConsensus()->GetHeight()));
// Upload status
auto uploadFileList = _siaDrive->GetUploadFileList();
if (uploadFileList)
{
auto list = CefV8Value::CreateArray(uploadFileList->size());
int idx = 0;
for (const auto& file : *uploadFileList)
{
auto f = CefV8Value::CreateObject(nullptr, nullptr);
f->SetValue("SiaPath", CefV8Value::CreateString(file->GetSiaPath().str()), V8_PROPERTY_ATTRIBUTE_NONE);
f->SetValue("Progress", CefV8Value::CreateUInt(min(100u, file->GetUploadProgress())), V8_PROPERTY_ATTRIBUTE_NONE);
list->SetValue(idx++, f);
}
ExecuteSetter(context, renterActions, "setUploadProgress", list);
}
if (!_siaDrive)
{
#ifdef _WIN32
_siaDrive.reset(new Dokan::CSiaDokanDrive(*_siaApi, _siaDriveConfig.get()));
_siaDrive.reset(new Dokan::CSiaDokanDrive(*_siaApi, _siaDriveConfig.get()));
#else
a
a
#endif
}
}
}