diff --git a/linux/ckb-next.autostart.desktop.in b/linux/ckb-next.autostart.desktop.in deleted file mode 100644 index cd37c01d..00000000 --- a/linux/ckb-next.autostart.desktop.in +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright 2017-2018 ckb-next Development Team -# Distributed under the terms of the GNU General Public License v2 - -[Desktop Entry] -Version=1.0 -Type=Application -Name=ckb-next -Comment=Corsair keyboard driver user interface -Keywords=ckb;corsair;keyboard;rgb; -Categories=Settings;System; -TryExec=@CMAKE_INSTALL_PREFIX@/bin/ckb-next -Exec=@CMAKE_INSTALL_PREFIX@/bin/ckb-next --background -Icon=ckb-next -StartupNotify=true diff --git a/linux/ckb-next.desktop.in b/linux/ckb-next.desktop.in index d541afea..722c33bf 100644 --- a/linux/ckb-next.desktop.in +++ b/linux/ckb-next.desktop.in @@ -9,6 +9,6 @@ Comment=Corsair keyboard driver user interface Keywords=ckb;corsair;keyboard;rgb; Categories=Settings;System; TryExec=@CMAKE_INSTALL_PREFIX@/bin/ckb-next -Exec=@CMAKE_INSTALL_PREFIX@/bin/ckb-next +Exec=@CMAKE_INSTALL_PREFIX@/bin/ckb-next@CKB_NEXT_BACKGROUND_ARG@ Icon=ckb-next StartupNotify=true diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index f6d8aa34..4c7e14e9 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -126,7 +126,6 @@ if (MACOS OR LINUX) animdetailsdialog.cpp animscript.cpp animsettingdialog.cpp - autorun.cpp batterysystemtrayicon.cpp ckbmainbackgroundcolour.cpp ckbsettings.cpp @@ -185,7 +184,6 @@ if (MACOS OR LINUX) animdetailsdialog.h animscript.h animsettingdialog.h - autorun.h ckbmainbackgroundcolour.h ckbsettings.h ckbsettingswriter.h @@ -581,26 +579,19 @@ if (MACOS) "${CMAKE_SOURCE_DIR}/macos/org.ckb-next.plist" "${CMAKE_CURRENT_BINARY_DIR}/org.ckb-next.plist" COPYONLY) - - if (NOT TEXT_QRC_STRING) - set(TEXT_QRC_STRING "org.ckb-next.plist\n") - endif () - elseif (LINUX) - if (NOT TEXT_QRC_STRING) - set(TEXT_QRC_STRING "ckb-next.autostart.desktop\n") - endif () - # Generate and import desktop files message(STATUS "Generating and importing ckb-next.desktop") + set(CKB_NEXT_BACKGROUND_ARG "") configure_file( "${CMAKE_SOURCE_DIR}/linux/ckb-next.desktop.in" "${CMAKE_CURRENT_BINARY_DIR}/ckb-next.desktop" @ONLY) - message(STATUS "Generating and importing ckb-next.autostart.desktop") + message(STATUS "Generating autostart/ckb-next.desktop") + set(CKB_NEXT_BACKGROUND_ARG " --background") configure_file( - "${CMAKE_SOURCE_DIR}/linux/ckb-next.autostart.desktop.in" - "${CMAKE_CURRENT_BINARY_DIR}/ckb-next.autostart.desktop" + "${CMAKE_SOURCE_DIR}/linux/ckb-next.desktop.in" + "${CMAKE_CURRENT_BINARY_DIR}/autostart/ckb-next.desktop" @ONLY) endif () @@ -804,6 +795,14 @@ elseif (LINUX) OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) + + install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/autostart/ckb-next.desktop" + DESTINATION "${CMAKE_INSTALL_FULL_SYSCONFDIR}/xdg/autostart" + PERMISSIONS + OWNER_READ OWNER_WRITE + GROUP_READ + WORLD_READ) endif () # Deploy QT5 diff --git a/src/gui/autorun.cpp b/src/gui/autorun.cpp deleted file mode 100644 index cac6bb11..00000000 --- a/src/gui/autorun.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include -#include -#include -#include "autorun.h" -#include "ckbsettings.h" -#include -#include - -// >=0.3.0 (new) paths -#ifdef Q_OS_LINUX -static QDir path(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.config/autostart"); -static const QString file = "ckb-next.autostart.desktop"; -static const QString internalFile(":/txt/ckb-next.autostart.desktop"); -#elif defined(Q_OS_MACOS) -static QDir path(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/Library/LaunchAgents"); -static const QString file = "org.ckb-next.plist"; -static const QString internalFile(":/txt/org.ckb-next.plist"); -#endif - -static const QString settingPath = "Program/NewDidLoginItem"; - -// <=0.2.9 (old) paths -#ifdef Q_OS_LINUX -static const QString oldFile = "ckb.desktop"; -#elif defined(Q_OS_MACX) -static const QString oldFile = "com.ckb.ckb.plist"; -#endif - -static const QString oldSettingPath = "Program/DidLoginItem"; - -bool AutoRun::available() { - // Allow autostart if the program is located in a system path -#ifdef Q_OS_LINUX - const QString& fpath = qApp->applicationFilePath(); - QFileInfo finfo(fpath); - return QDir::root().absoluteFilePath(QStandardPaths::findExecutable(finfo.fileName())) == fpath; -#elif defined(Q_OS_MACOS) - return qApp->applicationFilePath().startsWith("/Applications/ckb-next.app", Qt::CaseInsensitive); -#endif -} - -bool AutoRun::once() { - return CkbSettings::get(settingPath).toBool(); -} - -bool AutoRun::isEnabled() { - // Check if the file exists. If not, autostart is disabled. - if (!path.exists() || !path.exists(file)) - return false; - // Check if the existing autostart file matches the one bundled with the binary - QFile internal(internalFile), sysfile(path.absoluteFilePath(file)); - - internal.open(QIODevice::ReadOnly); - // We can't open this RW because default permissions are -r--r--r-- - sysfile.open(QIODevice::ReadOnly); - - QByteArray internalData = internal.readAll(); - // Only load internalData size bytes at most from the file on disk - QByteArray sysfileData = sysfile.read(internalData.length()); - - internal.close(); - sysfile.close(); - - if(internalData != sysfileData){ - sysfile.remove(); - qDebug() << "Autostart files differ. Replacing with new one."; - enable(); - return true; - } - - // If autostart is enabled, set the flag from once() (in case it hasn't been done yet) - CkbSettings::set(settingPath, true); - return true; -} - -void AutoRun::enable() { - if (!available()) - return; - - // Copy file into place - if (!path.exists()) - QDir::home().mkpath(path.absolutePath()); - QFile::copy(internalFile, path.absoluteFilePath(file)); - // Mark once() as done - CkbSettings::set(settingPath, true); - - // If an old autostart was enabled, disable it and remove - if (CkbSettings::get(oldSettingPath).toBool()) { - CkbSettings::set(oldSettingPath, false); - QFile::remove(path.absoluteFilePath(oldFile)); - } -} - -void AutoRun::disable() { - if (!available()) - return; - // Remove file - QFile::remove(path.absoluteFilePath(file)); -} diff --git a/src/gui/autorun.h b/src/gui/autorun.h deleted file mode 100644 index 26be55a1..00000000 --- a/src/gui/autorun.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef AUTORUN_H -#define AUTORUN_H - -#include - -// Class for running ckb at login - -class AutoRun -{ -public: - // Whether or not run at login is possible - static bool available(); - - // Whether or not ckb has been set to run at login at least once before - static bool once(); - - // Enable/disable launch at login - static bool isEnabled(); - static void enable(); - static void disable(); -}; - -#endif // AUTORUN_H diff --git a/src/gui/settingswidget.cpp b/src/gui/settingswidget.cpp index 72d7ea6e..28f77459 100644 --- a/src/gui/settingswidget.cpp +++ b/src/gui/settingswidget.cpp @@ -1,6 +1,5 @@ #include #include "animscript.h" -#include "autorun.h" #include "ckbsettings.h" #include "kb.h" #include "settingswidget.h" @@ -79,14 +78,32 @@ SettingsWidget::SettingsWidget(QWidget *parent) : // Read auto update settings ui->autoFWBox->setChecked(!settings.value("DisableAutoFWCheck").toBool()); - // Read auto run settings - if(!AutoRun::available()) - ui->loginItemBox->hide(); - else { - if(!AutoRun::once()) - // If this is the first time running the app, enable auto run by default - AutoRun::enable(); - ui->loginItemBox->setChecked(AutoRun::isEnabled()); +#ifdef Q_OS_LINUX + static const QString deletedAutorunPath = QStringLiteral("Program/DeletedOldAutostart"); + // If autostart was enabled, and there's an autostart file in XDG_CONFIG_DIRS, then delete the local one. + if(!CkbSettings::get(deletedAutorunPath).toBool()) { + CkbSettings::set(deletedAutorunPath, QVariant::fromValue(true)); + + // Have to do this manually since Qt won't separate system paths from user ones + QStringList config_dirs = QString::fromLocal8Bit(qgetenv("XDG_CONFIG_DIRS")).split(QChar(':'), Qt::SkipEmptyParts); + if(config_dirs.isEmpty()) + config_dirs.append(QStringLiteral("/etc/xdg")); + + for(const QString& str : config_dirs) { + QDir d(str); + if(!d.exists() || !d.cd(QStringLiteral("autostart"))) + continue; + + if(d.exists(QStringLiteral("ckb-next.desktop"))) { + qDebug() << "Found autostart file in" << d.absolutePath(); + // Path copy pasted from the old autorun.cpp + static const QDir path(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.config/autostart"); + // ckb-next wouldn't let you modify the autostart file before, so if the file exists, it's a pretty good guarantee that it's the one we created + // If the user modified it and made it read only, then this won't be able to remove it anyway + QFile::remove(path.absoluteFilePath(QStringLiteral("ckb-next.autostart.desktop"))); + break; + } + } } QString copyrightText = QString("© 2014-2016 ccMSC.
© 2017-%1 %2.").arg(CKB_NEXT_COPYRIGHT_YEAR, tr("The ckb-next development team")); @@ -178,13 +195,6 @@ void SettingsWidget::on_autoFWBox_clicked(bool checked){ CkbSettings::set("Program/DisableAutoFWCheck", !checked); } -void SettingsWidget::on_loginItemBox_clicked(bool checked){ - if(checked) - AutoRun::enable(); - else - AutoRun::disable(); -} - void SettingsWidget::on_aboutQt_clicked(){ QMessageBox::aboutQt(this); } diff --git a/src/gui/settingswidget.h b/src/gui/settingswidget.h index 45c86390..f6797636 100644 --- a/src/gui/settingswidget.h +++ b/src/gui/settingswidget.h @@ -40,7 +40,6 @@ private slots: void on_altBox_activated(int index); void on_winBox_activated(int index); void on_autoFWBox_clicked(bool checked); - void on_loginItemBox_clicked(bool checked); void on_aboutQt_clicked(); void on_generateReportButton_clicked(); void devDetectFinished(int retVal); diff --git a/src/gui/settingswidget.ui b/src/gui/settingswidget.ui index 1ac76147..64760cfa 100644 --- a/src/gui/settingswidget.ui +++ b/src/gui/settingswidget.ui @@ -36,7 +36,6 @@ - 75 true @@ -135,7 +134,6 @@ - 75 true @@ -367,7 +365,6 @@ - 75 true @@ -383,16 +380,6 @@ - - - - ckb-next will be started when you log in to your computer. - - - Start ckb-next at login - - -