From c185f40acd309e7cec8e506cbcad761a9a2c0cd2 Mon Sep 17 00:00:00 2001 From: AlexeyZavar Date: Mon, 1 Jul 2024 06:04:14 +0300 Subject: [PATCH] feat: enter with ghost mode from taskbar or command line --- Telegram/Resources/icons/ayu/ghost_tray.png | Bin 0 -> 371 bytes .../Resources/icons/ayu/ghost_tray@2x.png | Bin 0 -> 609 bytes .../Resources/icons/ayu/ghost_tray@3x.png | Bin 0 -> 887 bytes Telegram/SourceFiles/ayu/ayu_settings.cpp | 9 +++ Telegram/SourceFiles/ayu/ui/ayu_icons.style | 2 + Telegram/SourceFiles/core/launcher.cpp | 2 + .../platform/win/integration_win.cpp | 76 +++++++++--------- .../SourceFiles/platform/win/tray_win.cpp | 22 ++++- Telegram/SourceFiles/platform/win/tray_win.h | 1 + Telegram/SourceFiles/settings.cpp | 1 + Telegram/SourceFiles/settings.h | 1 + 11 files changed, 75 insertions(+), 39 deletions(-) create mode 100644 Telegram/Resources/icons/ayu/ghost_tray.png create mode 100644 Telegram/Resources/icons/ayu/ghost_tray@2x.png create mode 100644 Telegram/Resources/icons/ayu/ghost_tray@3x.png diff --git a/Telegram/Resources/icons/ayu/ghost_tray.png b/Telegram/Resources/icons/ayu/ghost_tray.png new file mode 100644 index 0000000000000000000000000000000000000000..e3973fd5c0e9731dbf4926a344939811aec58e96 GIT binary patch literal 371 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9GG!XV7ZFl&wkP>``W z$lZxy-8q?;Kn_c~qpu?a!^VE@KZ&eBISx-3$B+ufx4{>ux&-j-H5S!yWG``0FIm81 z<-oeafwQE6D}Yh!#J<^^AMd%j)mr|u_4he7PgHky&ITHy%j10VbIh~KY3yx@6IQJ{ zQX2bnCjV{CE+_6?>n3Y-scekDe(_pDmt#o3O4|9D_ zg=dl9A@)O`_e?*!&9B8wMR@;BzXF-(n>N4QtmYfcD7q}6Y=W|yXVEW_!rR-H%N&cW z{$4A8deZ^6zqR-4_uibbtaE<;3Z8$#|EBVl@9E@cEck7w#CrYGciUOZ8UrQMuJ7_I zer3_;T)VDT=D6|yW8Bp$n{LSTO4WWYPl^qn(cQe$Pxp!R$<9qWA6Y${#9ztp56J_D O5re0zpUXO@geCxaaFaIx literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/ayu/ghost_tray@2x.png b/Telegram/Resources/icons/ayu/ghost_tray@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..f00f8d2d430ba43c01284d3fc3d633193ce14ef8 GIT binary patch literal 609 zcmV-n0-pVeP)0E;leNiTrbh30T=b z5!^?D7+wO?>GUhXeI$tWM8HbV^V7l03bUxqr;se)CI!3SEV$H`CorGNQp}$1^R3`M z6&{OHku+k1Y<>v& z*!>>E(ga29rsi&{S&GG~oc>o;32hB22viMPuh;ImTCIXU6drJRrV=Q08;wSlEBI55 z#jMtpKen1cO`s-F6ZoG5TCLXOhn86`4_qq9)09j4>GNH&^x{HY4_(8+qTYi;!=HLX zzl|yOG#oR6KrVDoR3hq=V)p|0d}P*x0w4g|gGf0b|QweZ^+XyqS00000NkvXXu0mjf)7c2+ literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/ayu/ghost_tray@3x.png b/Telegram/Resources/icons/ayu/ghost_tray@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..c92a525c22ce21df53055da09e9bced877b6ab75 GIT binary patch literal 887 zcmV--1Bm>IP)M#s7Ouz=P0c-$F02{ytWCPd$HUK7o4S)%N319=*Am7iwY8Bzwal+N~F7Hl9oW`=A zEIX0hhEgh3713(7)Ob8r-ELQPIvv&P^~^m8;eNjxxm+&lbUK+|wBLcWjA-N1*=&{` z4u`ZX(04MK7+q!UP-P5XEEehG@krl=+wEp_>e&k>&>$8?kR*wk&*z!Yka#|y-=RXF zaH7!41NvzqYP;R45O`U_Gp+4)({#7nIrRn1hWi2SH8aH$2q8TimEsph zLWfO1?qTdo1O|hFHP)BQWz~iELS(&OTb%?ON)Z5in^*e%{@V<)nnAsq?ZoCL7FeS+~k8e}M2 z7WGd%Xkv~jrHPGD*@^Koau@p@+B%9YxjQ4(6NP*V;27Jzn|)T61lmsweb4K zPx3yA!^tYM(y{-BD8|}>vJldEv!YMvCc)PNY&Q2LGbAY?#&d;5UUu?DiCw1Xc=+&> zVbnw#$ictkeb65KzQ%VxZ|6Y|YSK=Ec9<#(q@o0Ip<(pmPSN4i}Ec zW2TJ+smTWo@jig;D-^O%s19BTFa)>W`x)5F0gt*r*A_Mol0#Y67uQ6NrtPKy1_mej6`^ z174%yCm~4nP_sb>gkl#2DIn@bz9JUtMR*qaAashUJn1RUijktiCiKBI?@_;@l zk02b-r${|X0{w@>p}Dr6ixu&J4-^I=z!(&=E_>Ka{!AssE*^l`!X!x&Cs_c4^P^Fp zgUE1%1TVAD`7!j76D^19;iV1wcL6>t7y#ZLjYiJJO?4zPI>)HO@(=R7>RF_JGt~e9 N002ovPDHLkV1giAiS_^h literal 0 HcmV?d00001 diff --git a/Telegram/SourceFiles/ayu/ayu_settings.cpp b/Telegram/SourceFiles/ayu/ayu_settings.cpp index 243083867..b6ec7f765 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.cpp +++ b/Telegram/SourceFiles/ayu/ayu_settings.cpp @@ -164,6 +164,15 @@ void load() { } catch (...) { LOG(("AyuGramSettings: failed to read settings file (not json-like)")); } + + if (cGhost()) { + settings->sendReadMessages = false; + settings->sendReadStories = false; + settings->sendOnlinePackets = false; + settings->sendUploadProgress = false; + settings->sendOfflinePacketAfterOnline = true; + } + postinitialize(); } diff --git a/Telegram/SourceFiles/ayu/ui/ayu_icons.style b/Telegram/SourceFiles/ayu/ui/ayu_icons.style index 0416ce22f..fa8f664c3 100644 --- a/Telegram/SourceFiles/ayu/ui/ayu_icons.style +++ b/Telegram/SourceFiles/ayu/ui/ayu_icons.style @@ -23,3 +23,5 @@ outChannelBadgeIcon: icon {{ "ayu/channel", msgOutDateFg }}; outChannelBadgeSelectedIcon: icon {{ "ayu/channel", msgOutDateFgSelected }}; infoExteraBadge: icon {{ "ayu/exterabadge", profileVerifiedCheckBg }}; + +winEnterWithGuestIcon: icon {{ "ayu/ghost_tray", windowFg }}; diff --git a/Telegram/SourceFiles/core/launcher.cpp b/Telegram/SourceFiles/core/launcher.cpp index 67f44a1e2..50af38902 100644 --- a/Telegram/SourceFiles/core/launcher.cpp +++ b/Telegram/SourceFiles/core/launcher.cpp @@ -516,6 +516,7 @@ void Launcher::processArguments() { { "-tosettings" , KeyFormat::NoValues }, { "-startintray" , KeyFormat::NoValues }, { "-quit" , KeyFormat::NoValues }, + { "-ghost" , KeyFormat::NoValues }, { "-sendpath" , KeyFormat::AllLeftValues }, { "-workdir" , KeyFormat::OneValue }, { "--" , KeyFormat::OneValue }, @@ -559,6 +560,7 @@ void Launcher::processArguments() { gStartToSettings = parseResult.contains("-tosettings"); gStartInTray = parseResult.contains("-startintray"); gQuit = parseResult.contains("-quit"); + gGhost = parseResult.contains("-ghost"); gSendPaths = parseResult.value("-sendpath", {}); _customWorkingDir = parseResult.value("-workdir", {}).join(QString()); if (!_customWorkingDir.isEmpty()) { diff --git a/Telegram/SourceFiles/platform/win/integration_win.cpp b/Telegram/SourceFiles/platform/win/integration_win.cpp index 0a44470da..71856388e 100644 --- a/Telegram/SourceFiles/platform/win/integration_win.cpp +++ b/Telegram/SourceFiles/platform/win/integration_win.cpp @@ -63,6 +63,38 @@ void WindowsIntegration::createCustomJumpList() { } } +void AddJumpListItem(IObjectCollection* collection, const QString& title, const QString& args, const QString& icon) { + auto shellLink = base::WinRT::TryCreateInstance(CLSID_ShellLink); + if (!shellLink) { + return; + } + + const auto exe = QDir::toNativeSeparators(cExeDir() + cExeName()); + const auto dir = QDir::toNativeSeparators(QDir(cWorkingDir()).absolutePath()); + shellLink->SetArguments(args.toStdWString().c_str()); + shellLink->SetPath(exe.toStdWString().c_str()); + shellLink->SetWorkingDirectory(dir.toStdWString().c_str()); + shellLink->SetIconLocation(icon.toStdWString().c_str(), 0); + + if (const auto propertyStore = shellLink.try_as()) { + auto appIdPropVar = PROPVARIANT(); + HRESULT hr = InitPropVariantFromString(AppUserModelId::Id().c_str(), &appIdPropVar); + if (SUCCEEDED(hr)) { + hr = propertyStore->SetValue(AppUserModelId::Key(), appIdPropVar); + PropVariantClear(&appIdPropVar); + } + auto titlePropVar = PROPVARIANT(); + hr = InitPropVariantFromString(title.toStdWString().c_str(), &titlePropVar); + if (SUCCEEDED(hr)) { + hr = propertyStore->SetValue(PKEY_Title, titlePropVar); + PropVariantClear(&titlePropVar); + } + propertyStore->Commit(); + } + + collection->AddObject(shellLink.get()); +} + void WindowsIntegration::refreshCustomJumpList() { auto added = false; auto maxSlots = UINT(); @@ -79,49 +111,17 @@ void WindowsIntegration::refreshCustomJumpList() { } }); - auto shellLink = base::WinRT::TryCreateInstance( - CLSID_ShellLink); - if (!shellLink) { - return; - } - - // Set the path to your application and the command-line argument for quitting - const auto exe = QDir::toNativeSeparators(cExeDir() + cExeName()); - const auto dir = QDir::toNativeSeparators(QDir(cWorkingDir()).absolutePath()); - const auto icon = Tray::QuitJumpListIconPath(); - shellLink->SetArguments(L"-quit"); - shellLink->SetPath(exe.toStdWString().c_str()); - shellLink->SetWorkingDirectory(dir.toStdWString().c_str()); - shellLink->SetIconLocation(icon.toStdWString().c_str(), 0); - - if (const auto propertyStore = shellLink.try_as()) { - auto appIdPropVar = PROPVARIANT(); - hr = InitPropVariantFromString( - AppUserModelId::Id().c_str(), - &appIdPropVar); - if (SUCCEEDED(hr)) { - hr = propertyStore->SetValue( - AppUserModelId::Key(), - appIdPropVar); - PropVariantClear(&appIdPropVar); - } - auto titlePropVar = PROPVARIANT(); - hr = InitPropVariantFromString( - tr::lng_quit_from_tray(tr::now).toStdWString().c_str(), - &titlePropVar); - if (SUCCEEDED(hr)) { - hr = propertyStore->SetValue(PKEY_Title, titlePropVar); - PropVariantClear(&titlePropVar); - } - propertyStore->Commit(); - } - auto collection = base::WinRT::TryCreateInstance( CLSID_EnumerableObjectCollection); if (!collection) { return; } - collection->AddObject(shellLink.get()); + + // add "Enter with Ghost" item + AddJumpListItem(collection.get(), tr::ayu_GhostModeShortcut(tr::now), "-ghost", Tray::GhostJumpListIconPath()); + + // add "Quit" item + AddJumpListItem(collection.get(), tr::lng_quit_from_tray(tr::now), "-quit", Tray::QuitJumpListIconPath()); _jumpList->AddUserTasks(collection.get()); added = true; diff --git a/Telegram/SourceFiles/platform/win/tray_win.cpp b/Telegram/SourceFiles/platform/win/tray_win.cpp index a0b171f71..256f5e623 100644 --- a/Telegram/SourceFiles/platform/win/tray_win.cpp +++ b/Telegram/SourceFiles/platform/win/tray_win.cpp @@ -30,7 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL // AyuGram includes #include "ayu/ui/ayu_logo.h" -#include "ui/painter.h" +#include "styles/style_ayu_icons.h" namespace Platform { @@ -453,6 +453,26 @@ QString Tray::QuitJumpListIconPath() { return path; } +QString Tray::GhostJumpListIconPath() { + const auto dark = IsDarkTaskbar(); + const auto key = !dark ? 0 : *dark ? 1 : 2; + const auto path = cWorkingDir() + u"tdata/temp/ghost_%1.ico"_q.arg(key); + if (QFile::exists(path)) { + return path; + } + const auto color = !dark + ? st::trayCounterBg->c + : *dark + ? QColor(255, 255, 255) + : QColor(0, 0, 0, 228); + WriteIco(path, { + st::winEnterWithGuestIcon.instance(color, 100, true), + st::winEnterWithGuestIcon.instance(color, 200, true), + st::winEnterWithGuestIcon.instance(color, 300, true), + }); + return path; +} + bool HasMonochromeSetting() { return IsDarkTaskbar().has_value(); } diff --git a/Telegram/SourceFiles/platform/win/tray_win.h b/Telegram/SourceFiles/platform/win/tray_win.h index cb79c3beb..0297378f5 100644 --- a/Telegram/SourceFiles/platform/win/tray_win.h +++ b/Telegram/SourceFiles/platform/win/tray_win.h @@ -60,6 +60,7 @@ public: bool monochrome, bool supportMode); [[nodiscard]] static QString QuitJumpListIconPath(); + [[nodiscard]] static QString GhostJumpListIconPath(); private: base::unique_qptr _icon; diff --git a/Telegram/SourceFiles/settings.cpp b/Telegram/SourceFiles/settings.cpp index 4e2f6e878..366f94946 100644 --- a/Telegram/SourceFiles/settings.cpp +++ b/Telegram/SourceFiles/settings.cpp @@ -34,6 +34,7 @@ LaunchMode gLaunchMode = LaunchModeNormal; bool gSeenTrayTooltip = false; bool gRestartingUpdate = false, gRestarting = false, gRestartingToSettings = false, gWriteProtected = false; bool gQuit = false; +bool gGhost = false; int32 gLastUpdateCheck = 0; bool gNoStartUpdate = false; bool gStartToSettings = false; diff --git a/Telegram/SourceFiles/settings.h b/Telegram/SourceFiles/settings.h index c0d6f1cbb..7902b7754 100644 --- a/Telegram/SourceFiles/settings.h +++ b/Telegram/SourceFiles/settings.h @@ -82,6 +82,7 @@ DeclareSetting(bool, StartToSettings); DeclareSetting(bool, DebugMode); DeclareReadSetting(bool, ManyInstance); DeclareSetting(bool, Quit); +DeclareSetting(bool, Ghost); DeclareSetting(QByteArray, LocalSalt); DeclareSetting(int, ScreenScale);