2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2024-07-22 16:48:02 +00:00
|
|
|
* Copyright (C) 2012 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 "MainWindow.h"
|
|
|
|
|
#include "SetupWizard.h"
|
2024-08-09 13:03:48 +00:00
|
|
|
#include "common/constants.h"
|
2024-08-07 14:05:18 +00:00
|
|
|
#include "gui/Logger.h"
|
|
|
|
|
#include "gui/config/AppConfig.h"
|
|
|
|
|
#include "gui/config/ConfigScopes.h"
|
2024-10-01 13:30:24 +00:00
|
|
|
#include "gui/constants.h"
|
2024-08-10 23:58:24 +00:00
|
|
|
#include "gui/diagnostic.h"
|
2024-07-26 22:53:52 +00:00
|
|
|
#include "gui/dotenv.h"
|
2024-08-03 00:17:29 +00:00
|
|
|
#include "gui/messages.h"
|
2024-08-10 23:58:24 +00:00
|
|
|
#include "gui/string_utils.h"
|
2024-10-01 13:30:24 +00:00
|
|
|
|
|
|
|
|
#ifdef DESKFLOW_GUI_HOOK_HEADER
|
|
|
|
|
#include DESKFLOW_GUI_HOOK_HEADER
|
|
|
|
|
#endif
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-08-03 00:17:29 +00:00
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QDebug>
|
2024-10-01 13:30:24 +00:00
|
|
|
#include <QGuiApplication>
|
2024-07-02 19:07:06 +00:00
|
|
|
#include <QMessageBox>
|
2024-08-03 00:17:29 +00:00
|
|
|
#include <QObject>
|
2024-08-13 23:13:17 +00:00
|
|
|
#include <QtGlobal>
|
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
|
|
|
#include <cstdlib>
|
2014-05-06 13:00:08 +00:00
|
|
|
#endif
|
|
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
using namespace deskflow::gui;
|
2024-07-22 16:48:02 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
class QThreadImpl : public QThread
|
|
|
|
|
{
|
2012-06-10 16:50:54 +00:00
|
|
|
public:
|
2024-10-17 18:04:35 +00:00
|
|
|
static void msleep(unsigned long msecs)
|
|
|
|
|
{
|
|
|
|
|
QThread::msleep(msecs);
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
};
|
|
|
|
|
|
2014-01-24 17:53:03 +00:00
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
|
bool checkMacAssistiveDevices();
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool hasArg(const QString &arg, const QStringList &args)
|
|
|
|
|
{
|
|
|
|
|
return std::ranges::any_of(args, [&arg](const QString &a) { return a == arg; });
|
2024-08-10 23:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
2024-08-03 00:17:29 +00:00
|
|
|
|
2024-08-07 14:05:18 +00:00
|
|
|
#if defined(Q_OS_MAC)
|
2024-07-02 19:07:06 +00:00
|
|
|
/* Workaround for QTBUG-40332 - "High ping when QNetworkAccessManager is
|
|
|
|
|
* instantiated" */
|
|
|
|
|
::setenv("QT_BEARER_POLL_TIMEOUT", "-1", 1);
|
2017-05-10 14:25:21 +00:00
|
|
|
#endif
|
2021-05-21 07:12:36 +00:00
|
|
|
|
2024-08-03 00:17:29 +00:00
|
|
|
QCoreApplication::setApplicationName(kAppName);
|
2024-08-09 13:03:48 +00:00
|
|
|
QCoreApplication::setOrganizationName(kAppName);
|
2024-11-11 00:47:08 +00:00
|
|
|
QGuiApplication::setDesktopFileName(QStringLiteral("org.deskflow.deskflow"));
|
2024-08-09 13:03:48 +00:00
|
|
|
|
2024-08-09 18:20:10 +00:00
|
|
|
// used as a prefix for settings paths, and must not be a url.
|
|
|
|
|
QCoreApplication::setOrganizationDomain(kOrgDomain);
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-11-09 14:29:58 +00:00
|
|
|
QApplication app(argc, argv);
|
|
|
|
|
|
|
|
|
|
#if !defined(Q_OS_MAC)
|
|
|
|
|
// causes dark mode to be used on some DE's
|
|
|
|
|
if (qEnvironmentVariable("XDG_CURRENT_DESKTOP") != QLatin1String("KDE")) {
|
2024-12-24 04:11:47 +00:00
|
|
|
QApplication::setStyle("fusion");
|
2024-11-09 14:29:58 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
2024-08-09 13:03:48 +00:00
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
qInstallMessageHandler(deskflow::gui::messages::messageHandler);
|
2024-11-27 03:16:34 +00:00
|
|
|
qInfo("%s v%s", kAppName, qPrintable(kVersion));
|
2024-08-03 00:17:29 +00:00
|
|
|
|
2024-08-09 13:03:48 +00:00
|
|
|
dotenv();
|
2024-08-07 14:05:18 +00:00
|
|
|
Logger::instance().loadEnvVars();
|
|
|
|
|
|
2014-01-24 17:53:03 +00:00
|
|
|
#if defined(Q_OS_MAC)
|
2014-01-28 11:33:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
if (app.applicationDirPath().startsWith("/Volumes/")) {
|
2024-11-01 12:59:17 +00:00
|
|
|
QString msgBody = QStringLiteral("Please drag %1 to the Applications folder, "
|
|
|
|
|
"and open it from there.");
|
|
|
|
|
QMessageBox::information(NULL, kAppName, msgBody.arg(kAppName));
|
2024-07-02 19:07:06 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!checkMacAssistiveDevices()) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2014-01-24 17:53:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
2024-08-03 00:17:29 +00:00
|
|
|
ConfigScopes configScopes;
|
2024-08-10 23:58:24 +00:00
|
|
|
|
|
|
|
|
// --no-reset
|
|
|
|
|
QStringList arguments = QCoreApplication::arguments();
|
|
|
|
|
const auto noReset = hasArg("--no-reset", arguments);
|
2024-10-17 18:04:35 +00:00
|
|
|
const auto resetEnvVar = strToTrue(qEnvironmentVariable("DESKFLOW_RESET_ALL"));
|
2024-08-10 23:58:24 +00:00
|
|
|
if (resetEnvVar && !noReset) {
|
|
|
|
|
diagnostic::clearSettings(configScopes, false);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-03 00:17:29 +00:00
|
|
|
AppConfig appConfig(configScopes);
|
2016-11-23 15:10:42 +00:00
|
|
|
|
2024-07-16 13:36:44 +00:00
|
|
|
QObject::connect(
|
2024-10-17 18:04:35 +00:00
|
|
|
&configScopes, &ConfigScopes::saving, &appConfig, [&appConfig]() { appConfig.commit(); }, Qt::DirectConnection
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
if (appConfig.wizardShouldRun()) {
|
2024-08-03 00:17:29 +00:00
|
|
|
SetupWizard wizard(appConfig);
|
|
|
|
|
auto result = wizard.exec();
|
|
|
|
|
if (result != QDialog::Accepted) {
|
|
|
|
|
qInfo("wizard cancelled, exiting");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
configScopes.save();
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
2024-08-03 00:17:29 +00:00
|
|
|
MainWindow mainWindow(configScopes, appConfig);
|
|
|
|
|
mainWindow.open();
|
2024-10-01 13:30:24 +00:00
|
|
|
|
|
|
|
|
#ifdef DESKFLOW_GUI_HOOK_START
|
|
|
|
|
DESKFLOW_GUI_HOOK_START
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-12-24 04:11:47 +00:00
|
|
|
return QApplication::exec();
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-24 17:53:03 +00:00
|
|
|
#if defined(Q_OS_MAC)
|
2024-10-17 18:04:35 +00:00
|
|
|
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
|
|
|
|
2024-07-02 19:07:06 +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
|
2024-09-17 19:00:25 +00:00
|
|
|
// tab, with a list of allowed applications. deskflow should
|
2024-07-02 19:07:06 +00:00
|
|
|
// show up there automatically, but will be unchecked.
|
2014-01-24 17:53:03 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
if (AXIsProcessTrusted()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-03-21 16:08:33 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
const void *keys[] = {kAXTrustedCheckOptionPrompt};
|
|
|
|
|
const void *trueValue[] = {kCFBooleanTrue};
|
2024-10-17 18:04:35 +00:00
|
|
|
CFDictionaryRef options = CFDictionaryCreate(NULL, keys, trueValue, 1, NULL, NULL);
|
2014-01-24 17:53:03 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
bool result = AXIsProcessTrustedWithOptions(options);
|
|
|
|
|
CFRelease(options);
|
|
|
|
|
return result;
|
2014-01-24 17:53:03 +00:00
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
// now deprecated in mavericks.
|
|
|
|
|
bool result = AXAPIEnabled();
|
|
|
|
|
if (!result) {
|
2024-11-01 12:59:17 +00:00
|
|
|
QString msgBody = QString("Please enable access to assistive devices "
|
|
|
|
|
"System Preferences -> Security & Privacy -> "
|
|
|
|
|
"Privacy -> Accessibility, then re-open %1.");
|
|
|
|
|
QMessageBox::information(NULL, kAppName, msgBody.arg(kAppName));
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
return result;
|
2014-01-24 17:53:03 +00:00
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
#endif
|