mirror of
https://github.com/lubosz/overte.git
synced 2025-04-27 17:55:27 +02:00
Remove File API and limit audio recording file location
This commit is contained in:
parent
894f8cec2b
commit
8332e41989
8 changed files with 42 additions and 56 deletions
interface
resources/qml/hifi/+webengine
src
libraries/script-engine/src
|
@ -18,27 +18,5 @@ Item {
|
|||
|
||||
|
||||
function initWebviewProfileHandlers(profile) {
|
||||
downloadUrl = currentUrl;
|
||||
if (webViewProfileSetup) return;
|
||||
webViewProfileSetup = true;
|
||||
|
||||
profile.downloadRequested.connect(function(download){
|
||||
adaptedPath = File.convertUrlToPath(downloadUrl);
|
||||
tempDir = File.getTempDir();
|
||||
download.path = tempDir + "/" + adaptedPath;
|
||||
download.accept();
|
||||
if (download.state === WebEngineDownloadItem.DownloadInterrupted) {
|
||||
console.log("download failed to complete");
|
||||
}
|
||||
})
|
||||
|
||||
profile.downloadFinished.connect(function(download){
|
||||
if (download.state === WebEngineDownloadItem.DownloadCompleted) {
|
||||
File.runUnzip(download.path, downloadUrl, autoAdd);
|
||||
} else {
|
||||
console.log("The download was corrupted, state: " + download.state);
|
||||
}
|
||||
autoAdd = false;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,6 @@
|
|||
#include <EntityScriptServerLogClient.h>
|
||||
#include <EntityScriptingInterface.h>
|
||||
#include <ErrorDialog.h>
|
||||
#include <FileScriptingInterface.h>
|
||||
#include <Finally.h>
|
||||
#include <FingerprintUtils.h>
|
||||
#include <FramebufferCache.h>
|
||||
|
@ -3414,9 +3413,9 @@ void Application::onDesktopRootContextCreated(QQmlContext* surfaceContext) {
|
|||
surfaceContext->setContextProperty("Controller", DependencyManager::get<controller::ScriptingInterface>().data());
|
||||
surfaceContext->setContextProperty("Entities", DependencyManager::get<EntityScriptingInterface>().data());
|
||||
surfaceContext->setContextProperty("Performance", new PerformanceScriptingInterface());
|
||||
_fileDownload = new FileScriptingInterface(engine);
|
||||
_fileDownload = new ArchiveDownloadInterface(engine);
|
||||
surfaceContext->setContextProperty("File", _fileDownload);
|
||||
connect(_fileDownload, &FileScriptingInterface::unzipResult, this, &Application::handleUnzip);
|
||||
connect(_fileDownload, &ArchiveDownloadInterface::unzipResult, this, &Application::handleUnzip);
|
||||
surfaceContext->setContextProperty("MyAvatar", getMyAvatar().get());
|
||||
surfaceContext->setContextProperty("Messages", DependencyManager::get<MessagesClient>().data());
|
||||
surfaceContext->setContextProperty("Recording", DependencyManager::get<RecordingScriptingInterface>().data());
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
#include <AbstractViewStateInterface.h>
|
||||
#include <EntityEditPacketSender.h>
|
||||
#include <EntityTreeRenderer.h>
|
||||
#include <FileScriptingInterface.h>
|
||||
#include "ArchiveDownloadInterface.h"
|
||||
#include <input-plugins/KeyboardMouseDevice.h>
|
||||
#include <input-plugins/TouchscreenDevice.h>
|
||||
#include <input-plugins/TouchscreenVirtualPadDevice.h>
|
||||
|
@ -425,7 +425,7 @@ public slots:
|
|||
|
||||
void handleUnzip(QString sourceFile, QStringList destinationFile, bool autoAdd, bool isZip, bool isBlocks);
|
||||
|
||||
FileScriptingInterface* getFileDownloadInterface() { return _fileDownload; }
|
||||
ArchiveDownloadInterface* getFileDownloadInterface() { return _fileDownload; }
|
||||
|
||||
void handleLocalServerConnection() const;
|
||||
void readArgumentsFromLocalSocket() const;
|
||||
|
@ -820,7 +820,7 @@ private:
|
|||
QTimer _addAssetToWorldErrorTimer;
|
||||
mutable QTimer _entityServerConnectionTimer;
|
||||
|
||||
FileScriptingInterface* _fileDownload;
|
||||
ArchiveDownloadInterface* _fileDownload;
|
||||
AudioInjectorPointer _snapshotSoundInjector;
|
||||
SharedSoundPointer _snapshotSound;
|
||||
SharedSoundPointer _sampleSound;
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#include "AudioClient.h"
|
||||
#include "AudioHelpers.h"
|
||||
#include "ui/AvatarInputs.h"
|
||||
#include "ui/Snapshot.h"
|
||||
#include "AccountManager.h"
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
|
@ -58,9 +60,17 @@ Audio::Audio() : _devices(_contextIsHMD) {
|
|||
onContextChanged();
|
||||
}
|
||||
|
||||
bool Audio::startRecording(const QString& filepath) {
|
||||
bool Audio::startRecording() {
|
||||
return resultWithWriteLock<bool>([&] {
|
||||
return DependencyManager::get<AudioClient>()->startRecording(filepath);
|
||||
const QString FILENAME_PATH_FORMAT = "overte-snap-by-%1-on-%2";
|
||||
const QString DEFAULT_FORMAT = "wav";
|
||||
const QString DATETIME_FORMAT = "yyyy-MM-dd_hh-mm-ss";
|
||||
|
||||
QString username = DependencyManager::get<AccountManager>()->getAccountInfo().getUsername();
|
||||
QString filepath = DependencyManager::get<Snapshot>()->_snapshotsLocation.get();
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QString filename = FILENAME_PATH_FORMAT.arg(username, now.toString(DATETIME_FORMAT)) + "." + DEFAULT_FORMAT;
|
||||
return DependencyManager::get<AudioClient>()->startRecording(filepath + "/" + filename);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -301,18 +301,17 @@ public:
|
|||
* @returns {boolean} <code>true</code> if the specified file could be opened and audio recording has started, otherwise
|
||||
* <code>false</code>.
|
||||
* @example <caption>Make a 10 second audio recording.</caption>
|
||||
* var filename = File.getTempDir() + "/audio.wav";
|
||||
* if (Audio.startRecording(filename)) {
|
||||
* if (Audio.startRecording()) {
|
||||
* Script.setTimeout(function () {
|
||||
* Audio.stopRecording();
|
||||
* print("Audio recording made in: " + filename);
|
||||
* print("Audio recording finished.");
|
||||
* }, 10000);
|
||||
*
|
||||
* } else {
|
||||
* print("Could not make an audio recording in: " + filename);
|
||||
* print("Could not make an audio recording file.");
|
||||
* }
|
||||
*/
|
||||
Q_INVOKABLE bool startRecording(const QString& filename);
|
||||
Q_INVOKABLE bool startRecording();
|
||||
|
||||
/*@jsdoc
|
||||
* Finishes making an audio recording started with {@link Audio.startRecording|startRecording}.
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
//
|
||||
// FileScriptingInterface.cpp
|
||||
// ArchiveDownloadInterface.cpp
|
||||
// libraries/script-engine/src
|
||||
//
|
||||
// Created by Elisa Lupin-Jimenez on 6/28/16.
|
||||
// Copyright 2016 High Fidelity, Inc.
|
||||
// Copyright 2023 Overte e.V.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "FileScriptingInterface.h"
|
||||
#include "ArchiveDownloadInterface.h"
|
||||
|
||||
#include <QtCore/QTemporaryDir>
|
||||
#include <QtCore/QDir>
|
||||
|
@ -33,11 +34,11 @@
|
|||
#include "ScriptEngineLogging.h"
|
||||
|
||||
|
||||
FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent) {
|
||||
ArchiveDownloadInterface::ArchiveDownloadInterface(QObject* parent) : QObject(parent) {
|
||||
// nothing for now
|
||||
}
|
||||
|
||||
void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd, bool isZip, bool isBlocks) {
|
||||
void ArchiveDownloadInterface::runUnzip(QString path, QUrl url, bool autoAdd, bool isZip, bool isBlocks) {
|
||||
QString fileName = "/" + path.section("/", -1);
|
||||
QString tempDir = path;
|
||||
if (!isZip) {
|
||||
|
@ -71,7 +72,7 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd, bool
|
|||
|
||||
}
|
||||
|
||||
QStringList FileScriptingInterface::unzipFile(QString path, QString tempDir) {
|
||||
QStringList ArchiveDownloadInterface::unzipFile(QString path, QString tempDir) {
|
||||
#if defined(Q_OS_ANDROID)
|
||||
// FIXME quazip hasn't been built on the android toolchain
|
||||
return QStringList();
|
||||
|
@ -94,7 +95,7 @@ QStringList FileScriptingInterface::unzipFile(QString path, QString tempDir) {
|
|||
}
|
||||
|
||||
// fix to check that we are only referring to a temporary directory
|
||||
bool FileScriptingInterface::isTempDir(QString tempDir) {
|
||||
bool ArchiveDownloadInterface::isTempDir(QString tempDir) {
|
||||
QString folderName = "/" + tempDir.section("/", -1);
|
||||
QString tempContainer = tempDir;
|
||||
tempContainer.remove(folderName);
|
||||
|
@ -106,7 +107,7 @@ bool FileScriptingInterface::isTempDir(QString tempDir) {
|
|||
return (testContainer == tempContainer);
|
||||
}
|
||||
|
||||
bool FileScriptingInterface::hasModel(QStringList fileList) {
|
||||
bool ArchiveDownloadInterface::hasModel(QStringList fileList) {
|
||||
for (int i = 0; i < fileList.size(); i++) {
|
||||
if (fileList.at(i).toLower().contains(".fbx") || fileList.at(i).toLower().contains(".obj")) {
|
||||
return true;
|
||||
|
@ -115,14 +116,14 @@ bool FileScriptingInterface::hasModel(QStringList fileList) {
|
|||
return false;
|
||||
}
|
||||
|
||||
QString FileScriptingInterface::getTempDir() {
|
||||
QString ArchiveDownloadInterface::getTempDir() {
|
||||
QTemporaryDir dir;
|
||||
dir.setAutoRemove(false);
|
||||
return dir.path();
|
||||
// do something to delete this temp dir later
|
||||
}
|
||||
|
||||
QString FileScriptingInterface::convertUrlToPath(QUrl url) {
|
||||
QString ArchiveDownloadInterface::convertUrlToPath(QUrl url) {
|
||||
QString newUrl;
|
||||
QString oldUrl = url.toString();
|
||||
newUrl = oldUrl.section("filename=", 1, 1);
|
||||
|
@ -130,10 +131,10 @@ QString FileScriptingInterface::convertUrlToPath(QUrl url) {
|
|||
}
|
||||
|
||||
// this function is not in use
|
||||
void FileScriptingInterface::downloadZip(QString path, const QString link) {
|
||||
void ArchiveDownloadInterface::downloadZip(QString path, const QString link) {
|
||||
QUrl url = QUrl(link);
|
||||
auto request = DependencyManager::get<ResourceManager>()->createResourceRequest(
|
||||
nullptr, url, true, -1, "FileScriptingInterface::downloadZip");
|
||||
nullptr, url, true, -1, "ArchiveDownloadInterface::downloadZip");
|
||||
connect(request, &ResourceRequest::finished, this, [this, path]{
|
||||
unzipFile(path, ""); // so intellisense isn't mad
|
||||
});
|
||||
|
@ -141,7 +142,7 @@ void FileScriptingInterface::downloadZip(QString path, const QString link) {
|
|||
}
|
||||
|
||||
// this function is not in use
|
||||
void FileScriptingInterface::recursiveFileScan(QFileInfo file, QString* dirName) {
|
||||
void ArchiveDownloadInterface::recursiveFileScan(QFileInfo file, QString* dirName) {
|
||||
/*if (!file.isDir()) {
|
||||
return;
|
||||
}*/
|
|
@ -1,9 +1,10 @@
|
|||
//
|
||||
// FileScriptingInterface.h
|
||||
// ArchiveDownloadInterface.h
|
||||
// libraries/script-engine/src
|
||||
//
|
||||
// Created by Elisa Lupin-Jimenez on 6/28/16.
|
||||
// Copyright 2016 High Fidelity, Inc.
|
||||
// Copyright 2023 Overte e.V.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
@ -12,10 +13,11 @@
|
|||
/// @addtogroup ScriptEngine
|
||||
/// @{
|
||||
|
||||
#ifndef hifi_FileScriptingInterface_h
|
||||
#define hifi_FileScriptingInterface_h
|
||||
#ifndef hifi_ArchiveDownloadInterface_h
|
||||
#define hifi_ArchiveDownloadInterface_h
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QUrl>
|
||||
#include <QFileInfo>
|
||||
#include <QString>
|
||||
|
||||
|
@ -30,12 +32,11 @@
|
|||
* @hifi-server-entity
|
||||
* @hifi-assignment-client
|
||||
*/
|
||||
/// Provides the <code><a href="https://apidocs.overte.org/File.html">File</a></code> scripting API
|
||||
class FileScriptingInterface : public QObject {
|
||||
class ArchiveDownloadInterface : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FileScriptingInterface(QObject* parent);
|
||||
ArchiveDownloadInterface(QObject* parent);
|
||||
|
||||
public slots:
|
||||
|
||||
|
@ -116,6 +117,6 @@ private:
|
|||
|
||||
};
|
||||
|
||||
#endif // hifi_FileScriptingInterface_h
|
||||
#endif // hifi_ArchiveDownloadInterface_h
|
||||
|
||||
/// @}
|
|
@ -42,7 +42,6 @@
|
|||
#include "AssetScriptingInterface.h"
|
||||
#include "BatchLoader.h"
|
||||
#include "EventTypes.h"
|
||||
#include "FileScriptingInterface.h" // unzip project
|
||||
#include "MenuItemProperties.h"
|
||||
#include "ScriptCache.h"
|
||||
#include "ScriptContext.h"
|
||||
|
@ -767,7 +766,6 @@ void ScriptManager::init() {
|
|||
scriptEngine->registerGlobalObject("Messages", DependencyManager::get<MessagesClient>().data());
|
||||
}
|
||||
|
||||
scriptEngine->registerGlobalObject("File", new FileScriptingInterface(this));
|
||||
scriptEngine->registerGlobalObject("console", &_consoleScriptingInterface);
|
||||
scriptEngine->registerFunction("console", "info", ConsoleScriptingInterface::info, scriptEngine->currentContext()->argumentCount());
|
||||
scriptEngine->registerFunction("console", "log", ConsoleScriptingInterface::log, scriptEngine->currentContext()->argumentCount());
|
||||
|
|
Loading…
Reference in a new issue