|
|
|
@@ -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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|