2012-06-10 16:50:54 +00:00
|
|
|
/*
|
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2016-09-07 14:24:00 +00:00
|
|
|
* Copyright (C) 2012-2016 Symless Ltd.
|
2012-06-10 16:50:54 +00:00
|
|
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
2016-10-17 16:57:14 +00:00
|
|
|
*
|
2012-06-10 16:50:54 +00:00
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
2015-05-03 02:33:52 +00:00
|
|
|
* found in the file LICENSE that should have accompanied this file.
|
2016-10-17 16:57:14 +00:00
|
|
|
*
|
2012-06-10 16:50:54 +00:00
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "QSynergyApplication.h"
|
2016-10-17 16:57:14 +00:00
|
|
|
#include "LicenseManager.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
#include "MainWindow.h"
|
|
|
|
|
#include "AppConfig.h"
|
|
|
|
|
#include "SetupWizard.h"
|
2021-05-14 12:27:04 +00:00
|
|
|
#include "SetupWizardBlocker.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
|
#include <QtGui>
|
2014-02-14 16:21:02 +00:00
|
|
|
#include <QMessageBox>
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2014-01-24 17:53:03 +00:00
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
|
#include <Carbon/Carbon.h>
|
2017-05-10 14:25:21 +00:00
|
|
|
#endif
|
2014-05-06 13:00:08 +00:00
|
|
|
|
2017-05-10 14:25:21 +00:00
|
|
|
#ifdef Q_OS_DARWIN
|
|
|
|
|
#include <cstdlib>
|
2014-05-06 13:00:08 +00:00
|
|
|
#endif
|
|
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
class QThreadImpl : public QThread
|
|
|
|
|
{
|
|
|
|
|
public:
|
2018-06-07 15:22:49 +00:00
|
|
|
static void msleep(unsigned long msecs)
|
|
|
|
|
{
|
|
|
|
|
QThread::msleep(msecs);
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
};
|
|
|
|
|
|
2020-03-19 15:35:29 +00:00
|
|
|
QString getSystemSettingPath();
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2014-01-24 17:53:03 +00:00
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
|
bool checkMacAssistiveDevices();
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
|
{
|
2017-05-10 14:25:21 +00:00
|
|
|
#ifdef Q_OS_DARWIN
|
|
|
|
|
/* Workaround for QTBUG-40332 - "High ping when QNetworkAccessManager is instantiated" */
|
|
|
|
|
::setenv ("QT_BEARER_POLL_TIMEOUT", "-1", 1);
|
|
|
|
|
#endif
|
2021-05-05 12:16:38 +00:00
|
|
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
2018-06-07 15:22:49 +00:00
|
|
|
QCoreApplication::setOrganizationName("Synergy");
|
|
|
|
|
QCoreApplication::setOrganizationDomain("http://symless.com/");
|
|
|
|
|
QCoreApplication::setApplicationName("Synergy");
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2018-06-07 15:22:49 +00:00
|
|
|
QSynergyApplication app(argc, argv);
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2014-01-24 17:53:03 +00:00
|
|
|
#if defined(Q_OS_MAC)
|
2014-01-28 11:33:54 +00:00
|
|
|
|
2018-06-07 15:22:49 +00:00
|
|
|
if (app.applicationDirPath().startsWith("/Volumes/")) {
|
|
|
|
|
QMessageBox::information(
|
|
|
|
|
NULL, "Synergy",
|
|
|
|
|
"Please drag Synergy to the Applications folder, and open it from there.");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!checkMacAssistiveDevices())
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2014-01-24 17:53:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
2013-10-15 15:46:02 +00:00
|
|
|
#ifndef Q_OS_WIN
|
2018-06-07 15:22:49 +00:00
|
|
|
QApplication::setQuitOnLastWindowClosed(false);
|
2013-10-15 15:46:02 +00:00
|
|
|
#endif
|
2020-04-23 17:11:20 +00:00
|
|
|
|
|
|
|
|
AppConfig appConfig;
|
2018-06-07 15:22:49 +00:00
|
|
|
qRegisterMetaType<Edition>("Edition");
|
|
|
|
|
#ifndef SYNERGY_ENTERPRISE
|
|
|
|
|
LicenseManager licenseManager (&appConfig);
|
|
|
|
|
#endif
|
2013-05-29 20:46:24 +00:00
|
|
|
|
2018-06-07 15:22:49 +00:00
|
|
|
app.switchTranslator(appConfig.language());
|
2013-05-29 20:46:24 +00:00
|
|
|
|
2018-06-07 15:22:49 +00:00
|
|
|
#ifdef SYNERGY_ENTERPRISE
|
2020-07-08 12:17:06 +00:00
|
|
|
MainWindow mainWindow(appConfig);
|
2018-06-07 15:22:49 +00:00
|
|
|
#else
|
2020-02-25 14:41:11 +00:00
|
|
|
MainWindow mainWindow(appConfig, licenseManager);
|
2018-06-07 15:22:49 +00:00
|
|
|
#endif
|
2016-11-23 15:10:42 +00:00
|
|
|
|
2018-06-07 15:22:49 +00:00
|
|
|
QObject::connect(dynamic_cast<QObject*>(&app), SIGNAL(aboutToQuit()),
|
|
|
|
|
&mainWindow, SLOT(saveSettings()));
|
2016-11-23 15:10:42 +00:00
|
|
|
|
2021-05-14 12:27:04 +00:00
|
|
|
std::unique_ptr<SetupWizardBlocker> setupBlocker;
|
|
|
|
|
if (qgetenv("XDG_SESSION_TYPE") == "wayland")
|
|
|
|
|
{
|
|
|
|
|
setupBlocker.reset(new SetupWizardBlocker(mainWindow, SetupWizardBlocker::qBlockerType::waylandDetected));
|
|
|
|
|
setupBlocker->show();
|
|
|
|
|
return QApplication::exec();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-21 10:46:01 +00:00
|
|
|
std::unique_ptr<SetupWizard> setupWizard;
|
2018-06-07 15:22:49 +00:00
|
|
|
if (appConfig.wizardShouldRun())
|
|
|
|
|
{
|
2021-03-23 07:49:52 +00:00
|
|
|
setupWizard.reset(new SetupWizard(mainWindow));
|
2021-01-21 10:46:01 +00:00
|
|
|
setupWizard->show();
|
2018-06-07 15:22:49 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mainWindow.open();
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2018-06-07 15:22:49 +00:00
|
|
|
return app.exec();
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-19 15:35:29 +00:00
|
|
|
|
2014-01-24 17:53:03 +00:00
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
|
bool checkMacAssistiveDevices()
|
|
|
|
|
{
|
2014-02-14 16:21:02 +00:00
|
|
|
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 // mavericks
|
2014-11-06 17:05:38 +00:00
|
|
|
|
2018-06-07 15:22:49 +00:00
|
|
|
// new in mavericks, applications are trusted individually
|
|
|
|
|
// with use of the accessibility api. this call will show a
|
|
|
|
|
// prompt which can show the security/privacy/accessibility
|
|
|
|
|
// tab, with a list of allowed applications. synergy should
|
|
|
|
|
// show up there automatically, but will be unchecked.
|
2014-01-24 17:53:03 +00:00
|
|
|
|
2018-06-07 15:22:49 +00:00
|
|
|
if (AXIsProcessTrusted()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-03-21 16:08:33 +00:00
|
|
|
|
2018-06-07 15:22:49 +00:00
|
|
|
const void* keys[] = { kAXTrustedCheckOptionPrompt };
|
|
|
|
|
const void* trueValue[] = { kCFBooleanTrue };
|
|
|
|
|
CFDictionaryRef options = CFDictionaryCreate(NULL, keys, trueValue, 1, NULL, NULL);
|
2014-01-24 17:53:03 +00:00
|
|
|
|
2018-06-07 15:22:49 +00:00
|
|
|
bool result = AXIsProcessTrustedWithOptions(options);
|
|
|
|
|
CFRelease(options);
|
|
|
|
|
return result;
|
2014-01-24 17:53:03 +00:00
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
2018-06-07 15:22:49 +00:00
|
|
|
// now deprecated in mavericks.
|
|
|
|
|
bool result = AXAPIEnabled();
|
|
|
|
|
if (!result) {
|
|
|
|
|
QMessageBox::information(
|
|
|
|
|
NULL, "Synergy",
|
|
|
|
|
"Please enable access to assistive devices "
|
|
|
|
|
"System Preferences -> Security & Privacy -> "
|
|
|
|
|
"Privacy -> Accessibility, then re-open Synergy.");
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2014-01-24 17:53:03 +00:00
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
#endif
|