1
0

Unmount on shutdown

This commit is contained in:
Scott E. Graves
2017-03-24 08:28:17 -05:00
parent 8ffb6d20f6
commit 14b0b39995
4 changed files with 41 additions and 26 deletions

View File

@@ -1,3 +1,5 @@
/* Work Laptop
Work Laptop
vitals thirsty tattoo unjustly already lexicon ruthless rated skater voyage avoid jeers aunt tawny richly glass menu kidneys went wounded wounded trendy towel lipstick raking bacon dozen blip aggravate
*/
Home Laptop
basin bobsled greater eden deftly dwarf powder intended under pact remedy neutral mime bite sphere nexus python trolling virtual sulking lordship ghetto aphid jazz village gables tapestry drinks afar

View File

@@ -143,13 +143,18 @@
return window.appActions.unmountDrive(cb);
}
function _shutdown() {
window.appActions.shutdown();
}
return {
createWallet: _createWallet,
mountDrive: _mountDrive,
startApp: _startApp,
stopApp: _stopApp,
unlockWallet: _unlockWallet,
unmountDrive: _unmountDrive
unmountDrive: _unmountDrive,
shutdown: _shutdown
};
})();
@@ -280,4 +285,8 @@
setMainWindow('offline_window');
}
});
window.onunload = ()=> {
AppActions.shutdown();
};
})();

View File

@@ -29,6 +29,8 @@ class CSiaDriveApp :
public:
CSiaDriveApp();
virtual ~CSiaDriveApp();
private:
std::unique_ptr<Api::CAutoThread> _refreshThread;
std::unique_ptr<Api::CSiaApi> _siaApi;
@@ -57,7 +59,6 @@ public:
// CefBrowserProcessHandler methods:
virtual void OnContextInitialized() OVERRIDE;
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) OVERRIDE;
virtual void OnContextReleased(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) OVERRIDE;
private:
static void ExecuteSetter(CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> obj, const SString& method, const SString& value);

View File

@@ -17,11 +17,12 @@ class FunctionHandler :
public CefV8Handler
{
public:
FunctionHandler(const CSiaApi& siaApi, bool& appStarted, std::unique_ptr<CSiaDriveConfig>& siaDriveConfig, std::unique_ptr<Api::Dokan::CSiaDokanDrive>& siaDrive) :
FunctionHandler(const CSiaApi& siaApi, bool& appStarted, std::unique_ptr<CSiaDriveConfig>& siaDriveConfig, std::unique_ptr<Api::Dokan::CSiaDokanDrive>& siaDrive, std::function<void()> shutdownCallback) :
_siaApi(siaApi),
_siaDriveConfig(siaDriveConfig),
_siaDrive(siaDrive),
_appStarted(appStarted)
_appStarted(appStarted),
_shutdownCallback(shutdownCallback)
{
}
@@ -30,6 +31,7 @@ private:
std::unique_ptr<CSiaDriveConfig>& _siaDriveConfig;
std::unique_ptr<Api::Dokan::CSiaDokanDrive>& _siaDrive;
bool& _appStarted;
std::function<void()> _shutdownCallback;
private:
void MountCallback(CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> cb) const
@@ -147,6 +149,11 @@ public:
return true;
}
else if (name == "shutdown")
{
_shutdownCallback();
return true;
}
// Function does not exist.
return false;
@@ -201,6 +208,12 @@ CSiaDriveApp::CSiaDriveApp()
_siaApi.reset(new CSiaApi(hostConfig, _siaDriveConfig.get()));
}
CSiaDriveApp::~CSiaDriveApp()
{
_siaApi.reset(nullptr);
_siaCurl.reset(nullptr);
}
void CSiaDriveApp::ExecuteSetter(CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> obj, const SString& method, const SString& value)
{
ExecuteSetter(context, obj, method, CefV8Value::CreateString(value.str()));
@@ -229,7 +242,7 @@ void CSiaDriveApp::OnContextCreated(
obj->SetValue("clientVersion", CefV8Value::CreateString(SIDRIVE_VERSION_STRING), V8_PROPERTY_ATTRIBUTE_NONE);
global->SetValue("uiState", obj, V8_PROPERTY_ATTRIBUTE_NONE);
CefRefPtr<FunctionHandler> handler(new FunctionHandler(*_siaApi, _appStarted, _siaDriveConfig, _siaDrive));
CefRefPtr<FunctionHandler> handler(new FunctionHandler(*_siaApi, _appStarted, _siaDriveConfig, _siaDrive, [this]() {this->ShutdownServices(); }));
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);
@@ -237,6 +250,7 @@ void CSiaDriveApp::OnContextCreated(
obj->SetValue("stopApp", CefV8Value::CreateFunction("stopApp", handler), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("mountDrive", CefV8Value::CreateFunction("mountDrive", handler), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("unmountDrive", CefV8Value::CreateFunction("unmountDrive", handler), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("shutdown", CefV8Value::CreateFunction("shutdown", handler), V8_PROPERTY_ATTRIBUTE_NONE);
global->SetValue("appActions", obj, V8_PROPERTY_ATTRIBUTE_NONE);
_refreshThread.reset(new CAutoThread(*_siaCurl, _siaDriveConfig.get(), [this, context](const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig)
@@ -282,31 +296,20 @@ void CSiaDriveApp::OnContextInitialized()
void CSiaDriveApp::ShutdownServices()
{
if (CefCurrentlyOn(TID_RENDERER))
if (_refreshThread)
{
if (_refreshThread)
{
_refreshThread->StopAutoThread();
_refreshThread.reset(nullptr);
}
if (_siaDrive)
{
_siaDrive->Unmount();
_siaDrive.reset(nullptr);
}
_appStarted = false;
_refreshThread->StopAutoThread();
_refreshThread.reset(nullptr);
}
else
if (_siaDrive)
{
CefPostTask(TID_RENDERER, base::Bind(&CSiaDriveApp::ShutdownServices, this));
_siaDrive->Unmount();
_siaDrive.reset(nullptr);
}
}
void CSiaDriveApp::OnContextReleased(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)
{
ShutdownServices();
}
void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig)
{
if (CefCurrentlyOn(TID_RENDERER))