mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Use some methods from lib_base
This commit is contained in:
parent
df9c7f07a1
commit
a38b4f039a
22 changed files with 42 additions and 485 deletions
|
@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "chat_helpers/emoji_keywords.h"
|
#include "chat_helpers/emoji_keywords.h"
|
||||||
#include "chat_helpers/stickers_emoji_image_loader.h"
|
#include "chat_helpers/stickers_emoji_image_loader.h"
|
||||||
#include "base/platform/base_platform_info.h"
|
#include "base/platform/base_platform_info.h"
|
||||||
|
#include "base/platform/base_platform_last_input.h"
|
||||||
#include "platform/platform_specific.h"
|
#include "platform/platform_specific.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "dialogs/dialogs_entry.h"
|
#include "dialogs/dialogs_entry.h"
|
||||||
|
@ -807,7 +808,7 @@ void Application::updateNonIdle() {
|
||||||
|
|
||||||
crl::time Application::lastNonIdleTime() const {
|
crl::time Application::lastNonIdleTime() const {
|
||||||
return std::max(
|
return std::max(
|
||||||
Platform::LastUserInputTime().value_or(0),
|
base::Platform::LastUserInputTime().value_or(0),
|
||||||
_lastNonIdleTime);
|
_lastNonIdleTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "core/file_utilities.h"
|
#include "core/file_utilities.h"
|
||||||
|
|
||||||
#include "storage/localstorage.h"
|
#include "storage/localstorage.h"
|
||||||
|
#include "base/platform/base_platform_file_utilities.h"
|
||||||
#include "platform/platform_file_utilities.h"
|
#include "platform/platform_file_utilities.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
|
@ -154,7 +155,7 @@ void Launch(const QString &filepath) {
|
||||||
void ShowInFolder(const QString &filepath) {
|
void ShowInFolder(const QString &filepath) {
|
||||||
crl::on_main([=] {
|
crl::on_main([=] {
|
||||||
Ui::PreventDelayedActivation();
|
Ui::PreventDelayedActivation();
|
||||||
Platform::File::UnsafeShowInFolder(filepath);
|
base::Platform::ShowInFolder(filepath);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "platform/platform_launcher.h"
|
#include "platform/platform_launcher.h"
|
||||||
#include "platform/platform_specific.h"
|
#include "platform/platform_specific.h"
|
||||||
#include "base/platform/base_platform_info.h"
|
#include "base/platform/base_platform_info.h"
|
||||||
|
#include "base/platform/base_platform_file_utilities.h"
|
||||||
#include "ui/main_queue_processor.h"
|
#include "ui/main_queue_processor.h"
|
||||||
#include "ui/ui_utility.h"
|
#include "ui/ui_utility.h"
|
||||||
#include "core/crash_reports.h"
|
#include "core/crash_reports.h"
|
||||||
|
@ -342,7 +343,7 @@ int Launcher::exec() {
|
||||||
if (!UpdaterDisabled() && cRestartingUpdate()) {
|
if (!UpdaterDisabled() && cRestartingUpdate()) {
|
||||||
DEBUG_LOG(("Sandbox Info: executing updater to install update."));
|
DEBUG_LOG(("Sandbox Info: executing updater to install update."));
|
||||||
if (!launchUpdater(UpdaterLaunch::PerformUpdate)) {
|
if (!launchUpdater(UpdaterLaunch::PerformUpdate)) {
|
||||||
psDeleteDir(cWorkingDir() + qsl("tupdates/temp"));
|
base::Platform::DeleteDirectory(cWorkingDir() + qsl("tupdates/temp"));
|
||||||
}
|
}
|
||||||
} else if (cRestarting()) {
|
} else if (cRestarting()) {
|
||||||
DEBUG_LOG(("Sandbox Info: executing Telegram because of restart."));
|
DEBUG_LOG(("Sandbox Info: executing Telegram because of restart."));
|
||||||
|
@ -402,7 +403,7 @@ bool Launcher::customWorkingDir() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Launcher::prepareSettings() {
|
void Launcher::prepareSettings() {
|
||||||
auto path = Platform::CurrentExecutablePath(_argc, _argv);
|
auto path = base::Platform::CurrentExecutablePath(_argc, _argv);
|
||||||
LOG(("Executable path before check: %1").arg(path));
|
LOG(("Executable path before check: %1").arg(path));
|
||||||
if (!path.isEmpty()) {
|
if (!path.isEmpty()) {
|
||||||
auto info = QFileInfo(path);
|
auto info = QFileInfo(path);
|
||||||
|
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "core/update_checker.h"
|
#include "core/update_checker.h"
|
||||||
|
|
||||||
#include "base/platform/base_platform_info.h"
|
#include "base/platform/base_platform_info.h"
|
||||||
|
#include "base/platform/base_platform_file_utilities.h"
|
||||||
#include "base/timer.h"
|
#include "base/timer.h"
|
||||||
#include "base/bytes.h"
|
#include "base/bytes.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
|
@ -211,7 +212,7 @@ QString UpdatesFolder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClearAll() {
|
void ClearAll() {
|
||||||
psDeleteDir(UpdatesFolder());
|
base::Platform::DeleteDirectory(UpdatesFolder());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FindUpdateFile() {
|
QString FindUpdateFile() {
|
||||||
|
@ -270,7 +271,7 @@ bool UnpackUpdate(const QString &filepath) {
|
||||||
input.close();
|
input.close();
|
||||||
|
|
||||||
QString tempDirPath = cWorkingDir() + qsl("tupdates/temp"), readyFilePath = cWorkingDir() + qsl("tupdates/temp/ready");
|
QString tempDirPath = cWorkingDir() + qsl("tupdates/temp"), readyFilePath = cWorkingDir() + qsl("tupdates/temp/ready");
|
||||||
psDeleteDir(tempDirPath);
|
base::Platform::DeleteDirectory(tempDirPath);
|
||||||
|
|
||||||
QDir tempDir(tempDirPath);
|
QDir tempDir(tempDirPath);
|
||||||
if (tempDir.exists() || QFile(readyFilePath).exists()) {
|
if (tempDir.exists() || QFile(readyFilePath).exists()) {
|
||||||
|
@ -1560,8 +1561,8 @@ bool checkReadyUpdate() {
|
||||||
#endif // Q_OS_UNIX
|
#endif // Q_OS_UNIX
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
Platform::RemoveQuarantine(QFileInfo(curUpdater).absolutePath());
|
base::Platform::RemoveQuarantine(QFileInfo(curUpdater).absolutePath());
|
||||||
Platform::RemoveQuarantine(updater.absolutePath());
|
base::Platform::RemoveQuarantine(updater.absolutePath());
|
||||||
#endif // Q_OS_MAC
|
#endif // Q_OS_MAC
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -11,11 +11,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "platform/linux/linux_gdk_helper.h"
|
#include "platform/linux/linux_gdk_helper.h"
|
||||||
#include "platform/linux/linux_desktop_environment.h"
|
#include "platform/linux/linux_desktop_environment.h"
|
||||||
#include "platform/linux/specific_linux.h"
|
#include "platform/linux/specific_linux.h"
|
||||||
#include "boxes/abstract_box.h"
|
|
||||||
#include "storage/localstorage.h"
|
#include "storage/localstorage.h"
|
||||||
#include "base/platform/base_platform_file_utilities.h"
|
|
||||||
|
|
||||||
#include <QtCore/QProcess>
|
|
||||||
#include <QtGui/QDesktopServices>
|
#include <QtGui/QDesktopServices>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -91,12 +88,6 @@ void UnsafeLaunch(const QString &filepath) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnsafeShowInFolder(const QString &filepath) {
|
|
||||||
// Hide mediaview to make other apps visible.
|
|
||||||
Ui::hideLayer(anim::type::instant);
|
|
||||||
base::Platform::ShowInFolder(filepath);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace File
|
} // namespace File
|
||||||
|
|
||||||
namespace FileDialog {
|
namespace FileDialog {
|
||||||
|
|
|
@ -174,33 +174,6 @@ QString FlatpakID() {
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ProcessNameByPID(const QString &pid) {
|
|
||||||
constexpr auto kMaxPath = 1024;
|
|
||||||
char result[kMaxPath] = { 0 };
|
|
||||||
auto count = readlink("/proc/" + pid.toLatin1() + "/exe", result, kMaxPath);
|
|
||||||
if (count > 0) {
|
|
||||||
auto filename = QFile::decodeName(result);
|
|
||||||
auto deletedPostfix = qstr(" (deleted)");
|
|
||||||
if (filename.endsWith(deletedPostfix) && !QFileInfo(filename).exists()) {
|
|
||||||
filename.chop(deletedPostfix.size());
|
|
||||||
}
|
|
||||||
return filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString RealExecutablePath(int argc, char *argv[]) {
|
|
||||||
const auto processName = ProcessNameByPID(qsl("self"));
|
|
||||||
|
|
||||||
// Fallback to the first command line argument.
|
|
||||||
return !processName.isEmpty()
|
|
||||||
? processName
|
|
||||||
: argc
|
|
||||||
? QFile::decodeName(argv[0])
|
|
||||||
: QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RunShellCommand(const QString &program, const QStringList &arguments) {
|
bool RunShellCommand(const QString &program, const QStringList &arguments) {
|
||||||
const auto result = QProcess::execute(program, arguments);
|
const auto result = QProcess::execute(program, arguments);
|
||||||
|
|
||||||
|
@ -310,131 +283,6 @@ bool GetImageFromClipboardSupported() {
|
||||||
}
|
}
|
||||||
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
|
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
|
||||||
|
|
||||||
std::optional<crl::time> XCBLastUserInputTime() {
|
|
||||||
const auto connection = base::Platform::XCB::GetConnectionFromQt();
|
|
||||||
if (!connection) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!base::Platform::XCB::IsExtensionPresent(
|
|
||||||
connection,
|
|
||||||
&xcb_screensaver_id)) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto root = base::Platform::XCB::GetRootWindowFromQt();
|
|
||||||
if (!root.has_value()) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto cookie = xcb_screensaver_query_info(
|
|
||||||
connection,
|
|
||||||
*root);
|
|
||||||
|
|
||||||
auto reply = xcb_screensaver_query_info_reply(
|
|
||||||
connection,
|
|
||||||
cookie,
|
|
||||||
nullptr);
|
|
||||||
|
|
||||||
if (!reply) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto idle = reply->ms_since_user_input;
|
|
||||||
free(reply);
|
|
||||||
|
|
||||||
return (crl::now() - static_cast<crl::time>(idle));
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
||||||
std::optional<crl::time> FreedesktopDBusLastUserInputTime() {
|
|
||||||
static auto NotSupported = false;
|
|
||||||
|
|
||||||
if (NotSupported) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const auto Message = QDBusMessage::createMethodCall(
|
|
||||||
qsl("org.freedesktop.ScreenSaver"),
|
|
||||||
qsl("/org/freedesktop/ScreenSaver"),
|
|
||||||
qsl("org.freedesktop.ScreenSaver"),
|
|
||||||
qsl("GetSessionIdleTime"));
|
|
||||||
|
|
||||||
const QDBusReply<uint> reply = QDBusConnection::sessionBus().call(
|
|
||||||
Message);
|
|
||||||
|
|
||||||
static const auto NotSupportedErrors = {
|
|
||||||
QDBusError::ServiceUnknown,
|
|
||||||
QDBusError::NotSupported,
|
|
||||||
};
|
|
||||||
|
|
||||||
static const auto NotSupportedErrorsToLog = {
|
|
||||||
QDBusError::Disconnected,
|
|
||||||
QDBusError::AccessDenied,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (reply.isValid()) {
|
|
||||||
return (crl::now() - static_cast<crl::time>(reply.value()));
|
|
||||||
} else if (ranges::contains(NotSupportedErrors, reply.error().type())) {
|
|
||||||
NotSupported = true;
|
|
||||||
} else {
|
|
||||||
if (ranges::contains(NotSupportedErrorsToLog, reply.error().type())) {
|
|
||||||
NotSupported = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG(("App Error: Unable to get last user input time "
|
|
||||||
"from org.freedesktop.ScreenSaver: %1: %2")
|
|
||||||
.arg(reply.error().name())
|
|
||||||
.arg(reply.error().message()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<crl::time> MutterDBusLastUserInputTime() {
|
|
||||||
static auto NotSupported = false;
|
|
||||||
|
|
||||||
if (NotSupported) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const auto Message = QDBusMessage::createMethodCall(
|
|
||||||
qsl("org.gnome.Mutter.IdleMonitor"),
|
|
||||||
qsl("/org/gnome/Mutter/IdleMonitor/Core"),
|
|
||||||
qsl("org.gnome.Mutter.IdleMonitor"),
|
|
||||||
qsl("GetIdletime"));
|
|
||||||
|
|
||||||
const QDBusReply<qulonglong> reply = QDBusConnection::sessionBus().call(
|
|
||||||
Message);
|
|
||||||
|
|
||||||
static const auto NotSupportedErrors = {
|
|
||||||
QDBusError::ServiceUnknown,
|
|
||||||
};
|
|
||||||
|
|
||||||
static const auto NotSupportedErrorsToLog = {
|
|
||||||
QDBusError::Disconnected,
|
|
||||||
QDBusError::AccessDenied,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (reply.isValid()) {
|
|
||||||
return (crl::now() - static_cast<crl::time>(reply.value()));
|
|
||||||
} else if (ranges::contains(NotSupportedErrors, reply.error().type())) {
|
|
||||||
NotSupported = true;
|
|
||||||
} else {
|
|
||||||
if (ranges::contains(NotSupportedErrorsToLog, reply.error().type())) {
|
|
||||||
NotSupported = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG(("App Error: Unable to get last user input time "
|
|
||||||
"from org.gnome.Mutter.IdleMonitor: %1: %2")
|
|
||||||
.arg(reply.error().name())
|
|
||||||
.arg(reply.error().message()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
||||||
|
|
||||||
uint XCBMoveResizeFromEdges(Qt::Edges edges) {
|
uint XCBMoveResizeFromEdges(Qt::Edges edges) {
|
||||||
if (edges == (Qt::TopEdge | Qt::LeftEdge))
|
if (edges == (Qt::TopEdge | Qt::LeftEdge))
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -682,11 +530,6 @@ bool InSnap() {
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InAppImage() {
|
|
||||||
static const auto Result = qEnvironmentVariableIsSet("APPIMAGE");
|
|
||||||
return Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsStaticBinary() {
|
bool IsStaticBinary() {
|
||||||
#ifdef DESKTOP_APP_USE_PACKAGED
|
#ifdef DESKTOP_APP_USE_PACKAGED
|
||||||
return false;
|
return false;
|
||||||
|
@ -773,25 +616,6 @@ bool CanOpenDirectoryWithPortal() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CurrentExecutablePath(int argc, char *argv[]) {
|
|
||||||
if (InAppImage()) {
|
|
||||||
const auto appimagePath = QString::fromUtf8(qgetenv("APPIMAGE"));
|
|
||||||
const auto appimagePathList = appimagePath.split('/');
|
|
||||||
|
|
||||||
if (qEnvironmentVariableIsSet("ARGV0")
|
|
||||||
&& appimagePathList.size() >= 5
|
|
||||||
&& appimagePathList[1] == qstr("run")
|
|
||||||
&& appimagePathList[2] == qstr("user")
|
|
||||||
&& appimagePathList[4] == qstr("appimagelauncherfs")) {
|
|
||||||
return QString::fromUtf8(qgetenv("ARGV0"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return appimagePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
return RealExecutablePath(argc, argv);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString AppRuntimeDirectory() {
|
QString AppRuntimeDirectory() {
|
||||||
static const auto Result = [&] {
|
static const auto Result = [&] {
|
||||||
auto runtimeDir = QStandardPaths::writableLocation(
|
auto runtimeDir = QStandardPaths::writableLocation(
|
||||||
|
@ -908,29 +732,6 @@ QImage GetImageFromClipboard() {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<crl::time> LastUserInputTime() {
|
|
||||||
if (!IsWayland()) {
|
|
||||||
const auto xcbResult = XCBLastUserInputTime();
|
|
||||||
if (xcbResult.has_value()) {
|
|
||||||
return xcbResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
||||||
const auto freedesktopResult = FreedesktopDBusLastUserInputTime();
|
|
||||||
if (freedesktopResult.has_value()) {
|
|
||||||
return freedesktopResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto mutterResult = MutterDBusLastUserInputTime();
|
|
||||||
if (mutterResult.has_value()) {
|
|
||||||
return mutterResult;
|
|
||||||
}
|
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
||||||
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<bool> IsDarkMode() {
|
std::optional<bool> IsDarkMode() {
|
||||||
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
|
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
|
||||||
if (Libs::GtkSettingSupported() && Libs::GtkLoaded()) {
|
if (Libs::GtkSettingSupported() && Libs::GtkLoaded()) {
|
||||||
|
@ -1089,41 +890,6 @@ QRect psDesktopRect() {
|
||||||
void psWriteDump() {
|
void psWriteDump() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _removeDirectory(const QString &path) { // from http://stackoverflow.com/questions/2256945/removing-a-non-empty-directory-programmatically-in-c-or-c
|
|
||||||
QByteArray pathRaw = QFile::encodeName(path);
|
|
||||||
DIR *d = opendir(pathRaw.constData());
|
|
||||||
if (!d) return false;
|
|
||||||
|
|
||||||
while (struct dirent *p = readdir(d)) {
|
|
||||||
/* Skip the names "." and ".." as we don't want to recurse on them. */
|
|
||||||
if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) continue;
|
|
||||||
|
|
||||||
QString fname = path + '/' + p->d_name;
|
|
||||||
QByteArray fnameRaw = QFile::encodeName(fname);
|
|
||||||
struct stat statbuf;
|
|
||||||
if (!stat(fnameRaw.constData(), &statbuf)) {
|
|
||||||
if (S_ISDIR(statbuf.st_mode)) {
|
|
||||||
if (!_removeDirectory(fname)) {
|
|
||||||
closedir(d);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (unlink(fnameRaw.constData())) {
|
|
||||||
closedir(d);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir(d);
|
|
||||||
|
|
||||||
return !rmdir(pathRaw.constData());
|
|
||||||
}
|
|
||||||
|
|
||||||
void psDeleteDir(const QString &dir) {
|
|
||||||
_removeDirectory(dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
void psActivateProcess(uint64 pid) {
|
void psActivateProcess(uint64 pid) {
|
||||||
// objc_activateProgram();
|
// objc_activateProgram();
|
||||||
}
|
}
|
||||||
|
@ -1444,10 +1210,6 @@ void psNewVersion() {
|
||||||
Platform::RegisterCustomScheme();
|
Platform::RegisterCustomScheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool psShowOpenWithMenu(int x, int y, const QString &file) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void psAutoStart(bool start, bool silent) {
|
void psAutoStart(bool start, bool silent) {
|
||||||
if (InFlatpak()) {
|
if (InFlatpak()) {
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
|
|
@ -22,7 +22,6 @@ inline void SetWatchingMediaKeys(bool watching) {
|
||||||
|
|
||||||
bool InFlatpak();
|
bool InFlatpak();
|
||||||
bool InSnap();
|
bool InSnap();
|
||||||
bool InAppImage();
|
|
||||||
bool IsStaticBinary();
|
bool IsStaticBinary();
|
||||||
bool UseGtkIntegration();
|
bool UseGtkIntegration();
|
||||||
bool IsGtkIntegrationForced();
|
bool IsGtkIntegrationForced();
|
||||||
|
@ -55,8 +54,6 @@ inline void psCheckLocalSocket(const QString &serverName) {
|
||||||
|
|
||||||
void psWriteDump();
|
void psWriteDump();
|
||||||
|
|
||||||
void psDeleteDir(const QString &dir);
|
|
||||||
|
|
||||||
QStringList psInitLogs();
|
QStringList psInitLogs();
|
||||||
void psClearInitLogs();
|
void psClearInitLogs();
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "platform/mac/file_utilities_mac.h"
|
#include "platform/mac/file_utilities_mac.h"
|
||||||
|
|
||||||
#include "base/platform/mac/base_utilities_mac.h"
|
#include "base/platform/mac/base_utilities_mac.h"
|
||||||
#include "base/platform/base_platform_file_utilities.h"
|
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "styles/style_window.h"
|
#include "styles/style_window.h"
|
||||||
|
|
||||||
|
@ -573,9 +572,5 @@ void UnsafeLaunch(const QString &filepath) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnsafeShowInFolder(const QString &filepath) {
|
|
||||||
base::Platform::ShowInFolder(filepath);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace File
|
} // namespace File
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
|
|
@ -10,8 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "core/crash_reports.h"
|
#include "core/crash_reports.h"
|
||||||
#include "core/update_checker.h"
|
#include "core/update_checker.h"
|
||||||
#include "base/platform/base_platform_info.h"
|
#include "base/platform/base_platform_info.h"
|
||||||
|
#include "base/platform/base_platform_file_utilities.h"
|
||||||
#include "base/platform/mac/base_utilities_mac.h"
|
#include "base/platform/mac/base_utilities_mac.h"
|
||||||
#include "platform/platform_specific.h"
|
|
||||||
|
|
||||||
#include <Cocoa/Cocoa.h>
|
#include <Cocoa/Cocoa.h>
|
||||||
#include <CoreFoundation/CFURL.h>
|
#include <CoreFoundation/CFURL.h>
|
||||||
|
@ -54,7 +54,7 @@ bool Launcher::launchUpdater(UpdaterLaunch action) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
path = [path stringByAppendingString:@"/Contents/Frameworks/Updater"];
|
path = [path stringByAppendingString:@"/Contents/Frameworks/Updater"];
|
||||||
RemoveQuarantine(QFile::decodeName([path fileSystemRepresentation]));
|
base::Platform::RemoveQuarantine(QFile::decodeName([path fileSystemRepresentation]));
|
||||||
|
|
||||||
NSMutableArray *args = [[NSMutableArray alloc] initWithObjects:@"-workpath", Q2NSString(cWorkingDir()), @"-procid", nil];
|
NSMutableArray *args = [[NSMutableArray alloc] initWithObjects:@"-workpath", Q2NSString(cWorkingDir()), @"-procid", nil];
|
||||||
[args addObject:[NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]]];
|
[args addObject:[NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]]];
|
||||||
|
|
|
@ -16,8 +16,6 @@ class LocationPoint;
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
|
|
||||||
void RemoveQuarantine(const QString &path);
|
|
||||||
|
|
||||||
[[nodiscard]] bool IsDarkMenuBar();
|
[[nodiscard]] bool IsDarkMenuBar();
|
||||||
|
|
||||||
inline QImage GetImageFromClipboard() {
|
inline QImage GetImageFromClipboard() {
|
||||||
|
@ -76,8 +74,6 @@ inline void psCheckLocalSocket(const QString &serverName) {
|
||||||
|
|
||||||
void psWriteDump();
|
void psWriteDump();
|
||||||
|
|
||||||
void psDeleteDir(const QString &dir);
|
|
||||||
|
|
||||||
QStringList psInitLogs();
|
QStringList psInitLogs();
|
||||||
void psClearInitLogs();
|
void psClearInitLogs();
|
||||||
|
|
||||||
|
@ -92,8 +88,6 @@ QRect psDesktopRect();
|
||||||
int psCleanup();
|
int psCleanup();
|
||||||
int psFixPrevious();
|
int psFixPrevious();
|
||||||
|
|
||||||
bool psShowOpenWithMenu(int x, int y, const QString &file);
|
|
||||||
|
|
||||||
void psNewVersion();
|
void psNewVersion();
|
||||||
|
|
||||||
void psDownloadPathEnableAccess();
|
void psDownloadPathEnableAccess();
|
||||||
|
|
|
@ -65,10 +65,6 @@ void psWriteDump() {
|
||||||
#endif // DESKTOP_APP_DISABLE_CRASH_REPORTS
|
#endif // DESKTOP_APP_DISABLE_CRASH_REPORTS
|
||||||
}
|
}
|
||||||
|
|
||||||
void psDeleteDir(const QString &dir) {
|
|
||||||
objc_deleteDir(dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList psInitLogs() {
|
QStringList psInitLogs() {
|
||||||
return _initLogs;
|
return _initLogs;
|
||||||
}
|
}
|
||||||
|
@ -118,10 +114,6 @@ void finish() {
|
||||||
objc_finish();
|
objc_finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CurrentExecutablePath(int argc, char *argv[]) {
|
|
||||||
return NS2QString([[NSBundle mainBundle] bundlePath]);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString SingleInstanceLocalServerName(const QString &hash) {
|
QString SingleInstanceLocalServerName(const QString &hash) {
|
||||||
#ifndef OS_MAC_STORE
|
#ifndef OS_MAC_STORE
|
||||||
return qsl("/tmp/") + hash + '-' + cGUIDStr();
|
return qsl("/tmp/") + hash + '-' + cGUIDStr();
|
||||||
|
@ -130,14 +122,6 @@ QString SingleInstanceLocalServerName(const QString &hash) {
|
||||||
#endif // OS_MAC_STORE
|
#endif // OS_MAC_STORE
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveQuarantine(const QString &path) {
|
|
||||||
const auto kQuarantineAttribute = "com.apple.quarantine";
|
|
||||||
|
|
||||||
DEBUG_LOG(("Removing quarantine attribute: %1").arg(path));
|
|
||||||
const auto local = QFile::encodeName(path);
|
|
||||||
removexattr(local.data(), kQuarantineAttribute, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsDarkMenuBar() {
|
bool IsDarkMenuBar() {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
|
@ -234,60 +218,6 @@ bool OpenSystemSettings(SystemSettingsType type) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Taken from https://github.com/trueinteractions/tint/issues/53.
|
|
||||||
std::optional<crl::time> LastUserInputTime() {
|
|
||||||
CFMutableDictionaryRef properties = 0;
|
|
||||||
CFTypeRef obj;
|
|
||||||
mach_port_t masterPort;
|
|
||||||
io_iterator_t iter;
|
|
||||||
io_registry_entry_t curObj;
|
|
||||||
|
|
||||||
IOMasterPort(MACH_PORT_NULL, &masterPort);
|
|
||||||
|
|
||||||
/* Get IOHIDSystem */
|
|
||||||
IOServiceGetMatchingServices(masterPort, IOServiceMatching("IOHIDSystem"), &iter);
|
|
||||||
if (iter == 0) {
|
|
||||||
return std::nullopt;
|
|
||||||
} else {
|
|
||||||
curObj = IOIteratorNext(iter);
|
|
||||||
}
|
|
||||||
if (IORegistryEntryCreateCFProperties(curObj, &properties, kCFAllocatorDefault, 0) == KERN_SUCCESS && properties != NULL) {
|
|
||||||
obj = CFDictionaryGetValue(properties, CFSTR("HIDIdleTime"));
|
|
||||||
CFRetain(obj);
|
|
||||||
} else {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64 err = ~0L, idleTime = err;
|
|
||||||
if (obj) {
|
|
||||||
CFTypeID type = CFGetTypeID(obj);
|
|
||||||
|
|
||||||
if (type == CFDataGetTypeID()) {
|
|
||||||
CFDataGetBytes((CFDataRef) obj, CFRangeMake(0, sizeof(idleTime)), (UInt8*)&idleTime);
|
|
||||||
} else if (type == CFNumberGetTypeID()) {
|
|
||||||
CFNumberGetValue((CFNumberRef)obj, kCFNumberSInt64Type, &idleTime);
|
|
||||||
} else {
|
|
||||||
// error
|
|
||||||
}
|
|
||||||
|
|
||||||
CFRelease(obj);
|
|
||||||
|
|
||||||
if (idleTime != err) {
|
|
||||||
idleTime /= 1000000; // return as ms
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// error
|
|
||||||
}
|
|
||||||
|
|
||||||
CFRelease((CFTypeRef)properties);
|
|
||||||
IOObjectRelease(curObj);
|
|
||||||
IOObjectRelease(iter);
|
|
||||||
if (idleTime == err) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
return (crl::now() - static_cast<crl::time>(idleTime));
|
|
||||||
}
|
|
||||||
|
|
||||||
void IgnoreApplicationActivationRightNow() {
|
void IgnoreApplicationActivationRightNow() {
|
||||||
objc_ignoreApplicationActivationRightNow();
|
objc_ignoreApplicationActivationRightNow();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ void objc_finish();
|
||||||
|
|
||||||
void objc_activateProgram(WId winId);
|
void objc_activateProgram(WId winId);
|
||||||
bool objc_moveFile(const QString &from, const QString &to);
|
bool objc_moveFile(const QString &from, const QString &to);
|
||||||
void objc_deleteDir(const QString &dir);
|
|
||||||
|
|
||||||
double objc_appkitVersion();
|
double objc_appkitVersion();
|
||||||
|
|
||||||
|
|
|
@ -340,14 +340,6 @@ bool objc_moveFile(const QString &from, const QString &to) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void objc_deleteDir(const QString &dir) {
|
|
||||||
@autoreleasepool {
|
|
||||||
|
|
||||||
[[NSFileManager defaultManager] removeItemAtPath:Q2NSString(dir) error:nil];
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double objc_appkitVersion() {
|
double objc_appkitVersion() {
|
||||||
return NSAppKitVersionNumber;
|
return NSAppKitVersionNumber;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ void UnsafeOpenEmailLink(const QString &email);
|
||||||
bool UnsafeShowOpenWithDropdown(const QString &filepath, QPoint menuPosition);
|
bool UnsafeShowOpenWithDropdown(const QString &filepath, QPoint menuPosition);
|
||||||
bool UnsafeShowOpenWith(const QString &filepath);
|
bool UnsafeShowOpenWith(const QString &filepath);
|
||||||
void UnsafeLaunch(const QString &filepath);
|
void UnsafeLaunch(const QString &filepath);
|
||||||
void UnsafeShowInFolder(const QString &filepath);
|
|
||||||
|
|
||||||
void PostprocessDownloaded(const QString &filepath);
|
void PostprocessDownloaded(const QString &filepath);
|
||||||
|
|
||||||
|
|
|
@ -31,24 +31,12 @@ enum class SystemSettingsType {
|
||||||
|
|
||||||
void SetWatchingMediaKeys(bool watching);
|
void SetWatchingMediaKeys(bool watching);
|
||||||
void SetApplicationIcon(const QIcon &icon);
|
void SetApplicationIcon(const QIcon &icon);
|
||||||
QString CurrentExecutablePath(int argc, char *argv[]);
|
|
||||||
QString SingleInstanceLocalServerName(const QString &hash);
|
QString SingleInstanceLocalServerName(const QString &hash);
|
||||||
void RegisterCustomScheme(bool force = false);
|
void RegisterCustomScheme(bool force = false);
|
||||||
PermissionStatus GetPermissionStatus(PermissionType type);
|
PermissionStatus GetPermissionStatus(PermissionType type);
|
||||||
void RequestPermission(PermissionType type, Fn<void(PermissionStatus)> resultCallback);
|
void RequestPermission(PermissionType type, Fn<void(PermissionStatus)> resultCallback);
|
||||||
void OpenSystemSettingsForPermission(PermissionType type);
|
void OpenSystemSettingsForPermission(PermissionType type);
|
||||||
bool OpenSystemSettings(SystemSettingsType type);
|
bool OpenSystemSettings(SystemSettingsType type);
|
||||||
|
|
||||||
[[nodiscard]] std::optional<crl::time> LastUserInputTime();
|
|
||||||
[[nodiscard]] inline bool LastUserInputTimeSupported() {
|
|
||||||
return LastUserInputTime().has_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] std::optional<bool> IsDarkMode();
|
|
||||||
[[nodiscard]] inline bool IsDarkModeSupported() {
|
|
||||||
return IsDarkMode().has_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
void IgnoreApplicationActivationRightNow();
|
void IgnoreApplicationActivationRightNow();
|
||||||
bool AutostartSupported();
|
bool AutostartSupported();
|
||||||
bool TrayIconSupported();
|
bool TrayIconSupported();
|
||||||
|
@ -61,6 +49,11 @@ bool SetWindowExtents(QWindow *window, const QMargins &extents);
|
||||||
bool UnsetWindowExtents(QWindow *window);
|
bool UnsetWindowExtents(QWindow *window);
|
||||||
Window::ControlsLayout WindowControlsLayout();
|
Window::ControlsLayout WindowControlsLayout();
|
||||||
|
|
||||||
|
[[nodiscard]] std::optional<bool> IsDarkMode();
|
||||||
|
[[nodiscard]] inline bool IsDarkModeSupported() {
|
||||||
|
return IsDarkMode().has_value();
|
||||||
|
}
|
||||||
|
|
||||||
namespace ThirdParty {
|
namespace ThirdParty {
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
|
|
|
@ -10,7 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "storage/localstorage.h"
|
#include "storage/localstorage.h"
|
||||||
#include "platform/win/windows_dlls.h"
|
#include "platform/win/windows_dlls.h"
|
||||||
#include "base/platform/base_platform_file_utilities.h"
|
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/crash_reports.h"
|
#include "core/crash_reports.h"
|
||||||
|
@ -266,10 +265,6 @@ void UnsafeLaunch(const QString &filepath) {
|
||||||
ShellExecute(0, L"open", wstringPath.c_str(), 0, 0, SW_SHOWNORMAL);
|
ShellExecute(0, L"open", wstringPath.c_str(), 0, 0, SW_SHOWNORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnsafeShowInFolder(const QString &filepath) {
|
|
||||||
base::Platform::ShowInFolder(filepath);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PostprocessDownloaded(const QString &filepath) {
|
void PostprocessDownloaded(const QString &filepath) {
|
||||||
auto wstringZoneFile = QDir::toNativeSeparators(filepath).toStdWString() + L":Zone.Identifier";
|
auto wstringZoneFile = QDir::toNativeSeparators(filepath).toStdWString() + L":Zone.Identifier";
|
||||||
auto f = CreateFile(wstringZoneFile.c_str(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
auto f = CreateFile(wstringZoneFile.c_str(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace Platform {
|
||||||
namespace File {
|
namespace File {
|
||||||
|
|
||||||
inline QString UrlToLocal(const QUrl &url) {
|
inline QString UrlToLocal(const QUrl &url) {
|
||||||
return url.toLocalFile();
|
return ::File::internal::UrlToLocalDefault(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void UnsafeOpenUrl(const QString &url) {
|
inline void UnsafeOpenUrl(const QString &url) {
|
||||||
|
|
|
@ -70,8 +70,6 @@ using namespace Platform;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr auto kRefreshBadLastUserInputTimeout = 10 * crl::time(1000);
|
|
||||||
|
|
||||||
QStringList _initLogs;
|
QStringList _initLogs;
|
||||||
|
|
||||||
bool themeInited = false;
|
bool themeInited = false;
|
||||||
|
@ -87,49 +85,27 @@ public:
|
||||||
};
|
};
|
||||||
_PsInitializer _psInitializer;
|
_PsInitializer _psInitializer;
|
||||||
|
|
||||||
} // namespace
|
BOOL CALLBACK _ActivateProcess(HWND hWnd, LPARAM lParam) {
|
||||||
|
uint64 &processId(*(uint64*)lParam);
|
||||||
|
|
||||||
void psDeleteDir(const QString &dir) {
|
DWORD dwProcessId;
|
||||||
std::wstring wDir = QDir::toNativeSeparators(dir).toStdWString();
|
::GetWindowThreadProcessId(hWnd, &dwProcessId);
|
||||||
WCHAR path[4096];
|
|
||||||
memcpy(path, wDir.c_str(), (wDir.size() + 1) * sizeof(WCHAR));
|
|
||||||
path[wDir.size() + 1] = 0;
|
|
||||||
SHFILEOPSTRUCT file_op = {
|
|
||||||
NULL,
|
|
||||||
FO_DELETE,
|
|
||||||
path,
|
|
||||||
L"",
|
|
||||||
FOF_NOCONFIRMATION |
|
|
||||||
FOF_NOERRORUI |
|
|
||||||
FOF_SILENT,
|
|
||||||
false,
|
|
||||||
0,
|
|
||||||
L""
|
|
||||||
};
|
|
||||||
int res = SHFileOperation(&file_op);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
if ((uint64)dwProcessId == processId) { // found top-level window
|
||||||
BOOL CALLBACK _ActivateProcess(HWND hWnd, LPARAM lParam) {
|
static const int32 nameBufSize = 1024;
|
||||||
uint64 &processId(*(uint64*)lParam);
|
WCHAR nameBuf[nameBufSize];
|
||||||
|
int32 len = GetWindowText(hWnd, nameBuf, nameBufSize);
|
||||||
DWORD dwProcessId;
|
if (len && len < nameBufSize) {
|
||||||
::GetWindowThreadProcessId(hWnd, &dwProcessId);
|
if (QRegularExpression(qsl("^Telegram(\\s*\\(\\d+\\))?$")).match(QString::fromStdWString(nameBuf)).hasMatch()) {
|
||||||
|
BOOL res = ::SetForegroundWindow(hWnd);
|
||||||
if ((uint64)dwProcessId == processId) { // found top-level window
|
::SetFocus(hWnd);
|
||||||
static const int32 nameBufSize = 1024;
|
return FALSE;
|
||||||
WCHAR nameBuf[nameBufSize];
|
|
||||||
int32 len = GetWindowText(hWnd, nameBuf, nameBufSize);
|
|
||||||
if (len && len < nameBufSize) {
|
|
||||||
if (QRegularExpression(qsl("^Telegram(\\s*\\(\\d+\\))?$")).match(QString::fromStdWString(nameBuf)).hasMatch()) {
|
|
||||||
BOOL res = ::SetForegroundWindow(hWnd);
|
|
||||||
::SetFocus(hWnd);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList psInitLogs() {
|
QStringList psInitLogs() {
|
||||||
|
@ -312,78 +288,10 @@ void SetApplicationIcon(const QIcon &icon) {
|
||||||
QApplication::setWindowIcon(icon);
|
QApplication::setWindowIcon(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CurrentExecutablePath(int argc, char *argv[]) {
|
|
||||||
WCHAR result[MAX_PATH + 1] = { 0 };
|
|
||||||
auto count = GetModuleFileName(nullptr, result, MAX_PATH + 1);
|
|
||||||
if (count < MAX_PATH + 1) {
|
|
||||||
auto info = QFileInfo(QDir::fromNativeSeparators(QString::fromWCharArray(result)));
|
|
||||||
return info.absoluteFilePath();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback to the first command line argument.
|
|
||||||
auto argsCount = 0;
|
|
||||||
if (auto args = CommandLineToArgvW(GetCommandLine(), &argsCount)) {
|
|
||||||
auto info = QFileInfo(QDir::fromNativeSeparators(QString::fromWCharArray(args[0])));
|
|
||||||
LocalFree(args);
|
|
||||||
return info.absoluteFilePath();
|
|
||||||
}
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString SingleInstanceLocalServerName(const QString &hash) {
|
QString SingleInstanceLocalServerName(const QString &hash) {
|
||||||
return qsl("Global\\") + hash + '-' + cGUIDStr();
|
return qsl("Global\\") + hash + '-' + cGUIDStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<crl::time> LastUserInputTime() {
|
|
||||||
auto lii = LASTINPUTINFO{ 0 };
|
|
||||||
lii.cbSize = sizeof(LASTINPUTINFO);
|
|
||||||
if (!GetLastInputInfo(&lii)) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
const auto now = crl::now();
|
|
||||||
const auto input = crl::time(lii.dwTime);
|
|
||||||
static auto LastTrackedInput = input;
|
|
||||||
static auto LastTrackedWhen = now;
|
|
||||||
|
|
||||||
const auto ticks32 = crl::time(GetTickCount());
|
|
||||||
const auto ticks64 = crl::time(GetTickCount64());
|
|
||||||
const auto elapsed = std::max(ticks32, ticks64) - input;
|
|
||||||
const auto good = (std::abs(ticks32 - ticks64) <= crl::time(1000))
|
|
||||||
&& (elapsed >= 0);
|
|
||||||
if (good) {
|
|
||||||
LastTrackedInput = input;
|
|
||||||
LastTrackedWhen = now;
|
|
||||||
return (now > elapsed) ? (now - elapsed) : crl::time(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static auto WaitingDelayed = false;
|
|
||||||
if (!WaitingDelayed) {
|
|
||||||
WaitingDelayed = true;
|
|
||||||
base::call_delayed(kRefreshBadLastUserInputTimeout, [=] {
|
|
||||||
WaitingDelayed = false;
|
|
||||||
[[maybe_unused]] const auto cheked = LastUserInputTime();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
constexpr auto OverrunLimit = std::numeric_limits<DWORD>::max();
|
|
||||||
constexpr auto OverrunThreshold = OverrunLimit / 4;
|
|
||||||
if (LastTrackedInput == input) {
|
|
||||||
return LastTrackedWhen;
|
|
||||||
}
|
|
||||||
const auto guard = gsl::finally([&] {
|
|
||||||
LastTrackedInput = input;
|
|
||||||
LastTrackedWhen = now;
|
|
||||||
});
|
|
||||||
if (input > LastTrackedInput) {
|
|
||||||
const auto add = input - LastTrackedInput;
|
|
||||||
return std::min(LastTrackedWhen + add, now);
|
|
||||||
} else if (crl::time(OverrunLimit) + input - LastTrackedInput
|
|
||||||
< crl::time(OverrunThreshold)) {
|
|
||||||
const auto add = crl::time(OverrunLimit) + input - LastTrackedInput;
|
|
||||||
return std::min(LastTrackedWhen + add, now);
|
|
||||||
}
|
|
||||||
return LastTrackedWhen;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<bool> IsDarkMode() {
|
std::optional<bool> IsDarkMode() {
|
||||||
static const auto kSystemVersion = QOperatingSystemVersion::current();
|
static const auto kSystemVersion = QOperatingSystemVersion::current();
|
||||||
static const auto kDarkModeAddedVersion = QOperatingSystemVersion(
|
static const auto kDarkModeAddedVersion = QOperatingSystemVersion(
|
||||||
|
|
|
@ -65,8 +65,6 @@ inline void psCheckLocalSocket(const QString &) {
|
||||||
|
|
||||||
void psWriteDump();
|
void psWriteDump();
|
||||||
|
|
||||||
void psDeleteDir(const QString &dir);
|
|
||||||
|
|
||||||
QStringList psInitLogs();
|
QStringList psInitLogs();
|
||||||
void psClearInitLogs();
|
void psClearInitLogs();
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "calls/calls_instance.h"
|
#include "calls/calls_instance.h"
|
||||||
#include "core/core_cloud_password.h"
|
#include "core/core_cloud_password.h"
|
||||||
#include "core/update_checker.h"
|
#include "core/update_checker.h"
|
||||||
#include "platform/platform_specific.h"
|
#include "base/platform/base_platform_last_input.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_chat.h"
|
#include "data/data_chat.h"
|
||||||
|
@ -288,7 +288,7 @@ void SetupLocalPasscode(
|
||||||
Ui::show(Box<PasscodeBox>(&controller->session(), true));
|
Ui::show(Box<PasscodeBox>(&controller->session(), true));
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto label = Platform::LastUserInputTimeSupported()
|
const auto label = base::Platform::LastUserInputTimeSupported()
|
||||||
? tr::lng_passcode_autolock_away
|
? tr::lng_passcode_autolock_away
|
||||||
: tr::lng_passcode_autolock_inactive;
|
: tr::lng_passcode_autolock_inactive;
|
||||||
auto value = PasscodeChanges(
|
auto value = PasscodeChanges(
|
||||||
|
|
|
@ -24,7 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "main/main_account.h"
|
#include "main/main_account.h"
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
#include "history/history_item.h"
|
#include "history/history_item.h"
|
||||||
#include "platform/platform_specific.h"
|
#include "base/platform/base_platform_last_input.h"
|
||||||
#include "base/call_delayed.h"
|
#include "base/call_delayed.h"
|
||||||
#include "facades.h"
|
#include "facades.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
|
@ -663,7 +663,7 @@ void Notification::prepareActionsCache() {
|
||||||
bool Notification::checkLastInput(bool hasReplyingNotifications) {
|
bool Notification::checkLastInput(bool hasReplyingNotifications) {
|
||||||
if (!_waitingForInput) return true;
|
if (!_waitingForInput) return true;
|
||||||
|
|
||||||
const auto waitForUserInput = Platform::LastUserInputTimeSupported()
|
const auto waitForUserInput = base::Platform::LastUserInputTimeSupported()
|
||||||
? (Core::App().lastNonIdleTime() <= _started)
|
? (Core::App().lastNonIdleTime() <= _started)
|
||||||
: false;
|
: false;
|
||||||
if (!waitForUserInput) {
|
if (!waitForUserInput) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "window/notifications_utilities.h"
|
#include "window/notifications_utilities.h"
|
||||||
|
|
||||||
#include "platform/platform_specific.h"
|
#include "base/platform/base_platform_file_utilities.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "data/data_peer.h"
|
#include "data/data_peer.h"
|
||||||
#include "ui/empty_userpic.h"
|
#include "ui/empty_userpic.h"
|
||||||
|
@ -36,7 +36,7 @@ CachedUserpics::~CachedUserpics() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// This works about 1200ms on Windows for a folder with one image O_o
|
// This works about 1200ms on Windows for a folder with one image O_o
|
||||||
// psDeleteDir(cWorkingDir() + qsl("tdata/temp"));
|
// base::Platform::DeleteDirectory(cWorkingDir() + qsl("tdata/temp"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue