diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 58fe355b1..001a3ad23 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "chat_helpers/emoji_keywords.h" #include "chat_helpers/stickers_emoji_image_loader.h" #include "base/platform/base_platform_info.h" +#include "base/platform/base_platform_last_input.h" #include "platform/platform_specific.h" #include "mainwindow.h" #include "dialogs/dialogs_entry.h" @@ -807,7 +808,7 @@ void Application::updateNonIdle() { crl::time Application::lastNonIdleTime() const { return std::max( - Platform::LastUserInputTime().value_or(0), + base::Platform::LastUserInputTime().value_or(0), _lastNonIdleTime); } diff --git a/Telegram/SourceFiles/core/file_utilities.cpp b/Telegram/SourceFiles/core/file_utilities.cpp index 580be2082..5b3858ee6 100644 --- a/Telegram/SourceFiles/core/file_utilities.cpp +++ b/Telegram/SourceFiles/core/file_utilities.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/file_utilities.h" #include "storage/localstorage.h" +#include "base/platform/base_platform_file_utilities.h" #include "platform/platform_file_utilities.h" #include "core/application.h" #include "base/unixtime.h" @@ -154,7 +155,7 @@ void Launch(const QString &filepath) { void ShowInFolder(const QString &filepath) { crl::on_main([=] { Ui::PreventDelayedActivation(); - Platform::File::UnsafeShowInFolder(filepath); + base::Platform::ShowInFolder(filepath); }); } diff --git a/Telegram/SourceFiles/core/launcher.cpp b/Telegram/SourceFiles/core/launcher.cpp index ee01d01e0..28271acd9 100644 --- a/Telegram/SourceFiles/core/launcher.cpp +++ b/Telegram/SourceFiles/core/launcher.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_launcher.h" #include "platform/platform_specific.h" #include "base/platform/base_platform_info.h" +#include "base/platform/base_platform_file_utilities.h" #include "ui/main_queue_processor.h" #include "ui/ui_utility.h" #include "core/crash_reports.h" @@ -342,7 +343,7 @@ int Launcher::exec() { if (!UpdaterDisabled() && cRestartingUpdate()) { DEBUG_LOG(("Sandbox Info: executing updater to install update.")); if (!launchUpdater(UpdaterLaunch::PerformUpdate)) { - psDeleteDir(cWorkingDir() + qsl("tupdates/temp")); + base::Platform::DeleteDirectory(cWorkingDir() + qsl("tupdates/temp")); } } else if (cRestarting()) { DEBUG_LOG(("Sandbox Info: executing Telegram because of restart.")); @@ -402,7 +403,7 @@ bool Launcher::customWorkingDir() const { } void Launcher::prepareSettings() { - auto path = Platform::CurrentExecutablePath(_argc, _argv); + auto path = base::Platform::CurrentExecutablePath(_argc, _argv); LOG(("Executable path before check: %1").arg(path)); if (!path.isEmpty()) { auto info = QFileInfo(path); diff --git a/Telegram/SourceFiles/core/update_checker.cpp b/Telegram/SourceFiles/core/update_checker.cpp index 2c4fb4794..69ba0f74b 100644 --- a/Telegram/SourceFiles/core/update_checker.cpp +++ b/Telegram/SourceFiles/core/update_checker.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/update_checker.h" #include "base/platform/base_platform_info.h" +#include "base/platform/base_platform_file_utilities.h" #include "base/timer.h" #include "base/bytes.h" #include "base/unixtime.h" @@ -211,7 +212,7 @@ QString UpdatesFolder() { } void ClearAll() { - psDeleteDir(UpdatesFolder()); + base::Platform::DeleteDirectory(UpdatesFolder()); } QString FindUpdateFile() { @@ -270,7 +271,7 @@ bool UnpackUpdate(const QString &filepath) { input.close(); QString tempDirPath = cWorkingDir() + qsl("tupdates/temp"), readyFilePath = cWorkingDir() + qsl("tupdates/temp/ready"); - psDeleteDir(tempDirPath); + base::Platform::DeleteDirectory(tempDirPath); QDir tempDir(tempDirPath); if (tempDir.exists() || QFile(readyFilePath).exists()) { @@ -1560,8 +1561,8 @@ bool checkReadyUpdate() { #endif // Q_OS_UNIX #ifdef Q_OS_MAC - Platform::RemoveQuarantine(QFileInfo(curUpdater).absolutePath()); - Platform::RemoveQuarantine(updater.absolutePath()); + base::Platform::RemoveQuarantine(QFileInfo(curUpdater).absolutePath()); + base::Platform::RemoveQuarantine(updater.absolutePath()); #endif // Q_OS_MAC return true; diff --git a/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp b/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp index 5f14f4f97..0531a5b45 100644 --- a/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp @@ -11,11 +11,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/linux/linux_gdk_helper.h" #include "platform/linux/linux_desktop_environment.h" #include "platform/linux/specific_linux.h" -#include "boxes/abstract_box.h" #include "storage/localstorage.h" -#include "base/platform/base_platform_file_utilities.h" -#include #include 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 FileDialog { diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index ae7122f5c..f07b61349 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -174,33 +174,6 @@ QString FlatpakID() { 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) { const auto result = QProcess::execute(program, arguments); @@ -310,131 +283,6 @@ bool GetImageFromClipboardSupported() { } #endif // !TDESKTOP_DISABLE_GTK_INTEGRATION -std::optional 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(idle)); -} - -#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION -std::optional 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 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(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 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 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(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) { if (edges == (Qt::TopEdge | Qt::LeftEdge)) return 0; @@ -682,11 +530,6 @@ bool InSnap() { return Result; } -bool InAppImage() { - static const auto Result = qEnvironmentVariableIsSet("APPIMAGE"); - return Result; -} - bool IsStaticBinary() { #ifdef DESKTOP_APP_USE_PACKAGED return false; @@ -773,25 +616,6 @@ bool CanOpenDirectoryWithPortal() { 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() { static const auto Result = [&] { auto runtimeDir = QStandardPaths::writableLocation( @@ -908,29 +732,6 @@ QImage GetImageFromClipboard() { return data; } -std::optional 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 IsDarkMode() { #ifndef TDESKTOP_DISABLE_GTK_INTEGRATION if (Libs::GtkSettingSupported() && Libs::GtkLoaded()) { @@ -1089,41 +890,6 @@ QRect psDesktopRect() { 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) { // objc_activateProgram(); } @@ -1444,10 +1210,6 @@ void psNewVersion() { Platform::RegisterCustomScheme(); } -bool psShowOpenWithMenu(int x, int y, const QString &file) { - return false; -} - void psAutoStart(bool start, bool silent) { if (InFlatpak()) { #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.h b/Telegram/SourceFiles/platform/linux/specific_linux.h index f5cae2472..bc71760f8 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.h +++ b/Telegram/SourceFiles/platform/linux/specific_linux.h @@ -22,7 +22,6 @@ inline void SetWatchingMediaKeys(bool watching) { bool InFlatpak(); bool InSnap(); -bool InAppImage(); bool IsStaticBinary(); bool UseGtkIntegration(); bool IsGtkIntegrationForced(); @@ -55,8 +54,6 @@ inline void psCheckLocalSocket(const QString &serverName) { void psWriteDump(); -void psDeleteDir(const QString &dir); - QStringList psInitLogs(); void psClearInitLogs(); diff --git a/Telegram/SourceFiles/platform/mac/file_utilities_mac.mm b/Telegram/SourceFiles/platform/mac/file_utilities_mac.mm index 81f924734..59f7f7329 100644 --- a/Telegram/SourceFiles/platform/mac/file_utilities_mac.mm +++ b/Telegram/SourceFiles/platform/mac/file_utilities_mac.mm @@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/mac/file_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 "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 Platform diff --git a/Telegram/SourceFiles/platform/mac/launcher_mac.mm b/Telegram/SourceFiles/platform/mac/launcher_mac.mm index a8d0cb26b..94fa4d5e5 100644 --- a/Telegram/SourceFiles/platform/mac/launcher_mac.mm +++ b/Telegram/SourceFiles/platform/mac/launcher_mac.mm @@ -10,8 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/crash_reports.h" #include "core/update_checker.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 "platform/platform_specific.h" #include #include @@ -54,7 +54,7 @@ bool Launcher::launchUpdater(UpdaterLaunch action) { return false; } 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]; [args addObject:[NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]]]; diff --git a/Telegram/SourceFiles/platform/mac/specific_mac.h b/Telegram/SourceFiles/platform/mac/specific_mac.h index d217b83f6..419ea4241 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac.h +++ b/Telegram/SourceFiles/platform/mac/specific_mac.h @@ -16,8 +16,6 @@ class LocationPoint; namespace Platform { -void RemoveQuarantine(const QString &path); - [[nodiscard]] bool IsDarkMenuBar(); inline QImage GetImageFromClipboard() { @@ -76,8 +74,6 @@ inline void psCheckLocalSocket(const QString &serverName) { void psWriteDump(); -void psDeleteDir(const QString &dir); - QStringList psInitLogs(); void psClearInitLogs(); @@ -92,8 +88,6 @@ QRect psDesktopRect(); int psCleanup(); int psFixPrevious(); -bool psShowOpenWithMenu(int x, int y, const QString &file); - void psNewVersion(); void psDownloadPathEnableAccess(); diff --git a/Telegram/SourceFiles/platform/mac/specific_mac.mm b/Telegram/SourceFiles/platform/mac/specific_mac.mm index 1d7bfefc5..63d320087 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac.mm +++ b/Telegram/SourceFiles/platform/mac/specific_mac.mm @@ -65,10 +65,6 @@ void psWriteDump() { #endif // DESKTOP_APP_DISABLE_CRASH_REPORTS } -void psDeleteDir(const QString &dir) { - objc_deleteDir(dir); -} - QStringList psInitLogs() { return _initLogs; } @@ -118,10 +114,6 @@ void finish() { objc_finish(); } -QString CurrentExecutablePath(int argc, char *argv[]) { - return NS2QString([[NSBundle mainBundle] bundlePath]); -} - QString SingleInstanceLocalServerName(const QString &hash) { #ifndef OS_MAC_STORE return qsl("/tmp/") + hash + '-' + cGUIDStr(); @@ -130,14 +122,6 @@ QString SingleInstanceLocalServerName(const QString &hash) { #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 result = false; @autoreleasepool { @@ -234,60 +218,6 @@ bool OpenSystemSettings(SystemSettingsType type) { return true; } -// Taken from https://github.com/trueinteractions/tint/issues/53. -std::optional 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(idleTime)); -} - void IgnoreApplicationActivationRightNow() { objc_ignoreApplicationActivationRightNow(); } diff --git a/Telegram/SourceFiles/platform/mac/specific_mac_p.h b/Telegram/SourceFiles/platform/mac/specific_mac_p.h index 866e666f3..0a01209d3 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac_p.h +++ b/Telegram/SourceFiles/platform/mac/specific_mac_p.h @@ -19,7 +19,6 @@ void objc_finish(); void objc_activateProgram(WId winId); bool objc_moveFile(const QString &from, const QString &to); -void objc_deleteDir(const QString &dir); double objc_appkitVersion(); diff --git a/Telegram/SourceFiles/platform/mac/specific_mac_p.mm b/Telegram/SourceFiles/platform/mac/specific_mac_p.mm index 6d494395f..59b9539ee 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac_p.mm +++ b/Telegram/SourceFiles/platform/mac/specific_mac_p.mm @@ -340,14 +340,6 @@ bool objc_moveFile(const QString &from, const QString &to) { return false; } -void objc_deleteDir(const QString &dir) { - @autoreleasepool { - - [[NSFileManager defaultManager] removeItemAtPath:Q2NSString(dir) error:nil]; - - } -} - double objc_appkitVersion() { return NSAppKitVersionNumber; } diff --git a/Telegram/SourceFiles/platform/platform_file_utilities.h b/Telegram/SourceFiles/platform/platform_file_utilities.h index cd70b78a6..ad229d244 100644 --- a/Telegram/SourceFiles/platform/platform_file_utilities.h +++ b/Telegram/SourceFiles/platform/platform_file_utilities.h @@ -20,7 +20,6 @@ void UnsafeOpenEmailLink(const QString &email); bool UnsafeShowOpenWithDropdown(const QString &filepath, QPoint menuPosition); bool UnsafeShowOpenWith(const QString &filepath); void UnsafeLaunch(const QString &filepath); -void UnsafeShowInFolder(const QString &filepath); void PostprocessDownloaded(const QString &filepath); diff --git a/Telegram/SourceFiles/platform/platform_specific.h b/Telegram/SourceFiles/platform/platform_specific.h index cbdbb2ec3..0227a3174 100644 --- a/Telegram/SourceFiles/platform/platform_specific.h +++ b/Telegram/SourceFiles/platform/platform_specific.h @@ -31,24 +31,12 @@ enum class SystemSettingsType { void SetWatchingMediaKeys(bool watching); void SetApplicationIcon(const QIcon &icon); -QString CurrentExecutablePath(int argc, char *argv[]); QString SingleInstanceLocalServerName(const QString &hash); void RegisterCustomScheme(bool force = false); PermissionStatus GetPermissionStatus(PermissionType type); void RequestPermission(PermissionType type, Fn resultCallback); void OpenSystemSettingsForPermission(PermissionType type); bool OpenSystemSettings(SystemSettingsType type); - -[[nodiscard]] std::optional LastUserInputTime(); -[[nodiscard]] inline bool LastUserInputTimeSupported() { - return LastUserInputTime().has_value(); -} - -[[nodiscard]] std::optional IsDarkMode(); -[[nodiscard]] inline bool IsDarkModeSupported() { - return IsDarkMode().has_value(); -} - void IgnoreApplicationActivationRightNow(); bool AutostartSupported(); bool TrayIconSupported(); @@ -61,6 +49,11 @@ bool SetWindowExtents(QWindow *window, const QMargins &extents); bool UnsetWindowExtents(QWindow *window); Window::ControlsLayout WindowControlsLayout(); +[[nodiscard]] std::optional IsDarkMode(); +[[nodiscard]] inline bool IsDarkModeSupported() { + return IsDarkMode().has_value(); +} + namespace ThirdParty { void start(); diff --git a/Telegram/SourceFiles/platform/win/file_utilities_win.cpp b/Telegram/SourceFiles/platform/win/file_utilities_win.cpp index fe1dde530..b515f8e65 100644 --- a/Telegram/SourceFiles/platform/win/file_utilities_win.cpp +++ b/Telegram/SourceFiles/platform/win/file_utilities_win.cpp @@ -10,7 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "storage/localstorage.h" #include "platform/win/windows_dlls.h" -#include "base/platform/base_platform_file_utilities.h" #include "lang/lang_keys.h" #include "core/application.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); } -void UnsafeShowInFolder(const QString &filepath) { - base::Platform::ShowInFolder(filepath); -} - void PostprocessDownloaded(const QString &filepath) { 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); diff --git a/Telegram/SourceFiles/platform/win/file_utilities_win.h b/Telegram/SourceFiles/platform/win/file_utilities_win.h index 3647b1ca5..4a5b07f66 100644 --- a/Telegram/SourceFiles/platform/win/file_utilities_win.h +++ b/Telegram/SourceFiles/platform/win/file_utilities_win.h @@ -13,7 +13,7 @@ namespace Platform { namespace File { inline QString UrlToLocal(const QUrl &url) { - return url.toLocalFile(); + return ::File::internal::UrlToLocalDefault(url); } inline void UnsafeOpenUrl(const QString &url) { diff --git a/Telegram/SourceFiles/platform/win/specific_win.cpp b/Telegram/SourceFiles/platform/win/specific_win.cpp index 38cc936db..ae492a312 100644 --- a/Telegram/SourceFiles/platform/win/specific_win.cpp +++ b/Telegram/SourceFiles/platform/win/specific_win.cpp @@ -70,8 +70,6 @@ using namespace Platform; namespace { -constexpr auto kRefreshBadLastUserInputTimeout = 10 * crl::time(1000); - QStringList _initLogs; bool themeInited = false; @@ -87,49 +85,27 @@ public: }; _PsInitializer _psInitializer; -} // namespace +BOOL CALLBACK _ActivateProcess(HWND hWnd, LPARAM lParam) { + uint64 &processId(*(uint64*)lParam); -void psDeleteDir(const QString &dir) { - std::wstring wDir = QDir::toNativeSeparators(dir).toStdWString(); - 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); -} + DWORD dwProcessId; + ::GetWindowThreadProcessId(hWnd, &dwProcessId); -namespace { - BOOL CALLBACK _ActivateProcess(HWND hWnd, LPARAM lParam) { - uint64 &processId(*(uint64*)lParam); - - DWORD dwProcessId; - ::GetWindowThreadProcessId(hWnd, &dwProcessId); - - if ((uint64)dwProcessId == processId) { // found top-level window - static const int32 nameBufSize = 1024; - 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; - } + if ((uint64)dwProcessId == processId) { // found top-level window + static const int32 nameBufSize = 1024; + 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() { @@ -312,78 +288,10 @@ void SetApplicationIcon(const QIcon &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) { return qsl("Global\\") + hash + '-' + cGUIDStr(); } -std::optional 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::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 IsDarkMode() { static const auto kSystemVersion = QOperatingSystemVersion::current(); static const auto kDarkModeAddedVersion = QOperatingSystemVersion( diff --git a/Telegram/SourceFiles/platform/win/specific_win.h b/Telegram/SourceFiles/platform/win/specific_win.h index 1ef5471c1..92114eda5 100644 --- a/Telegram/SourceFiles/platform/win/specific_win.h +++ b/Telegram/SourceFiles/platform/win/specific_win.h @@ -65,8 +65,6 @@ inline void psCheckLocalSocket(const QString &) { void psWriteDump(); -void psDeleteDir(const QString &dir); - QStringList psInitLogs(); void psClearInitLogs(); diff --git a/Telegram/SourceFiles/settings/settings_privacy_security.cpp b/Telegram/SourceFiles/settings/settings_privacy_security.cpp index adac9798f..338009173 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_security.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_security.cpp @@ -32,7 +32,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "calls/calls_instance.h" #include "core/core_cloud_password.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 "data/data_session.h" #include "data/data_chat.h" @@ -288,7 +288,7 @@ void SetupLocalPasscode( Ui::show(Box(&controller->session(), true)); }); - const auto label = Platform::LastUserInputTimeSupported() + const auto label = base::Platform::LastUserInputTimeSupported() ? tr::lng_passcode_autolock_away : tr::lng_passcode_autolock_inactive; auto value = PasscodeChanges( diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index ad4ddfa57..3162481b6 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -24,7 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_account.h" #include "history/history.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 "facades.h" #include "app.h" @@ -663,7 +663,7 @@ void Notification::prepareActionsCache() { bool Notification::checkLastInput(bool hasReplyingNotifications) { if (!_waitingForInput) return true; - const auto waitForUserInput = Platform::LastUserInputTimeSupported() + const auto waitForUserInput = base::Platform::LastUserInputTimeSupported() ? (Core::App().lastNonIdleTime() <= _started) : false; if (!waitForUserInput) { diff --git a/Telegram/SourceFiles/window/notifications_utilities.cpp b/Telegram/SourceFiles/window/notifications_utilities.cpp index 86dc2a905..34b0c9cb0 100644 --- a/Telegram/SourceFiles/window/notifications_utilities.cpp +++ b/Telegram/SourceFiles/window/notifications_utilities.cpp @@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "window/notifications_utilities.h" -#include "platform/platform_specific.h" +#include "base/platform/base_platform_file_utilities.h" #include "core/application.h" #include "data/data_peer.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 - // psDeleteDir(cWorkingDir() + qsl("tdata/temp")); + // base::Platform::DeleteDirectory(cWorkingDir() + qsl("tdata/temp")); } }