2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +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

@@ -11,10 +11,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "platform/win/notifications_manager_win.h"
#include "platform/win/windows_app_user_model_id.h"
#include "platform/win/windows_dlls.h"
#include "platform/win/windows_autostart_task.h"
#include "base/platform/base_platform_info.h"
#include "base/platform/win/base_windows_co_task_mem.h"
#include "base/platform/win/base_windows_winrt.h"
#include "base/call_delayed.h"
#include "ui/boxes/confirm_box.h"
#include "lang/lang_keys.h"
#include "mainwindow.h"
#include "mainwidget.h"
@@ -175,7 +177,7 @@ QString psAppDataPathOld() {
void psDoCleanup() {
try {
psAutoStart(false, true);
Platform::AutostartToggle(false);
psSendToMenu(false, true);
AppUserModelId::cleanupShortcut();
DeleteMyModules();
@@ -328,7 +330,51 @@ std::optional<bool> IsDarkMode() {
}
bool AutostartSupported() {
return !IsWindowsStoreBuild();
return true;
}
void AutostartRequestStateFromSystem(Fn<void(bool)> callback) {
#ifdef OS_WIN_STORE
AutostartTask::RequestState([=](bool enabled) {
crl::on_main([=] {
callback(enabled);
});
});
#endif // OS_WIN_STORE
}
void AutostartToggle(bool enabled, Fn<void(bool)> done) {
#ifdef OS_WIN_STORE
const auto requested = enabled;
const auto callback = [=](bool enabled) { crl::on_main([=] {
if (!Core::IsAppLaunched()) {
return;
}
done(enabled);
if (!requested || enabled) {
return;
} else if (const auto window = Core::App().activeWindow()) {
window->show(Box<Ui::ConfirmBox>(
tr::lng_settings_auto_start_disabled_uwp(tr::now),
tr::lng_settings_open_system_settings(tr::now),
[] { AutostartTask::OpenSettings(); Ui::hideLayer(); }));
}
}); };
AutostartTask::Toggle(
enabled,
done ? Fn<void(bool)>(callback) : nullptr);
#else // OS_WIN_STORE
_manageAppLnk(start, silent, CSIDL_STARTUP, L"-autostart", L"Telegram autorun link.\nYou can disable autorun in Telegram settings.");
done(enabled);
#endif // OS_WIN_STORE
}
bool AutostartSkip() {
#ifdef OS_WIN_STORE
return false;
#else // OS_WIN_STORE
return !cAutoStart();
#endif // OS_WIN_STORE
}
void WriteCrashDumpDetails() {
@@ -534,10 +580,6 @@ void _manageAppLnk(bool create, bool silent, int path_csidl, const wchar_t *args
}
}
void psAutoStart(bool start, bool silent) {
_manageAppLnk(start, silent, CSIDL_STARTUP, L"-autostart", L"Telegram autorun link.\nYou can disable autorun in Telegram settings.");
}
void psSendToMenu(bool send, bool silent) {
_manageAppLnk(send, silent, CSIDL_SENDTO, L"-sendpath", L"Telegram send to link.\nYou can disable send to menu item in Telegram settings.");
}