diff --git a/build.cmd b/build.cmd index 2b1c5eb..51f8f50 100644 --- a/build.cmd +++ b/build.cmd @@ -18,19 +18,20 @@ rd /s /q "%ROOT%dist\%TARGET_MODE%\htdocs" mkdir build >NUL 2>&1 mkdir build\%TARGET_MODE% >NUL 2>&1 pushd build\%TARGET_MODE% >NUL 2>&1 - (%CMAKE% -G "Visual Studio 14 2015 Win64" -DCMAKE_BUILD_TYPE=%TARGET_MODE% -DSIADRIVE_INSTALL_FOLDER="%ROOT%dist\%TARGET_MODE%" ..\..) && ( - %CMAKE% --build . --config %TARGET_MODE%) && ( - %CMAKE% --build . --target install --config %TARGET_MODE% && ( - rd /s /q "%ROOT%dist\%TARGET_MODE%\config" - rd /s /q "%ROOT%dist\%TARGET_MODE%\htdocs\.idea" - del /q "%ROOT%dist\%TARGET_MODE%\*.log" - rd /s /q "%ROOT%dist\%TARGET_MODE%\logs" - if "%TARGET_MODE%"=="Release" ( - del /q "%ROOT%dist\%TARGET_MODE%\*.lib" - del /q "%ROOT%dist\%TARGET_MODE%\*.pdb" + ((%CMAKE% -G "Visual Studio 14 2015 Win64" -DCMAKE_BUILD_TYPE=%TARGET_MODE% -DSIADRIVE_INSTALL_FOLDER="%ROOT%dist\%TARGET_MODE%" ..\..) && ( + %CMAKE% --build . --config %TARGET_MODE%) && ( + %CMAKE% --build . --target install --config %TARGET_MODE% && ( + rd /s /q "%ROOT%dist\%TARGET_MODE%\config" + rd /s /q "%ROOT%dist\%TARGET_MODE%\htdocs\.idea" + del /q "%ROOT%dist\%TARGET_MODE%\*.log" + rd /s /q "%ROOT%dist\%TARGET_MODE%\logs" + if "%TARGET_MODE%"=="Release" ( + del /q "%ROOT%dist\%TARGET_MODE%\*.lib" + del /q "%ROOT%dist\%TARGET_MODE%\*.pdb" + ) ) ) - ) + ) || exit 1 popd popd \ No newline at end of file diff --git a/htdocs/js/index.js b/htdocs/js/index.js index 644daff..b44c245 100644 --- a/htdocs/js/index.js +++ b/htdocs/js/index.js @@ -261,7 +261,10 @@ } function _setSiaSettings(settings, cb) { - window.appActions.setSiaSettings(settings, cb); + } + + function _autoMountDrive() { + window.appActions.autoMountDrive(); } return { @@ -273,7 +276,8 @@ shutdown: _shutdown, setRenterSettings: _setRenterSettings, calculateEstimatedStorage: _calculateEstimatedStorage, - setSiaSettings: _setSiaSettings + setSiaSettings: _setSiaSettings, + autoMountDrive: _autoMountDrive }; })(); @@ -330,7 +334,7 @@ const okButton = document.getElementById('ID_RenterUploadsOk'); okButton.onclick = () => { okButton.onclick = null; - beginMainApplication(); + beginMainApplication(false); }; } @@ -340,7 +344,7 @@ cancelButton.onclick = () => { cancelButton.onclick = null; saveButton.onclick = null; - beginMainApplication(); + beginMainApplication(false); }; const saveButton = document.getElementById('ID_SiaSettingsOK'); @@ -360,7 +364,7 @@ 'AutoMountOnUnlock': getChecked('ID_Settings_AutoMountOnUnlock') }, (success, reason) => { if (success) { - beginMainApplication(); + beginMainApplication(false); } else { displayErrorPopup('Settings Failed', reason); handleSiaEditSettings(); @@ -369,7 +373,7 @@ }; } - function beginMainApplication() { + function beginMainApplication(checkAutoMount) { setMainWindow('app_window'); const settingsEditLink = document.getElementById('ID_Sia_Settings_Edit'); settingsEditLink.onclick = () => { @@ -422,6 +426,9 @@ } }; mountButton.onclick = _mountHandler; + if (checkAutoMount) { + AppActions.autoMountDrive( ); + } } function handleRenterEditSettings() { @@ -451,7 +458,7 @@ saveButton.onclick = null; cancelButton.onclick = null; defaultsButton.onclick = null; - beginMainApplication(); + beginMainApplication(false); }; const saveButton = document.getElementById('ID_RenterSettingsOK'); @@ -467,7 +474,7 @@ 'RenewWindowInBlocks': getValue('ID_RenterSetRenewWindow') }, (success, reason) => { if (success) { - beginMainApplication(); + beginMainApplication(false); } else { displayErrorPopup('Allocation Failed', reason); handleRenterEditSettings(); @@ -484,7 +491,7 @@ const password = document.getElementById('ID_WalletUnlockPwd'); if (AppActions.unlockWallet(password.value, (success, reason) => { if (success) { - beginMainApplication(); + beginMainApplication(true); } else { displayErrorPopup('Error', reason, () => { handleUnlockWallet(); @@ -503,7 +510,7 @@ if (UiState.getStoreUnlockPassword()) { if (AppActions.autoUnlockWallet((success) => { if (success) { - beginMainApplication(); + beginMainApplication(true); } else { manualUnlockWallet(); } @@ -544,7 +551,7 @@ }; } - function reloadApplication() { + function reloadApplication(checkAutoMount) { document.getElementById('ID_SiaDrive').innerText = 'SiaDrive ' + UiState.clientVersion(); document.getElementById('ID_ServerVersion').innerText = '...'; if (UiState.isOnline()) { @@ -552,7 +559,7 @@ if (UiState.isWalletLocked()) { handleUnlockWallet(); } else { - beginMainApplication(); + beginMainApplication(checkAutoMount); } } else { handleCreateWallet(); @@ -564,6 +571,6 @@ window.addEventListener('load', ()=> { console.log('Main window load'); - reloadApplication(); + reloadApplication(true); }); })(); \ No newline at end of file diff --git a/src/siadrive/siadriveapp.cpp b/src/siadrive/siadriveapp.cpp index 8b175eb..8638694 100644 --- a/src/siadrive/siadriveapp.cpp +++ b/src/siadrive/siadriveapp.cpp @@ -65,28 +65,7 @@ private: { CefV8ValueList args; args.push_back(CefV8Value::CreateBool(ApiSuccess(error))); - if (args[0]->GetBoolValue()) - { - if (_siaDriveConfig->GetAutoMountOnUnlock()) - { - const auto lastMountLocation = _siaDriveConfig->GetLastMountLocation(); - if (!lastMountLocation.empty()) - { - auto global = context->GetGlobal(); - auto uiUpdate = global->GetValue("uiUpdate"); - auto notifyDriveMounting = uiUpdate->GetValue("notifyDriveMounting");; - - CefV8ValueList args2; - args2.push_back(CefV8Value::CreateString(lastMountLocation)); - notifyDriveMounting->ExecuteFunction(nullptr, args2); - std::thread([this, lastMountLocation, context]() - { - _siaDrive->Mount(lastMountLocation[0], _siaDriveConfig->GetCacheFolder(), 0); - }).detach(); - } - } - } - else + if (!args[0]->GetBoolValue()) { args.push_back(CefV8Value::CreateString("Failed to unlock wallet")); } @@ -188,6 +167,30 @@ public: return true; } + else if (name == "autoMountDrive") + { + retval = CefV8Value::CreateBool(true); + if (_siaDriveConfig->GetAutoMountOnUnlock()) + { + const auto lastMountLocation = _siaDriveConfig->GetLastMountLocation(); + if (!lastMountLocation.empty()) + { + auto global = context->GetGlobal(); + auto uiUpdate = global->GetValue("uiUpdate"); + auto notifyDriveMounting = uiUpdate->GetValue("notifyDriveMounting");; + + CefV8ValueList args2; + args2.push_back(CefV8Value::CreateString(lastMountLocation)); + notifyDriveMounting->ExecuteFunction(nullptr, args2); + std::thread([this, lastMountLocation, context]() + { + _siaDrive->Mount(lastMountLocation[0], _siaDriveConfig->GetCacheFolder(), 0); + }).detach(); + } + } + + return true; + } else if (name == "createWallet") { retval = CefV8Value::CreateBool(true); @@ -377,6 +380,7 @@ void CSiaDriveApp::OnContextCreated( global->SetValue("uiState", obj, V8_PROPERTY_ATTRIBUTE_NONE); obj = CefV8Value::CreateObject(nullptr, nullptr); + obj->SetValue("autoMountDrive", CefV8Value::CreateFunction("autoMountDrive", handler), V8_PROPERTY_ATTRIBUTE_NONE); obj->SetValue("autoUnlockWallet", CefV8Value::CreateFunction("autoUnlockWallet", 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); @@ -608,30 +612,12 @@ void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr context, const { CefRefPtr reloadApplication = global->GetValue("uiUpdate")->GetValue("reloadApplication"); CefV8ValueList args; + args.push_back(CefV8Value::CreateBool(isOnline)); reloadApplication->ExecuteFunctionWithContext(context, nullptr, args); if (isOnline) { auto uiActions = global->GetValue("uiUpdate"); ExecuteSetter(context, uiActions, "setServerVersion", _siaApi->GetServerVersion()); - - if (_siaDriveConfig->GetAutoMountOnUnlock()) - { - const auto lastMountLocation = _siaDriveConfig->GetLastMountLocation(); - if (!lastMountLocation.empty()) - { - auto uiUpdate = global->GetValue("uiUpdate"); - auto notifyDriveMounting = uiUpdate->GetValue("notifyDriveMounting");; - - CefV8ValueList args2; - args2.push_back(CefV8Value::CreateString(lastMountLocation)); - notifyDriveMounting->ExecuteFunction(nullptr, args2); - - std::thread([this, lastMountLocation]() - { - _siaDrive->Mount(lastMountLocation[0], _siaDriveConfig->GetCacheFolder(), 0); - }).detach(); - } - } } if (!isOnline && _siaDrive)