From 14b0b39995b11de080ee14d4d3a9c65c60e5c738 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Fri, 24 Mar 2017 08:28:17 -0500 Subject: [PATCH] Unmount on shutdown --- Seeds.txt | 6 +++-- htdocs/js/index.js | 11 +++++++- include/siadrive/siadriveapp.h | 3 ++- src/siadrive/siadriveapp.cpp | 47 ++++++++++++++++++---------------- 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/Seeds.txt b/Seeds.txt index 0524ed3..24299a8 100644 --- a/Seeds.txt +++ b/Seeds.txt @@ -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 -*/ \ No newline at end of file + +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 \ No newline at end of file diff --git a/htdocs/js/index.js b/htdocs/js/index.js index 2a33540..53c546f 100644 --- a/htdocs/js/index.js +++ b/htdocs/js/index.js @@ -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(); + }; })(); \ No newline at end of file diff --git a/include/siadrive/siadriveapp.h b/include/siadrive/siadriveapp.h index 96d7b69..461174f 100644 --- a/include/siadrive/siadriveapp.h +++ b/include/siadrive/siadriveapp.h @@ -29,6 +29,8 @@ class CSiaDriveApp : public: CSiaDriveApp(); + virtual ~CSiaDriveApp(); + private: std::unique_ptr _refreshThread; std::unique_ptr _siaApi; @@ -57,7 +59,6 @@ public: // CefBrowserProcessHandler methods: virtual void OnContextInitialized() OVERRIDE; virtual void OnContextCreated(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) OVERRIDE; - virtual void OnContextReleased(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) OVERRIDE; private: static void ExecuteSetter(CefRefPtr context, CefRefPtr obj, const SString& method, const SString& value); diff --git a/src/siadrive/siadriveapp.cpp b/src/siadrive/siadriveapp.cpp index c874376..584b527 100644 --- a/src/siadrive/siadriveapp.cpp +++ b/src/siadrive/siadriveapp.cpp @@ -17,11 +17,12 @@ class FunctionHandler : public CefV8Handler { public: - FunctionHandler(const CSiaApi& siaApi, bool& appStarted, std::unique_ptr& siaDriveConfig, std::unique_ptr& siaDrive) : + FunctionHandler(const CSiaApi& siaApi, bool& appStarted, std::unique_ptr& siaDriveConfig, std::unique_ptr& siaDrive, std::function shutdownCallback) : _siaApi(siaApi), _siaDriveConfig(siaDriveConfig), _siaDrive(siaDrive), - _appStarted(appStarted) + _appStarted(appStarted), + _shutdownCallback(shutdownCallback) { } @@ -30,6 +31,7 @@ private: std::unique_ptr& _siaDriveConfig; std::unique_ptr& _siaDrive; bool& _appStarted; + std::function _shutdownCallback; private: void MountCallback(CefRefPtr context, CefRefPtr 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 context, CefRefPtr 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 handler(new FunctionHandler(*_siaApi, _appStarted, _siaDriveConfig, _siaDrive)); + CefRefPtr 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 browser, CefRefPtr frame, CefRefPtr context) -{ - ShutdownServices(); -} - void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr context, const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig) { if (CefCurrentlyOn(TID_RENDERER))