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

View File

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