diff --git a/src/Info.plist b/src/Info.plist
index ee8eda39b..35b8e922b 100644
--- a/src/Info.plist
+++ b/src/Info.plist
@@ -52,6 +52,8 @@
qbittorrent
CFBundleIdentifier
org.qbittorrent
+ NSAppleScriptEnabled
+ YES
NSHumanReadableCopyright
Copyright © 2006-2012 Christophe Dumez
UTExportedTypeDeclarations
diff --git a/src/main.cpp b/src/main.cpp
index 13b2e6e20..8aef644d0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -307,6 +307,9 @@ int main(int argc, char *argv[]) {
QObject::connect(&app, SIGNAL(messageReceived(const QString&)),
&window, SLOT(processParams(const QString&)));
app.setActivationWindow(&window);
+#ifdef Q_WS_MAC
+ static_cast(&app)->setReadyToProcessEvents();
+#endif // Q_WS_MAC
#else
// Load Headless class
HeadlessLoader loader(torrentCmdLine);
diff --git a/src/qmacapplication.cpp b/src/qmacapplication.cpp
index e8680255e..1361db949 100644
--- a/src/qmacapplication.cpp
+++ b/src/qmacapplication.cpp
@@ -34,11 +34,21 @@
#include "qmacapplication.h"
QMacApplication::QMacApplication(QString appid, int &argc, char** argv) :
- QtSingleApplication(appid, argc, argv)
+ QtSingleApplication(appid, argc, argv),
+ m_readyToProcessEvents(false)
{
qDebug("Constructing a QMacApplication to receive file open events");
}
+void QMacApplication::setReadyToProcessEvents()
+{
+ m_readyToProcessEvents = true;
+ if (!m_torrentsQueue.isEmpty()) {
+ emit newFileOpenMacEvent(m_torrentsQueue.join("|"));
+ m_torrentsQueue.clear();
+ }
+}
+
bool QMacApplication::event(QEvent * ev) {
switch (ev->type()) {
case QEvent::FileOpen:
@@ -49,7 +59,10 @@ bool QMacApplication::event(QEvent * ev) {
path = static_cast(ev)->url().toString();
}
qDebug("Received a mac file open event: %s", qPrintable(path));
- emit newFileOpenMacEvent(path);
+ if (m_readyToProcessEvents)
+ emit newFileOpenMacEvent(path);
+ else
+ m_torrentsQueue.append(path);
return true;
}
default:
diff --git a/src/qmacapplication.h b/src/qmacapplication.h
index 55b6e18fd..8148a4e13 100644
--- a/src/qmacapplication.h
+++ b/src/qmacapplication.h
@@ -31,12 +31,14 @@
#define QMACAPPLICATION_H
#include "qtsingleapplication.h"
+#include
class QMacApplication : public QtSingleApplication
{
Q_OBJECT
public:
explicit QMacApplication(QString appid, int &argc, char** argv);
+ void setReadyToProcessEvents();
signals:
void newFileOpenMacEvent(const QString &path);
@@ -44,6 +46,9 @@ signals:
protected:
bool event(QEvent *);
+private:
+ bool m_readyToProcessEvents;
+ QStringList m_torrentsQueue;
};
#endif // QMACAPPLICATION_H