1
0

Fluid UI response

This commit is contained in:
Scott E. Graves
2017-04-11 19:04:56 -05:00
parent 1b7d84efcc
commit 0b0eb84e83
2 changed files with 60 additions and 46 deletions

View File

@@ -23,47 +23,47 @@
}
}
window.uiUpdate = (()=> {
window.uiUpdate = (() => {
const _renter = (()=> {
const _renter = (() => {
return {
setAllocatedFunds: (currency)=> {
setAllocatedFunds: (currency) => {
setInnerText('ID_Renter_AllocatedFunds', currency);
},
setUsedFunds: (currency)=> {
setUsedFunds: (currency) => {
setInnerText('ID_Renter_UsedFunds', currency);
},
setAvailableFunds: (currency)=> {
setAvailableFunds: (currency) => {
setInnerText('ID_Renter_AvailableFunds', currency);
},
setHostCount: (count)=> {
setHostCount: (count) => {
setInnerText('ID_Renter_HostCount', count);
},
setEstimatedSpace: (space)=> {
setEstimatedSpace: (space) => {
setInnerText('ID_Renter_EstimatedSpace', space);
},
setUsedSpace: (space)=> {
setUsedSpace: (space) => {
setInnerText('ID_Renter_UsedSpace', space);
},
setEstimatedCost: (currency)=> {
setEstimatedCost: (currency) => {
setInnerText('ID_Renter_EstimatedCost', currency);
},
setAvailableSpace: (space)=> {
setAvailableSpace: (space) => {
setInnerText('ID_Renter_AvailablSpace', space);
},
setDownloadCost: (currency)=> {
setDownloadCost: (currency) => {
setInnerText('ID_Renter_EstimatedDownloadCost', currency);
},
setUploadCost: (currency)=> {
setUploadCost: (currency) => {
setInnerText('ID_Renter_EstimatedUploadCost', currency);
},
setAllowance: (allowance)=> {
setAllowance: (allowance) => {
if (document.getElementById('renter_settings_window').classList.contains('hidden-element')) {
setValue('ID_RenterSetFunds', allowance.Funds);
setValue('ID_RenterSetHosts', allowance.Hosts);
setValue('ID_RenterSetPeriod', allowance.Period);
setValue('ID_RenterSetRenewWindow', allowance.RenewWindowInBlocks);
AppActions.calculateEstimatedStorage(allowance.Funds, (res)=> {
AppActions.calculateEstimatedStorage(allowance.Funds, (res) => {
setInnerText('ID_RenterCalcStorage', '~' + res);
});
}
@@ -71,18 +71,18 @@
};
})();
const _wallet = (()=> {
const _wallet = (() => {
return {
setConfirmedBalance: (balance)=> {
setConfirmedBalance: (balance) => {
setInnerText('ID_WalletConfirmedBalance', balance);
},
setUnconfirmedBalance: (balance)=> {
setUnconfirmedBalance: (balance) => {
setInnerText('ID_WalletBalanceUnconfirmed', balance);
},
setTotalBalance: (balance)=> {
setTotalBalance: (balance) => {
setInnerText('ID_WalletTotalBalance', balance);
},
setReceiveAddress: (address)=> {
setReceiveAddress: (address) => {
setInnerText('ID_WalletReceiveAddress', address);
}
};
@@ -97,17 +97,18 @@
setServerVersion: (version) => {
setInnerText('ID_ServerVersion', version);
},
setAvailableDriveLetters: (drives)=> {
setAvailableDriveLetters: (drives) => {
if (document.getElementById('ID_MountButton').innerText !== 'Unmount') {
setSelect('ID_MountDrives', drives);
}
},
notifyDriveUnmounted: _notifyDriveUnmounted
notifyDriveUnmounted: _notifyDriveUnmounted,
reloadApplication: reloadApplication
};
})();
const UiState = (()=> {
const UiState = (() => {
function _clientVersion() {
return 'v' + window.uiState.clientVersion;
}
@@ -181,6 +182,7 @@
function _calculateEstimatedStorage(funds, cb) {
window.appActions.calculateEstimatedStorage(funds, cb)
}
return {
createWallet: _createWallet,
mountDrive: _mountDrive,
@@ -234,14 +236,14 @@
AppActions.startApp();
setMainWindow('app_window');
const renterEditLink = document.getElementById('ID_Renter_Edit');
renterEditLink.onclick = ()=> {
renterEditLink.onclick = () => {
renterEditLink.onclick = null;
handleRenterEditSettings();
};
const mountButton = document.getElementById('ID_MountButton');
const mountSelect = document.getElementById('ID_MountDrives');
_mountHandler = ()=> {
_mountHandler = () => {
if (UiState.allocatedRenterFunds() === '0') {
displayErrorPopup('Error', 'Renter funding must be configured before trying to mount.')
} else {
@@ -278,13 +280,13 @@
setMainWindow('renter_settings_window');
const funds = document.getElementById('ID_RenterSetFunds');
funds.oninput = () => {
AppActions.calculateEstimatedStorage(funds.value, (res)=> {
AppActions.calculateEstimatedStorage(funds.value, (res) => {
setInnerText('ID_RenterCalcStorage', '~' + res);
});
};
const defaultsButton = document.getElementById('ID_RenterSettingsDefaults');
defaultsButton.onclick = ()=> {
defaultsButton.onclick = () => {
funds.oninput = null;
const settings = UiState.defaultRenterSettings();
if (getValue('ID_RenterSetFunds') === '0') {
@@ -296,7 +298,7 @@
};
const cancelButton = document.getElementById('ID_RenterSettingsCancel');
cancelButton.onclick = ()=> {
cancelButton.onclick = () => {
funds.oninput = null;
saveButton.onclick = null;
cancelButton.onclick = null;
@@ -305,7 +307,7 @@
};
const saveButton = document.getElementById('ID_RenterSettingsOK');
saveButton.onclick = ()=> {
saveButton.onclick = () => {
funds.oninput = null;
saveButton.onclick = null;
cancelButton.onclick = null;
@@ -315,7 +317,7 @@
'Hosts': getValue('ID_RenterSetHosts'),
'Period': getValue('ID_RenterSetPeriod'),
'RenewWindowInBlocks': getValue('ID_RenterSetRenewWindow')
}, (success, reason)=> {
}, (success, reason) => {
if (success) {
beginMainApplication();
} else {
@@ -354,7 +356,7 @@
setMainWindow('wallet_created_window');
document.getElementById('ID_WalletSeed').innerText = seed;
const button = document.getElementById('ID_WalletCreatedButton');
button.onclick = ()=> {
button.onclick = () => {
button.onclick = null;
handleUnlockWallet();
};
@@ -377,8 +379,7 @@
};
}
window.addEventListener('load', ()=> {
console.log('Main window load');
function reloadApplication() {
AppActions.stopApp();
document.getElementById('ID_SiaDrive').innerText = 'SiaDrive ' + UiState.clientVersion();
document.getElementById('ID_ServerVersion').innerText = '...';
@@ -395,6 +396,11 @@
} else {
setMainWindow('offline_window');
}
}
window.addEventListener('load', ()=> {
console.log('Main window load');
reloadApplication();
});
window.onunload = ()=> {

View File

@@ -309,12 +309,12 @@ void CSiaDriveApp::OnContextCreated(
CEF_REQUIRE_RENDERER_THREAD();
CefRefPtr<CefV8Value> global = context->GetGlobal();
CefRefPtr<FunctionHandler> handler(new FunctionHandler(*_siaApi, _appStarted, _siaDriveConfig, _siaDrive, [this]() {this->ShutdownServices(); }, [this](CefRefPtr<CefV8Context> context) {this->SiaApiRefreshCallback(context, *_siaCurl, _siaDriveConfig.get()); }));
CefRefPtr<CefV8Value> obj = CefV8Value::CreateObject(nullptr, nullptr);
obj->SetValue("isWalletLocked", CefV8Value::CreateBool(_siaApi->GetWallet()->GetLocked()), V8_PROPERTY_ATTRIBUTE_NONE);
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("allocatedRenterFunds", CefV8Value::CreateString(_siaApi->GetRenter()->GetFunds().ToString()), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("isOnline", CefV8Value::CreateBool(_siaApi->GetWallet()->GetConnected()), V8_PROPERTY_ATTRIBUTE_NONE);
CefRefPtr<CefV8Value> defaultFunds = CefV8Value::CreateObject(nullptr, nullptr);
defaultFunds->SetValue("Funds", CefV8Value::CreateString(SIA_DEFAULT_MINIMUM_FUNDS.ToString()), V8_PROPERTY_ATTRIBUTE_NONE);
defaultFunds->SetValue("Hosts", CefV8Value::CreateString(SString::FromUInt32(SIA_DEFAULT_HOST_COUNT).str()), V8_PROPERTY_ATTRIBUTE_NONE);
@@ -323,7 +323,6 @@ void CSiaDriveApp::OnContextCreated(
obj->SetValue("defaultRenterSettings", defaultFunds, V8_PROPERTY_ATTRIBUTE_NONE);
global->SetValue("uiState", obj, V8_PROPERTY_ATTRIBUTE_NONE);
CefRefPtr<FunctionHandler> handler(new FunctionHandler(*_siaApi, _appStarted, _siaDriveConfig, _siaDrive, [this]() {this->ShutdownServices(); }, [this](CefRefPtr<CefV8Context> context) {this->SiaApiRefreshCallback(context, *_siaCurl, _siaDriveConfig.get()); }));
obj = CefV8Value::CreateObject(nullptr, nullptr);
obj->SetValue("unlockWallet", CefV8Value::CreateFunction("unlockWallet", handler), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("createWallet", CefV8Value::CreateFunction("createWallet", handler), V8_PROPERTY_ATTRIBUTE_NONE);
@@ -398,21 +397,22 @@ void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const
{
context->Enter();
auto global = context->GetGlobal();
bool wasOnline = global->GetValue("uiState")->GetValue("isOnline")->GetBoolValue();
auto uiState = global->GetValue("uiState");
bool wasOnline = uiState->GetValue("isOnline")->GetBoolValue();
bool isOnline = _siaApi->GetWallet()->GetConnected();
if (wasOnline != isOnline)
{
_appStarted = false;
context->GetBrowser()->Reload();
}
else if (_appStarted)
uiState->SetValue("isOnline", CefV8Value::CreateBool(isOnline), V8_PROPERTY_ATTRIBUTE_NONE);
if (isOnline)
{
auto uiActions = global->GetValue("uiUpdate");
auto renterActions = uiActions->GetValue("Renter");
auto walletActions = uiActions->GetValue("Wallet");
// Update server version
// Update UI state and server version
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);
// Display wallet data
auto confirmedBalance = _siaApi->GetWallet()->GetConfirmedBalance();
@@ -472,6 +472,14 @@ void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const
// Display block height
ExecuteSetter(context, uiActions, "setBlockHeight", SString::FromUInt64(_siaApi->GetConsensus()->GetHeight()));
}
if (isOnline != wasOnline)
{
CefRefPtr<CefV8Value> reloadApplication = global->GetValue("uiUpdate")->GetValue("reloadApplication");
CefV8ValueList args;
reloadApplication->ExecuteFunctionWithContext(context, nullptr, args);
}
context->Exit();
}
else