mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge pull request #2409 from matttbe:autostart_dir
Autorun:xdg: create autostart dir if needed fixes #2332
This commit is contained in:
commit
4c383a624e
|
@ -26,14 +26,19 @@
|
||||||
|
|
||||||
namespace Platform
|
namespace Platform
|
||||||
{
|
{
|
||||||
QString getAutostartFilePath()
|
QString getAutostartDirPath()
|
||||||
{
|
{
|
||||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||||
QString config = env.value("XDG_CONFIG_HOME");
|
QString config = env.value("XDG_CONFIG_HOME");
|
||||||
if (config.isEmpty())
|
if (config.isEmpty())
|
||||||
config = QDir::homePath() + "/" + ".config";
|
config = QDir::homePath() + "/" + ".config";
|
||||||
return config + "/" + "autostart/qTox - " +
|
return config + "/autostart";
|
||||||
Settings::getInstance().getCurrentProfile() + ".desktop";
|
}
|
||||||
|
|
||||||
|
QString getAutostartFilePath(QString dir)
|
||||||
|
{
|
||||||
|
return dir + "/qTox - " + Settings::getInstance().getCurrentProfile() +
|
||||||
|
".desktop";
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QString currentCommandLine()
|
inline QString currentCommandLine()
|
||||||
|
@ -45,11 +50,12 @@ namespace Platform
|
||||||
|
|
||||||
bool Platform::setAutorun(bool on)
|
bool Platform::setAutorun(bool on)
|
||||||
{
|
{
|
||||||
|
QString dirPath = getAutostartDirPath();
|
||||||
QFile desktop(getAutostartFilePath());
|
QFile desktop(getAutostartFilePath(dirPath));
|
||||||
if (on)
|
if (on)
|
||||||
{
|
{
|
||||||
if (!desktop.open(QFile::WriteOnly | QFile::Truncate))
|
if (!QDir().mkpath(dirPath) ||
|
||||||
|
!desktop.open(QFile::WriteOnly | QFile::Truncate))
|
||||||
return false;
|
return false;
|
||||||
desktop.write("[Desktop Entry]\n");
|
desktop.write("[Desktop Entry]\n");
|
||||||
desktop.write("Type=Application\n");
|
desktop.write("Type=Application\n");
|
||||||
|
@ -66,7 +72,7 @@ bool Platform::setAutorun(bool on)
|
||||||
|
|
||||||
bool Platform::getAutorun()
|
bool Platform::getAutorun()
|
||||||
{
|
{
|
||||||
return QFile(getAutostartFilePath()).exists();
|
return QFile(getAutostartFilePath(getAutostartDirPath())).exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // defined(Q_OS_UNIX) && !defined(__APPLE__) && !defined(__MACH__)
|
#endif // defined(Q_OS_UNIX) && !defined(__APPLE__) && !defined(__MACH__)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user