|
|
|
@@ -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,10 +296,9 @@ void CSiaDriveApp::OnContextInitialized()
|
|
|
|
|
|
|
|
|
|
void CSiaDriveApp::ShutdownServices()
|
|
|
|
|
{
|
|
|
|
|
if (CefCurrentlyOn(TID_RENDERER))
|
|
|
|
|
{
|
|
|
|
|
if (_refreshThread)
|
|
|
|
|
{
|
|
|
|
|
_appStarted = false;
|
|
|
|
|
_refreshThread->StopAutoThread();
|
|
|
|
|
_refreshThread.reset(nullptr);
|
|
|
|
|
}
|
|
|
|
@@ -295,16 +308,6 @@ void CSiaDriveApp::ShutdownServices()
|
|
|
|
|
_siaDrive->Unmount();
|
|
|
|
|
_siaDrive.reset(nullptr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CefPostTask(TID_RENDERER, base::Bind(&CSiaDriveApp::ShutdownServices, this));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSiaDriveApp::OnContextReleased(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)
|
|
|
|
|
{
|
|
|
|
|
ShutdownServices();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig)
|
|
|
|
|