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

View File

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