mirror of
https://github.com/ckb-next/ckb-next.git
synced 2026-10-10 12:27:21 -04:00
Merge branch 'rework-autostart'
This commit is contained in:
@@ -1,14 +0,0 @@
|
|||||||
# Copyright 2017-2018 ckb-next Development Team <[email protected]>
|
|
||||||
# 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
|
|
||||||
@@ -9,6 +9,6 @@ Comment=Corsair keyboard driver user interface
|
|||||||
Keywords=ckb;corsair;keyboard;rgb;
|
Keywords=ckb;corsair;keyboard;rgb;
|
||||||
Categories=Settings;System;
|
Categories=Settings;System;
|
||||||
TryExec=@CMAKE_INSTALL_PREFIX@/bin/ckb-next
|
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
|
Icon=ckb-next
|
||||||
StartupNotify=true
|
StartupNotify=true
|
||||||
|
|||||||
+13
-14
@@ -126,7 +126,6 @@ if (MACOS OR LINUX)
|
|||||||
animdetailsdialog.cpp
|
animdetailsdialog.cpp
|
||||||
animscript.cpp
|
animscript.cpp
|
||||||
animsettingdialog.cpp
|
animsettingdialog.cpp
|
||||||
autorun.cpp
|
|
||||||
batterysystemtrayicon.cpp
|
batterysystemtrayicon.cpp
|
||||||
ckbmainbackgroundcolour.cpp
|
ckbmainbackgroundcolour.cpp
|
||||||
ckbsettings.cpp
|
ckbsettings.cpp
|
||||||
@@ -185,7 +184,6 @@ if (MACOS OR LINUX)
|
|||||||
animdetailsdialog.h
|
animdetailsdialog.h
|
||||||
animscript.h
|
animscript.h
|
||||||
animsettingdialog.h
|
animsettingdialog.h
|
||||||
autorun.h
|
|
||||||
ckbmainbackgroundcolour.h
|
ckbmainbackgroundcolour.h
|
||||||
ckbsettings.h
|
ckbsettings.h
|
||||||
ckbsettingswriter.h
|
ckbsettingswriter.h
|
||||||
@@ -581,26 +579,19 @@ if (MACOS)
|
|||||||
"${CMAKE_SOURCE_DIR}/macos/org.ckb-next.plist"
|
"${CMAKE_SOURCE_DIR}/macos/org.ckb-next.plist"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/org.ckb-next.plist"
|
"${CMAKE_CURRENT_BINARY_DIR}/org.ckb-next.plist"
|
||||||
COPYONLY)
|
COPYONLY)
|
||||||
|
|
||||||
if (NOT TEXT_QRC_STRING)
|
|
||||||
set(TEXT_QRC_STRING "<file>org.ckb-next.plist</file>\n")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
elseif (LINUX)
|
elseif (LINUX)
|
||||||
if (NOT TEXT_QRC_STRING)
|
|
||||||
set(TEXT_QRC_STRING "<file>ckb-next.autostart.desktop</file>\n")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
# Generate and import desktop files
|
# Generate and import desktop files
|
||||||
message(STATUS "Generating and importing ckb-next.desktop")
|
message(STATUS "Generating and importing ckb-next.desktop")
|
||||||
|
set(CKB_NEXT_BACKGROUND_ARG "")
|
||||||
configure_file(
|
configure_file(
|
||||||
"${CMAKE_SOURCE_DIR}/linux/ckb-next.desktop.in"
|
"${CMAKE_SOURCE_DIR}/linux/ckb-next.desktop.in"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/ckb-next.desktop"
|
"${CMAKE_CURRENT_BINARY_DIR}/ckb-next.desktop"
|
||||||
@ONLY)
|
@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(
|
configure_file(
|
||||||
"${CMAKE_SOURCE_DIR}/linux/ckb-next.autostart.desktop.in"
|
"${CMAKE_SOURCE_DIR}/linux/ckb-next.desktop.in"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/ckb-next.autostart.desktop"
|
"${CMAKE_CURRENT_BINARY_DIR}/autostart/ckb-next.desktop"
|
||||||
@ONLY)
|
@ONLY)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
@@ -804,6 +795,14 @@ elseif (LINUX)
|
|||||||
OWNER_READ OWNER_WRITE
|
OWNER_READ OWNER_WRITE
|
||||||
GROUP_READ
|
GROUP_READ
|
||||||
WORLD_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 ()
|
endif ()
|
||||||
|
|
||||||
# Deploy QT5
|
# Deploy QT5
|
||||||
|
|||||||
@@ -1,99 +0,0 @@
|
|||||||
#include <QApplication>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QStandardPaths>
|
|
||||||
#include "autorun.h"
|
|
||||||
#include "ckbsettings.h"
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QFileInfo>
|
|
||||||
|
|
||||||
// >=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));
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
#ifndef AUTORUN_H
|
|
||||||
#define AUTORUN_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
// 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
|
|
||||||
+26
-16
@@ -1,6 +1,5 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include "animscript.h"
|
#include "animscript.h"
|
||||||
#include "autorun.h"
|
|
||||||
#include "ckbsettings.h"
|
#include "ckbsettings.h"
|
||||||
#include "kb.h"
|
#include "kb.h"
|
||||||
#include "settingswidget.h"
|
#include "settingswidget.h"
|
||||||
@@ -79,14 +78,32 @@ SettingsWidget::SettingsWidget(QWidget *parent) :
|
|||||||
// Read auto update settings
|
// Read auto update settings
|
||||||
ui->autoFWBox->setChecked(!settings.value("DisableAutoFWCheck").toBool());
|
ui->autoFWBox->setChecked(!settings.value("DisableAutoFWCheck").toBool());
|
||||||
|
|
||||||
// Read auto run settings
|
#ifdef Q_OS_LINUX
|
||||||
if(!AutoRun::available())
|
static const QString deletedAutorunPath = QStringLiteral("Program/DeletedOldAutostart");
|
||||||
ui->loginItemBox->hide();
|
// If autostart was enabled, and there's an autostart file in XDG_CONFIG_DIRS, then delete the local one.
|
||||||
else {
|
if(!CkbSettings::get(deletedAutorunPath).toBool()) {
|
||||||
if(!AutoRun::once())
|
CkbSettings::set(deletedAutorunPath, QVariant::fromValue<bool>(true));
|
||||||
// If this is the first time running the app, enable auto run by default
|
|
||||||
AutoRun::enable();
|
// Have to do this manually since Qt won't separate system paths from user ones
|
||||||
ui->loginItemBox->setChecked(AutoRun::isEnabled());
|
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 <a href=\"https://github.com/ccMSC/\" style=\"text-decoration:none;\">ccMSC</a>.<br/>© 2017-%1 <a href=\"https://github.com/ckb-next/ckb-next/graphs/contributors\" style=\"text-decoration:none;\">%2</a>.").arg(CKB_NEXT_COPYRIGHT_YEAR, tr("The ckb-next development team"));
|
QString copyrightText = QString("© 2014-2016 <a href=\"https://github.com/ccMSC/\" style=\"text-decoration:none;\">ccMSC</a>.<br/>© 2017-%1 <a href=\"https://github.com/ckb-next/ckb-next/graphs/contributors\" style=\"text-decoration:none;\">%2</a>.").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);
|
CkbSettings::set("Program/DisableAutoFWCheck", !checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsWidget::on_loginItemBox_clicked(bool checked){
|
|
||||||
if(checked)
|
|
||||||
AutoRun::enable();
|
|
||||||
else
|
|
||||||
AutoRun::disable();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SettingsWidget::on_aboutQt_clicked(){
|
void SettingsWidget::on_aboutQt_clicked(){
|
||||||
QMessageBox::aboutQt(this);
|
QMessageBox::aboutQt(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ private slots:
|
|||||||
void on_altBox_activated(int index);
|
void on_altBox_activated(int index);
|
||||||
void on_winBox_activated(int index);
|
void on_winBox_activated(int index);
|
||||||
void on_autoFWBox_clicked(bool checked);
|
void on_autoFWBox_clicked(bool checked);
|
||||||
void on_loginItemBox_clicked(bool checked);
|
|
||||||
void on_aboutQt_clicked();
|
void on_aboutQt_clicked();
|
||||||
void on_generateReportButton_clicked();
|
void on_generateReportButton_clicked();
|
||||||
void devDetectFinished(int retVal);
|
void devDetectFinished(int retVal);
|
||||||
|
|||||||
@@ -36,7 +36,6 @@
|
|||||||
</property>
|
</property>
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
<weight>75</weight>
|
|
||||||
<bold>true</bold>
|
<bold>true</bold>
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
@@ -135,7 +134,6 @@
|
|||||||
</property>
|
</property>
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
<weight>75</weight>
|
|
||||||
<bold>true</bold>
|
<bold>true</bold>
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
@@ -367,7 +365,6 @@
|
|||||||
</property>
|
</property>
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
<weight>75</weight>
|
|
||||||
<bold>true</bold>
|
<bold>true</bold>
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
@@ -383,16 +380,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="loginItemBox">
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>ckb-next will be started when you log in to your computer.</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Start ckb-next at login</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="autoFWBox">
|
<widget class="QCheckBox" name="autoFWBox">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
|
|||||||
Reference in New Issue
Block a user