Skip to content

Commit

Permalink
Added Shortcut Creation to Start Menu, Removed WinGet Files
Browse files Browse the repository at this point in the history
  • Loading branch information
nicola02nb committed Oct 8, 2024
1 parent 9fc2285 commit a3bfd39
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 43 deletions.
1 change: 1 addition & 0 deletions src/UI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ MainWindow::MainWindow(QWidget *parent)
, API(HeadsetControlAPI(HEADSETCONTROL_FILE_PATH))
{
QDir().mkpath(PROGRAM_CONFIG_PATH);
createStartMenuShortcut();
settings = loadSettingsFromFile(PROGRAM_SETTINGS_FILEPATH);
defaultStyle = styleSheet();

Expand Down
52 changes: 52 additions & 0 deletions src/Utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,55 @@ bool setOSRunOnStartup(bool enable)
return false;
#endif
}

bool createStartMenuShortcut()
{
QString appName = QCoreApplication::applicationName();
QString appPath = QCoreApplication::applicationFilePath();

#ifdef Q_OS_WIN
QString startupPath = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation);
QString linkPath = startupPath + QDir::separator() + appName + ".lnk";
QFile::remove(linkPath);
return QFile::link(appPath, linkPath);

#elif defined(Q_OS_LINUX)
// Get the applications directory
QString applicationsDir = QDir::homePath() + "/.local/share/applications/";

// Create applications directory if it doesn't exist
QDir().mkpath(applicationsDir);

// Create .desktop file
QString desktopFilePath = applicationsDir + appName.toLower() + ".desktop";
QFile desktopFile(desktopFilePath);

if (!desktopFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug() << "Failed to create .desktop file";
return false;
}

// Desktop entry content
QString desktopContent = QString("[Desktop Entry]\n"
"Version=1.0\n"
"Type=Application\n"
"Name=%1\n"
"Exec=%2\n"
"Terminal=false\n"
"Categories=Utility;\n")
.arg(appName, appPath);
desktopFile.write(desktopContent.toUtf8());
desktopFile.close();

// Make the .desktop file executable
QFile::setPermissions(desktopFilePath,
QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner | QFile::ReadGroup
| QFile::ReadOther);

return true;

#else
qDebug() << "Unsupported operating system";
return false;
#endif
}
2 changes: 2 additions & 0 deletions src/Utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ bool openFileExplorer(const QString &path);

bool setOSRunOnStartup(bool enable);

bool createStartMenuShortcut();

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

const QString APP_NAME = "HeadsetControl-GUI";
const QString GUI_VERSION = "0.16.9";
const QString GUI_VERSION = "0.16.10";

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

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit a3bfd39

Please sign in to comment.