Merge pull request #18 from druiz17/serverless-domains

Support file:///~/path/to/file/ format when loading domain from goto
This commit is contained in:
Seth Alves 2018-02-16 15:14:45 -08:00 committed by GitHub
commit 9ba11ba3e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 2 deletions

View file

@ -22,6 +22,7 @@
#include <NumericalConstants.h>
#include <SettingHandle.h>
#include <UUID.h>
#include <PathUtils.h>
#include "AddressManager.h"
#include "NodeList.h"
@ -309,10 +310,13 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl, LookupTrigger trigger) {
} else if (lookupUrl.scheme() == "http" || lookupUrl.scheme() == "https" || lookupUrl.scheme() == "file") {
qDebug() << "QQQQ file or http before serverless domain" << lookupUrl.toString();
_previousLookup.clear();
QUrl domainUrl = lookupUrl;
const QString path = PathUtils::expandToAppAbsolutePath(lookupUrl.path());
domainUrl.setPath(path);
emit setServersEnabled(false);
setDomainInfo(lookupUrl, QString(), 0, trigger);
setDomainInfo(domainUrl, QString(), 0, trigger);
DependencyManager::get<NodeList>()->getDomainHandler().setIsConnected(true);
emit loadServerlessDomain(lookupUrl);
emit loadServerlessDomain(domainUrl);
emit lookupResultsFinished();
return true;
}

View file

@ -116,10 +116,30 @@ const QString& PathUtils::resourcesUrl() {
return staticResourcePath;
}
QString applicationAbsolutePath() {
QString path;
#if defined(Q_OS_OSX)
path = QCoreApplication::applicationDirPath() + "/../";
#elif defined(Q_OS_ANDROID)
path = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
#else
path = QCoreApplication::applicationDirPath() + "/";
#endif
return path;
}
QUrl PathUtils::resourcesUrl(const QString& relativeUrl) {
return QUrl(resourcesUrl() + relativeUrl);
}
QString PathUtils::expandToAppAbsolutePath(const QString& filePath) {
QString path = filePath;
if (path.startsWith("/~/")) {
path.replace(1, 2, applicationAbsolutePath());
}
return path;
}
const QString& PathUtils::qmlBaseUrl() {
static const QString staticResourcePath = resourcesUrl() + "qml/";
return staticResourcePath;

View file

@ -37,6 +37,7 @@ public:
static QUrl resourcesUrl(const QString& relative);
static const QString& resourcesPath();
static const QString& qmlBaseUrl();
static QString expandToAppAbsolutePath(const QString& filePath);
static QUrl qmlUrl(const QString& relative);
#ifdef DEV_BUILD
static const QString& projectRootPath();