2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Support autostart in Windows Store version.

Fixes #3234.
This commit is contained in:
John Preston
2021-11-04 12:35:34 +04:00
parent 81327ede7b
commit f10ed4b9bc
17 changed files with 343 additions and 53 deletions

View File

@@ -560,6 +560,41 @@ bool AutostartSupported() {
return !InSnap();
}
void AutostartToggle(bool enabled, Fn<void(bool)> done) {
const auto guard = gsl::finally([&] {
done(enabled);
});
#ifdef __HAIKU__
HaikuAutostart(enabled);
#else // __HAIKU__
const auto silent = !done;
if (InFlatpak()) {
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
PortalAutostart(enabled, silent);
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
} else {
const auto autostart = QStandardPaths::writableLocation(
QStandardPaths::GenericConfigLocation)
+ qsl("/autostart/");
if (enabled) {
GenerateDesktopFile(autostart, qsl("-autostart"), silent);
} else {
QFile::remove(autostart + QGuiApplication::desktopFileName());
}
}
#endif // __HAIKU__
}
bool AutostartSkip() {
return !cAutoStart();
}
bool TrayIconSupported() {
return App::wnd()
? App::wnd()->trayAvailable()
@@ -637,7 +672,7 @@ QString psAppDataPath() {
void psDoCleanup() {
try {
psAutoStart(false, true);
Platform::AutostartToggle(false);
psSendToMenu(false, true);
} catch (...) {
}
@@ -837,29 +872,6 @@ void psNewVersion() {
#endif // __HAIKU__
}
void psAutoStart(bool start, bool silent) {
#ifdef __HAIKU__
HaikuAutostart(start);
return;
#endif // __HAIKU__
if (InFlatpak()) {
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
PortalAutostart(start, silent);
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
} else {
const auto autostart = QStandardPaths::writableLocation(
QStandardPaths::GenericConfigLocation)
+ qsl("/autostart/");
if (start) {
GenerateDesktopFile(autostart, qsl("-autostart"), silent);
} else {
QFile::remove(autostart + QGuiApplication::desktopFileName());
}
}
}
void psSendToMenu(bool send, bool silent) {
}

View File

@@ -29,6 +29,9 @@ inline void IgnoreApplicationActivationRightNow() {
inline void WriteCrashDumpDetails() {
}
inline void AutostartRequestStateFromSystem(Fn<void(bool)> callback) {
}
} // namespace Platform
inline void psCheckLocalSocket(const QString &serverName) {
@@ -40,7 +43,6 @@ inline void psCheckLocalSocket(const QString &serverName) {
void psActivateProcess(uint64 pid = 0);
QString psAppDataPath();
void psAutoStart(bool start, bool silent = false);
void psSendToMenu(bool send, bool silent = false);
int psCleanup();