mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-30 17:24:08 +00:00
Improve X11 autostart behavior
* Run the freedesktop.org-specific code only on X11 (not on Mac). * Use a (hopefully) unique destination .desktop file name to prevent clashes with a goldendict.desktop file possibly created and customized manually or by a system preferences tool. * Allow different executable and .desktop file names because there is no real dependency between them. * Improve performance slightly with an early return.
This commit is contained in:
parent
c27020ec2f
commit
d83586d3e4
|
@ -3259,7 +3259,7 @@ void MainWindow::on_newTab_triggered()
|
||||||
|
|
||||||
void MainWindow::setAutostart(bool autostart)
|
void MainWindow::setAutostart(bool autostart)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN32
|
#if defined Q_OS_WIN32
|
||||||
QSettings reg("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run",
|
QSettings reg("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run",
|
||||||
QSettings::NativeFormat);
|
QSettings::NativeFormat);
|
||||||
if (autostart) {
|
if (autostart) {
|
||||||
|
@ -3271,16 +3271,17 @@ void MainWindow::setAutostart(bool autostart)
|
||||||
reg.remove(QCoreApplication::applicationName());
|
reg.remove(QCoreApplication::applicationName());
|
||||||
}
|
}
|
||||||
reg.sync();
|
reg.sync();
|
||||||
#else
|
#elif defined HAVE_X11
|
||||||
// this is for Linux
|
const QString destinationPath = QDir::homePath() + "/.config/autostart/goldendict-owned-by-preferences.desktop";
|
||||||
QString app_fname = QFileInfo(QCoreApplication::applicationFilePath()).baseName();
|
if( autostart == QFile::exists( destinationPath ) )
|
||||||
QString ShareDataPath = Config::getProgramDataDir() + "../applications/";
|
return; // Nothing to do.
|
||||||
QString lnk(QDir::homePath() + "/.config/autostart/" + app_fname + ".desktop");
|
if( autostart )
|
||||||
if (autostart) {
|
{
|
||||||
QFile::copy(ShareDataPath + app_fname + ".desktop", lnk);
|
const QString sourcePath = Config::getProgramDataDir() + "../applications/goldendict.desktop";
|
||||||
} else {
|
QFile::copy( sourcePath, destinationPath );
|
||||||
QFile::remove(lnk);
|
}
|
||||||
}
|
else
|
||||||
|
QFile::remove( destinationPath );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue