1
0

Auto-mount

This commit is contained in:
Scott E. Graves
2017-05-04 11:39:47 -05:00
parent a985f1823e
commit 9b078ba30a
6 changed files with 61 additions and 10 deletions

View File

@@ -179,10 +179,11 @@
<div class="hidden-element" id="sia_settings_window"> <div class="hidden-element" id="sia_settings_window">
<div class="box" id="sia_settings"> <div class="box" id="sia_settings">
<h1>General Settings</h1> <h1>General Settings</h1>
<input type="checkbox" id="ID_Settings_LockWalletOnExit">&nbsp;Lock wallet on exit<br><br> <input type="checkbox" id="ID_Settings_AutoMountOnUnlock">&nbsp;Auto-mount last location<br><br>
<input type="checkbox" id="ID_Settings_AutoStartOnLogon">&nbsp;Auto-start on logon<br><br> <input type="checkbox" id="ID_Settings_AutoStartOnLogon">&nbsp;Auto-start on logon<br><br>
<input type="checkbox" id="ID_Settings_LaunchFileMgrOnMount">&nbsp;Launch file manager on mount<br><br>
<input type="checkbox" id="ID_Settings_CloseToTray">&nbsp;Close to system tray<br><br> <input type="checkbox" id="ID_Settings_CloseToTray">&nbsp;Close to system tray<br><br>
<input type="checkbox" id="ID_Settings_LaunchFileMgrOnMount">&nbsp;Launch file manager on mount<br><br>
<input type="checkbox" id="ID_Settings_LockWalletOnExit">&nbsp;Lock wallet on exit<br><br>
<input type="checkbox" id="ID_Settings_StoreUnlockPassword">&nbsp;Store unlock password<br><br> <input type="checkbox" id="ID_Settings_StoreUnlockPassword">&nbsp;Store unlock password<br><br>
<input type="checkbox" id="ID_Settings_LaunchBundledSiad">&nbsp;Use bundled siad<br><br> <input type="checkbox" id="ID_Settings_LaunchBundledSiad">&nbsp;Use bundled siad<br><br>
<h1>API Port</h1> <h1>API Port</h1>

View File

