desktop platform support

This commit is contained in:
Max Risuhin 2018-02-03 22:53:21 +02:00
parent e20241e49a
commit d93c7be66f
No known key found for this signature in database
GPG Key ID: BF733F5ACA0B4448
4 changed files with 269 additions and 1 deletions

7
desktop/CMakeLists.txt Normal file
View File

@ -0,0 +1,7 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(REACT_NATIVE_DESKTOP_EXTERNAL_MODULES_TYPE_NAMES ${REACT_NATIVE_DESKTOP_EXTERNAL_MODULES_TYPE_NAMES}
\"RNFSManager\" PARENT_SCOPE)
set(REACT_NATIVE_DESKTOP_EXTERNAL_MODULES_SRC ${REACT_NATIVE_DESKTOP_EXTERNAL_MODULES_SRC}
${CMAKE_CURRENT_SOURCE_DIR}/rnfsmanager.cpp PARENT_SCOPE)

193
desktop/rnfsmanager.cpp Normal file
View File

@ -0,0 +1,193 @@
/**
* Copyright (c) 2017-present, Status Research and Development GmbH.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include "rnfsmanager.h"
#include "bridge.h"
#include "eventdispatcher.h"
#include <QDebug>
#include <QFileInfo>
#include <QDir>
#include <QVariant>
#include <QByteArray>
namespace {
struct RegisterQMLMetaType {
RegisterQMLMetaType() {
qRegisterMetaType<RNFSManager*>();
}
} registerMetaType;
} // namespace
class RNFSManagerPrivate {
public:
Bridge* bridge = nullptr;
};
RNFSManager::RNFSManager(QObject* parent) : QObject(parent), d_ptr(new RNFSManagerPrivate) {}
RNFSManager::~RNFSManager() {}
void RNFSManager::setBridge(Bridge* bridge) {
Q_D(RNFSManager);
d->bridge = bridge;
}
QString RNFSManager::moduleName() {
return "RNFSManager";
}
QList<ModuleMethod*> RNFSManager::methodsToExport() {
return QList<ModuleMethod*>{};
}
QVariantMap RNFSManager::constantsToExport() {
return QVariantMap();
}
void RNFSManager::readDir(QString dirPath, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
}
void RNFSManager::exists(QString filepath, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
}
void RNFSManager::stat(QString filepath, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
}
void RNFSManager::writeFile(QString filepath, QString base64Content, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
}
void RNFSManager::appendFile(QString filepath, QString base64Content, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
}
void RNFSManager::write(QString filepath, QString base64Content, int position, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
}
void RNFSManager::unlink(QString filepath, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
}
void RNFSManager::mkdir(QString filepath, QVariantMap options, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
}
void RNFSManager::readFile(QString filepath, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
Q_D(RNFSManager);
QFile file(filepath);
if (!file.open(QIODevice::ReadOnly)) {
reject(d->bridge, QVariantList());
return;
}
QByteArray fileData = file.readAll().toBase64();
resolve(d->bridge, QVariantList{{QVariant(fileData)}});
}
void RNFSManager::read(QString filepath, int length, int position, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
}
void RNFSManager::hash(QString filepath, QString algorithm, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
}
void RNFSManager::moveFile(QString filepath, QString destPath, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
Q_D(RNFSManager);
if (copyRecursively(filepath, destPath) &&
removeRecursively(filepath)) {
resolve(d->bridge, QVariantList());
} else {
reject(d->bridge, QVariantList());
}
}
void RNFSManager::copyFile(QString filepath, QString destPath, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
}
void RNFSManager::downloadFile(QVariantMap options, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
}
void RNFSManager::stopDownload(int jobId) {
}
void RNFSManager::resumeDownload(int jobId) {
}
void RNFSManager::isResumable(int jobId, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
}
void RNFSManager::uploadFiles(QVariantMap options, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
}
void RNFSManager::stopUpload(int jobId) {
}
void RNFSManager::pathForBundle(QString bundleNamed, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
}
void RNFSManager::pathForGroup(QString groupId, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
}
void RNFSManager::getFSInfo(const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
}
void RNFSManager::touch(QString filepath, QDateTime mtime, QDateTime ctime, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
}
bool RNFSManager::copyRecursively(const QString& src, const QString& dst) {
QFileInfo filePathFileInfo(src);
if (filePathFileInfo.isDir()) {
QDir dstDir(dst);
if (!dstDir.isRoot()) {
dstDir.cdUp();
if (!dstDir.mkdir(QFileInfo(dst).fileName()))
return false;
}
QDir srcDir(src);
QStringList itemNames = srcDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::System | QDir::Hidden );
foreach (const QString &itemName, itemNames) {
if (!copyRecursively(src + QDir::separator() + itemName, dst + QDir::separator() + itemName))
return false;
}
} else {
return QFile::copy(src, dst);
}
return true;
}
bool RNFSManager::removeRecursively(const QString& path) {
QFileInfo filePathFileInfo(path);
if (filePathFileInfo.isDir()) {
QDir dir(path);
return dir.removeRecursively();
} else {
return QFile::remove(path);
}
}

67
desktop/rnfsmanager.h Normal file
View File

@ -0,0 +1,67 @@
/**
* Copyright (c) 2017-present, Status Research and Development GmbH.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#ifndef RNFSMANAGER_H
#define RNFSMANAGER_H
#include "moduleinterface.h"
#include <QVariantMap>
#include <QDateTime>
class RNFSManagerPrivate;
class RNFSManager : public QObject, public ModuleInterface {
Q_OBJECT
Q_INTERFACES(ModuleInterface)
Q_DECLARE_PRIVATE(RNFSManager)
public:
Q_INVOKABLE RNFSManager(QObject* parent = 0);
~RNFSManager();
void setBridge(Bridge* bridge) override;
QString moduleName() override;
QList<ModuleMethod*> methodsToExport() override;
QVariantMap constantsToExport() override;
Q_INVOKABLE REACT_PROMISE void readDir(QString dirPath, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
Q_INVOKABLE REACT_PROMISE void exists(QString filepath, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
Q_INVOKABLE REACT_PROMISE void stat(QString filepath, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
Q_INVOKABLE REACT_PROMISE void writeFile(QString filepath, QString base64Content, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
Q_INVOKABLE REACT_PROMISE void appendFile(QString filepath, QString base64Content, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
Q_INVOKABLE REACT_PROMISE void write(QString filepath, QString base64Content, int position, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
Q_INVOKABLE REACT_PROMISE void unlink(QString filepath, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
Q_INVOKABLE REACT_PROMISE void mkdir(QString filepath, QVariantMap options, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
Q_INVOKABLE REACT_PROMISE void readFile(QString filepath, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
Q_INVOKABLE REACT_PROMISE void read(QString filepath, int length, int position, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
Q_INVOKABLE REACT_PROMISE void hash(QString filepath, QString algorithm, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
Q_INVOKABLE REACT_PROMISE void moveFile(QString filepath, QString destPath, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
Q_INVOKABLE REACT_PROMISE void copyFile(QString filepath, QString destPath, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
Q_INVOKABLE REACT_PROMISE void downloadFile(QVariantMap options, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
Q_INVOKABLE void stopDownload(int jobId);
Q_INVOKABLE void resumeDownload(int jobId);
Q_INVOKABLE REACT_PROMISE void isResumable(int jobId, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
Q_INVOKABLE REACT_PROMISE void uploadFiles(QVariantMap options, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
Q_INVOKABLE void stopUpload(int jobId);
Q_INVOKABLE REACT_PROMISE void pathForBundle(QString bundleNamed, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
Q_INVOKABLE REACT_PROMISE void pathForGroup(QString groupId, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
Q_INVOKABLE REACT_PROMISE void getFSInfo(const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
Q_INVOKABLE REACT_PROMISE void touch(QString filepath, QDateTime mtime, QDateTime ctime, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject);
private:
QScopedPointer<RNFSManagerPrivate> d_ptr;
bool copyRecursively(const QString& src, const QString& dst);
bool removeRecursively(const QString& path);
};
#endif // RNFSMANAGER_H

View File

@ -20,7 +20,8 @@
"filesystem", "filesystem",
"download", "download",
"upload", "upload",
"file-transfer" "file-transfer",
"desktop"
], ],
"author": "Johannes Lumpe <johannes@lum.pe> (https://github.com/johanneslumpe)", "author": "Johannes Lumpe <johannes@lum.pe> (https://github.com/johanneslumpe)",
"license": "MIT", "license": "MIT",