mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 22:55:11 +00:00
@@ -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) {
|
||||
}
|
||||
|
||||
|
@@ -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();
|
||||
|
@@ -22,6 +22,9 @@ inline bool AutostartSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void AutostartRequestStateFromSystem(Fn<void(bool)> callback) {
|
||||
}
|
||||
|
||||
inline bool TrayIconSupported() {
|
||||
return true;
|
||||
}
|
||||
@@ -50,7 +53,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();
|
||||
|
@@ -48,7 +48,7 @@ QString psAppDataPath() {
|
||||
|
||||
void psDoCleanup() {
|
||||
try {
|
||||
psAutoStart(false, true);
|
||||
Platform::AutostartToggle(false);
|
||||
psSendToMenu(false, true);
|
||||
} catch (...) {
|
||||
}
|
||||
@@ -181,14 +181,19 @@ void IgnoreApplicationActivationRightNow() {
|
||||
objc_ignoreApplicationActivationRightNow();
|
||||
}
|
||||
|
||||
void AutostartToggle(bool enabled, Fn<void(bool)> done) {
|
||||
done(false);
|
||||
}
|
||||
|
||||
bool AutostartSkip() {
|
||||
return !cAutoStart();
|
||||
}
|
||||
|
||||
} // namespace Platform
|
||||
|
||||
void psNewVersion() {
|
||||
}
|
||||
|
||||
void psAutoStart(bool start, bool silent) {
|
||||
}
|
||||
|
||||
void psSendToMenu(bool send, bool silent) {
|
||||
}
|
||||
|
||||
|
@@ -34,7 +34,10 @@ void RequestPermission(PermissionType type, Fn<void(PermissionStatus)> resultCal
|
||||
void OpenSystemSettingsForPermission(PermissionType type);
|
||||
bool OpenSystemSettings(SystemSettingsType type);
|
||||
void IgnoreApplicationActivationRightNow();
|
||||
bool AutostartSupported();
|
||||
[[nodiscard]] bool AutostartSupported();
|
||||
void AutostartRequestStateFromSystem(Fn<void(bool)> callback);
|
||||
void AutostartToggle(bool enabled, Fn<void(bool)> done = nullptr);
|
||||
[[nodiscard]] bool AutostartSkip();
|
||||
bool TrayIconSupported();
|
||||
bool SkipTaskbarSupported();
|
||||
void WriteCrashDumpDetails();
|
||||
|
@@ -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.");
|
||||
}
|
||||
|
@@ -43,7 +43,6 @@ inline void psCheckLocalSocket(const QString &) {
|
||||
void psActivateProcess(uint64 pid = 0);
|
||||
QString psAppDataPath();
|
||||
QString psAppDataPathOld();
|
||||
void psAutoStart(bool start, bool silent = false);
|
||||
void psSendToMenu(bool send, bool silent = false);
|
||||
|
||||
int psCleanup();
|
||||
|
111
Telegram/SourceFiles/platform/win/windows_autostart_task.cpp
Normal file
111
Telegram/SourceFiles/platform/win/windows_autostart_task.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "platform/win/windows_autostart_task.h"
|
||||
|
||||
#include "base/platform/win/base_windows_winrt.h"
|
||||
|
||||
#include <winrt/Windows.ApplicationModel.h>
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
#include <winrt/Windows.System.h>
|
||||
|
||||
namespace Platform::AutostartTask {
|
||||
namespace {
|
||||
|
||||
using namespace winrt::Windows::ApplicationModel;
|
||||
using namespace winrt::Windows::System;
|
||||
using namespace winrt::Windows::Foundation;
|
||||
|
||||
[[nodiscard]] bool IsEnabled(StartupTaskState state) {
|
||||
switch (state) {
|
||||
case StartupTaskState::Enabled:
|
||||
case StartupTaskState::EnabledByPolicy:
|
||||
return true;
|
||||
case StartupTaskState::Disabled:
|
||||
case StartupTaskState::DisabledByPolicy:
|
||||
case StartupTaskState::DisabledByUser:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void Toggle(bool enabled, Fn<void(bool)> done) {
|
||||
if (!base::WinRT::Supported()) {
|
||||
return;
|
||||
}
|
||||
const auto processEnableResult = [=](StartupTaskState state) {
|
||||
LOG(("Startup Task: Enable finished, state: %1").arg(int(state)));
|
||||
|
||||
done(IsEnabled(state));
|
||||
};
|
||||
const auto processTask = [=](StartupTask task) {
|
||||
LOG(("Startup Task: Got it, state: %1, requested: %2"
|
||||
).arg(int(task.State())
|
||||
).arg(Logs::b(enabled)));
|
||||
|
||||
if (IsEnabled(task.State()) == enabled) {
|
||||
return;
|
||||
}
|
||||
if (!enabled) {
|
||||
LOG(("Startup Task: Disabling."));
|
||||
task.Disable();
|
||||
return;
|
||||
}
|
||||
LOG(("Startup Task: Requesting enable."));
|
||||
const auto asyncState = task.RequestEnableAsync();
|
||||
if (!done) {
|
||||
return;
|
||||
}
|
||||
asyncState.Completed([=](
|
||||
IAsyncOperation<StartupTaskState> operation,
|
||||
AsyncStatus status) {
|
||||
base::WinRT::Try([&] {
|
||||
processEnableResult(operation.GetResults());
|
||||
});
|
||||
});
|
||||
};
|
||||
base::WinRT::Try([&] {
|
||||
StartupTask::GetAsync(L"TelegramStartupTask").Completed([=](
|
||||
IAsyncOperation<StartupTask> operation,
|
||||
AsyncStatus status) {
|
||||
base::WinRT::Try([&] {
|
||||
processTask(operation.GetResults());
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void RequestState(Fn<void(bool)> callback) {
|
||||
Expects(callback != nullptr);
|
||||
|
||||
if (!base::WinRT::Supported()) {
|
||||
return;
|
||||
}
|
||||
const auto processTask = [=](StartupTask task) {
|
||||
DEBUG_LOG(("Startup Task: Got value, state: %1"
|
||||
).arg(int(task.State())));
|
||||
|
||||
callback(IsEnabled(task.State()));
|
||||
};
|
||||
base::WinRT::Try([&] {
|
||||
StartupTask::GetAsync(L"TelegramStartupTask").Completed([=](
|
||||
IAsyncOperation<StartupTask> operation,
|
||||
AsyncStatus status) {
|
||||
base::WinRT::Try([&] {
|
||||
processTask(operation.GetResults());
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void OpenSettings() {
|
||||
Launcher::LaunchUriAsync(Uri(L"ms-settings:startupapps"));
|
||||
}
|
||||
|
||||
} // namespace Platform::AutostartTask
|
16
Telegram/SourceFiles/platform/win/windows_autostart_task.h
Normal file
16
Telegram/SourceFiles/platform/win/windows_autostart_task.h
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace Platform::AutostartTask {
|
||||
|
||||
void Toggle(bool enabled, Fn<void(bool)> done);
|
||||
void RequestState(Fn<void(bool)> callback);
|
||||
void OpenSettings();
|
||||
|
||||
} // namespace Platform::AutostartTask
|
Reference in New Issue
Block a user