Skip to content

Commit

Permalink
Added runOnStartup to Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nicola02nb committed Sep 2, 2024
1 parent 0170f92 commit 7dba550
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/UI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ MainWindow::MainWindow(QWidget *parent)
this->disableFrames();

QString exe = "headsetcontrol";
#ifdef _WIN32
#ifdef Q_OS_WIN
exe = exe+".exe";
#endif

Expand Down
5 changes: 4 additions & 1 deletion src/UI/settingswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ SettingsWindow::SettingsWindow(const Settings& programSettings, QWidget *parent)
setModal(true);
ui->setupUi(this);

connect(ui->runonstartupCheckBox, &QCheckBox::clicked, this, &SettingsWindow::setRunOnStartup);

ui->runonstartupCheckBox->setChecked(programSettings.runOnstartup);
ui->batterylowtresholdSpinBox->setValue(programSettings.batteryLowThreshold);
ui->updateintervaltimeDoubleSpinBox->setValue((double)programSettings.msecUpdateIntervalTime/1000);
Expand All @@ -25,7 +27,8 @@ Settings SettingsWindow::getSettings(){
}

void SettingsWindow::setRunOnStartup(){
setOSRunOnStartup(ui->runonstartupCheckBox->isChecked());
bool enabled = setOSRunOnStartup(ui->runonstartupCheckBox->isChecked());
ui->runonstartupCheckBox->setChecked(enabled);
}

SettingsWindow::~SettingsWindow()
Expand Down
2 changes: 1 addition & 1 deletion src/UI/settingswindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<item>
<widget class="QFrame" name="frame_3">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
Expand Down
42 changes: 40 additions & 2 deletions src/Utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <QDesktopServices>
#include <QDir>

#include <QStandardPaths>

QString getLatestGitHubReleaseVersion(const QString& owner, const QString& repo)
{
QEventLoop loop;
Expand Down Expand Up @@ -96,7 +98,43 @@ bool openFileExplorer(const QString& path)
return QDesktopServices::openUrl(url);
}

void setOSRunOnStartup(bool enable){
//TO BE IMPLEMENTED
bool setOSRunOnStartup(bool enable){
QString appName = QCoreApplication::applicationName();
QString appDir = QCoreApplication::applicationDirPath();
QString appPath = QCoreApplication::applicationFilePath();

#ifdef Q_OS_WIN
QString startupPath = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + QDir::separator() + "Startup";
QString linkPath = startupPath + "\\" + appName + ".lnk";
if(enable){
QFile::remove(linkPath);
return QFile::link(appPath, linkPath);
}
QFile::remove(linkPath);
return false;

#elif defined(Q_OS_LINUX)
QString autostartPath = QDir::homePath() + "/.config/autostart/";
QString desktopFilePath = autostartPath + appName + ".desktop";

if(enable){
QFile::remove(desktopFilePath);
QFile desktopFile(desktopFilePath);
if (desktopFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&desktopFile);
out << "[Desktop Entry]\n";
out << "Path=" + appDir + "\n"
out << "Type=Application\n";
out << "Exec=" << appPath << "\n";
out << "Name=" << appName << "\n";
out << "Comment=Auto-starts " << appName << " on boot\n";
desktopFile.close();
return true;
}
}
QFile::remove(desktopFilePath);

return false;
#endif
}

2 changes: 1 addition & 1 deletion src/Utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ bool fileExists(const QString& filepath);

bool openFileExplorer(const QString& path);

void setOSRunOnStartup(bool enable);
bool setOSRunOnStartup(bool enable);

#endif // UTILS_H
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <QApplication>
#include <QTranslator>

const QString GUI_VERSION = "0.13.0";
const QString GUI_VERSION = "0.14.0";

int main(int argc, char *argv[])
{
Expand Down

0 comments on commit 7dba550

Please sign in to comment.