@@ -345,7 +345,8 @@
'RpcPort': getValue('ID_Settings_RpcPort'), 'RpcPort': getValue('ID_Settings_RpcPort'),
'LaunchFileMgrOnMount': getChecked('ID_Settings_LaunchFileMgrOnMount'), 'LaunchFileMgrOnMount': getChecked('ID_Settings_LaunchFileMgrOnMount'),
'CloseToTray': getChecked('ID_Settings_CloseToTray'), 'CloseToTray': getChecked('ID_Settings_CloseToTray'),
'StoreUnlockPassword': getChecked('ID_Settings_StoreUnlockPassword') 'StoreUnlockPassword': getChecked('ID_Settings_StoreUnlockPassword'),
'AutoMountOnUnlock': getChecked('ID_Settings_AutoMountOnUnlock')
}, (success, reason) => { }, (success, reason) => {
if (success) { if (success) {
beginMainApplication(); beginMainApplication();

View File

@@ -33,6 +33,8 @@ public:
JProperty(bool, PromptOnClose, public, public, _configDocument) JProperty(bool, PromptOnClose, public, public, _configDocument)
JProperty(bool, CloseToTray, public, public, _configDocument) JProperty(bool, CloseToTray, public, public, _configDocument)
JProperty(bool, StoreUnlockPassword, public, public, _configDocument) JProperty(bool, StoreUnlockPassword, public, public, _configDocument)
JProperty(bool, AutoMountOnUnlock, public, public, _configDocument)
JProperty(std::string, LastMountLocation, public, public, _configDocument)
private: private:
const bool _autoSave; const bool _autoSave;

View File

@@ -65,7 +65,25 @@ private:
{ {
CefV8ValueList args; CefV8ValueList args;
args.push_back(CefV8Value::CreateBool(ApiSuccess(error))); args.push_back(CefV8Value::CreateBool(ApiSuccess(error)));
if (!args[0]->GetBoolValue()) if (args[0]->GetBoolValue())
{
if (_siaDriveConfig->GetAutoMountOnUnlock())
{
const auto lastMountLocation = _siaDriveConfig->GetLastMountLocation();
if (!lastMountLocation.empty())
{
// Change mount location
// Disable mount location
// Change mount button to 'Unmount'
// Disable mount button
std::thread([this, lastMountLocation, context, cb]()
{
_siaDrive->Mount(lastMountLocation[0], _siaDriveConfig->GetCacheFolder(), 0);
}).detach();
}
}
}
else
{ {
args.push_back(CefV8Value::CreateString("Failed to unlock wallet")); args.push_back(CefV8Value::CreateString("Failed to unlock wallet"));
} }
@@ -246,6 +264,7 @@ public:
_siaDriveConfig->SetRpcPort(SString::ToUInt32(settings->GetValue("RpcPort")->GetStringValue().ToWString())); _siaDriveConfig->SetRpcPort(SString::ToUInt32(settings->GetValue("RpcPort")->GetStringValue().ToWString()));
_siaDriveConfig->SetCloseToTray(settings->GetValue("CloseToTray")->GetBoolValue()); _siaDriveConfig->SetCloseToTray(settings->GetValue("CloseToTray")->GetBoolValue());
_siaDriveConfig->SetStoreUnlockPassword(settings->GetValue("StoreUnlockPassword")->GetBoolValue()); _siaDriveConfig->SetStoreUnlockPassword(settings->GetValue("StoreUnlockPassword")->GetBoolValue());
_siaDriveConfig->SetAutoMountOnUnlock(settings->GetValue("AutoMountOnUnlock")->GetBoolValue());
if (!_siaDriveConfig->GetStoreUnlockPassword()) if (!_siaDriveConfig->GetStoreUnlockPassword())
{ {
SetRegistry("Unlock", ""); SetRegistry("Unlock", "");
@@ -481,7 +500,8 @@ void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const
{ "HostPort", _siaDriveConfig->GetHostPort() }, { "HostPort", _siaDriveConfig->GetHostPort() },
{ "RpcPort", _siaDriveConfig->GetRpcPort() }, { "RpcPort", _siaDriveConfig->GetRpcPort() },
{ "CloseToTray", _siaDriveConfig->GetCloseToTray() }, { "CloseToTray", _siaDriveConfig->GetCloseToTray() },
{ "StoreUnlockPassword", _siaDriveConfig->GetStoreUnlockPassword() } { "StoreUnlockPassword", _siaDriveConfig->GetStoreUnlockPassword() },
{ "AutoMountOnUnlock", _siaDriveConfig->GetAutoMountOnUnlock() }
}; };
ExecuteSetter(context, uiActions, "setSiaSettings", CefV8Value::CreateString(settings.dump())); ExecuteSetter(context, uiActions, "setSiaSettings", CefV8Value::CreateString(settings.dump()));
@@ -589,7 +609,23 @@ void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const
if (isOnline) if (isOnline)
{ {
auto uiActions = global->GetValue("uiUpdate"); auto uiActions = global->GetValue("uiUpdate");
ExecuteSetter(context, uiActions, "setServerVersion", _siaApi->GetServerVersion()); ExecuteSetter(context, uiActions, "setServerVersion", _siaApi->GetServerVersion());
if (_siaDriveConfig->GetAutoMountOnUnlock())
{
const auto lastMountLocation = _siaDriveConfig->GetLastMountLocation();
if (!lastMountLocation.empty())
{
// Change mount location
// Disable mount location
// Change mount button to 'Unmount'
// Disable mount button
std::thread([this, lastMountLocation]()
{
_siaDrive->Mount(lastMountLocation[0], _siaDriveConfig->GetCacheFolder(), 0);
}).detach();
}
}
} }
if (!isOnline && _siaDrive) if (!isOnline && _siaDrive)

View File

@@ -190,6 +190,18 @@ bool CSiaDriveConfig::LoadDefaults()
changed = true; changed = true;
} }
if (!CheckAutoMountOnUnlock())
{
SetAutoMountOnUnlock(false);
changed = true;
}
if (!CheckLastMountLocation())
{
SetLastMountLocation("");
changed = true;
}
return changed; return changed;
} }

View File

@@ -1937,6 +1937,7 @@ private:
static NTSTATUS DOKAN_CALLBACK Sia_Mounted(PDOKAN_FILE_INFO dokanFileInfo) static NTSTATUS DOKAN_CALLBACK Sia_Mounted(PDOKAN_FILE_INFO dokanFileInfo)
{ {
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DriveMounted(_mountPoint))); CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DriveMounted(_mountPoint)));
_siaDriveConfig->SetLastMountLocation(_mountPoint);
if (_siaDriveConfig->GetLaunchFileMgrOnMount()) if (_siaDriveConfig->GetLaunchFileMgrOnMount())
{ {
::ShellExecute(nullptr, L"open", &_mountPoint[0], nullptr, nullptr, SW_SHOWDEFAULT); ::ShellExecute(nullptr, L"open", &_mountPoint[0], nullptr, nullptr, SW_SHOWDEFAULT);
@@ -2288,15 +2289,13 @@ private:
if (dokanFileInfo->DeleteOnClose) if (dokanFileInfo->DeleteOnClose)
{ {
// Should already be deleted by CloseHandle
// if open with FILE_FLAG_DELETE_ON_CLOSE
if (dokanFileInfo->IsDirectory) if (dokanFileInfo->IsDirectory)
{ {
while (!filePath.RemoveDirectory()); filePath.RemoveDirectory();
} }
else else
{ {
while (!filePath.DeleteFile()); filePath.DeleteFile();
} }
_siaApi->GetRenter()->RefreshFileTree(); _siaApi->GetRenter()->RefreshFileTree();