feat: enter with ghost mode from taskbar or command line

This commit is contained in:
AlexeyZavar 2024-07-01 06:04:14 +03:00
parent 75bcd2b24b
commit c185f40acd
11 changed files with 75 additions and 39 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 609 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 887 B

View file

@ -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();
}

View file

@ -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 }};

View file

@ -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()) {

View file

@ -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<IShellLink>(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<IPropertyStore>()) {
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<IShellLink>(
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<IPropertyStore>()) {
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<IObjectCollection>(
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;

View file

@ -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();
}

View file

@ -60,6 +60,7 @@ public:
bool monochrome,
bool supportMode);
[[nodiscard]] static QString QuitJumpListIconPath();
[[nodiscard]] static QString GhostJumpListIconPath();
private:
base::unique_qptr<QPlatformSystemTrayIcon> _icon;

View file

@ -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;

View file

@ -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);