Add "Respect the Focus settings" on Windows.

This commit is contained in:
John Preston 2024-10-17 12:58:05 +04:00
parent e6af33367e
commit 285c96fd2e
5 changed files with 47 additions and 4 deletions

View file

@ -499,8 +499,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_settings_notify_global" = "Global settings";
"lng_settings_notify_title" = "Notifications for chats";
"lng_settings_desktop_notify" = "Desktop notifications";
"lng_settings_native_title" = "Native notifications";
"lng_settings_native_title" = "System integration";
"lng_settings_use_windows" = "Use Windows notifications";
"lng_settings_skip_in_focus" = "Respect system Focus mode";
"lng_settings_use_native_notifications" = "Use native notifications";
"lng_settings_notifications_position" = "Location on the screen";
"lng_settings_notifications_count" = "Notifications count";

View file

@ -222,7 +222,7 @@ QByteArray Settings::serialize() const {
+ Serialize::stringSize(_customFontFamily)
+ sizeof(qint32) * 3
+ Serialize::bytearraySize(_tonsiteStorageToken)
+ sizeof(qint32) * 2;
+ sizeof(qint32) * 3;
auto result = QByteArray();
result.reserve(size);
@ -378,7 +378,8 @@ QByteArray Settings::serialize() const {
<< qint32(!_weatherInCelsius ? 0 : *_weatherInCelsius ? 1 : 2)
<< _tonsiteStorageToken
<< qint32(_includeMutedCounterFolders ? 1 : 0)
<< qint32(_ivZoom.current());
<< qint32(_ivZoom.current())
<< qint32(_skipToastsInFocus ? 1 : 0);
}
Ensures(result.size() == size);
@ -503,6 +504,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
qint32 weatherInCelsius = !_weatherInCelsius ? 0 : *_weatherInCelsius ? 1 : 2;
QByteArray tonsiteStorageToken = _tonsiteStorageToken;
qint32 ivZoom = _ivZoom.current();
qint32 skipToastsInFocus = _skipToastsInFocus ? 1 : 0;
stream >> themesAccentColors;
if (!stream.atEnd()) {
@ -815,6 +817,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
if (!stream.atEnd()) {
stream >> ivZoom;
}
if (!stream.atEnd()) {
stream >> skipToastsInFocus;
}
if (stream.status() != QDataStream::Ok) {
LOG(("App Error: "
"Bad data for Core::Settings::constructFromSerialized()"));
@ -1027,6 +1032,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
: (weatherInCelsius == 1);
_tonsiteStorageToken = tonsiteStorageToken;
_ivZoom = ivZoom;
_skipToastsInFocus = (skipToastsInFocus == 1);
}
QString Settings::getSoundPath(const QString &key) const {
@ -1353,6 +1359,7 @@ void Settings::resetOnLastLogout() {
_flashBounceNotify = true;
_notifyView = NotifyView::ShowPreview;
//_nativeNotifications = std::nullopt;
//_skipToastsInFocus = false;
//_notificationsCount = 3;
//_notificationsCorner = ScreenCorner::BottomRight;
_includeMutedCounter = true;
@ -1472,6 +1479,14 @@ void Settings::setNativeNotifications(bool value) {
: std::make_optional(value);
}
bool Settings::skipToastsInFocus() const {
return _skipToastsInFocus;
}
void Settings::setSkipToastsInFocus(bool value) {
_skipToastsInFocus = value;
}
void Settings::setTranslateButtonEnabled(bool value) {
_translateButtonEnabled = value;
}

View file

@ -220,6 +220,9 @@ public:
[[nodiscard]] bool nativeNotifications() const;
void setNativeNotifications(bool value);
[[nodiscard]] bool skipToastsInFocus() const;
void setSkipToastsInFocus(bool value);
[[nodiscard]] int notificationsCount() const {
return _notificationsCount;
}
@ -958,6 +961,7 @@ private:
bool _flashBounceNotify = true;
NotifyView _notifyView = NotifyView::ShowPreview;
std::optional<bool> _nativeNotifications;
bool _skipToastsInFocus = false;
int _notificationsCount = 3;
ScreenCorner _notificationsCorner = ScreenCorner::BottomRight;
bool _includeMutedCounter = true;

View file

@ -367,6 +367,7 @@ bool SkipSoundForCustom() {
return (UserNotificationState == QUNS_NOT_PRESENT)
|| (UserNotificationState == QUNS_PRESENTATION_MODE)
|| (FocusAssistBlocks && Core::App().settings().skipToastsInFocus())
|| Core::App().screenIsLocked();
}
@ -387,7 +388,8 @@ bool SkipToastForCustom() {
QuerySystemNotificationSettings();
return (UserNotificationState == QUNS_PRESENTATION_MODE)
|| (UserNotificationState == QUNS_RUNNING_D3D_FULL_SCREEN);
|| (UserNotificationState == QUNS_RUNNING_D3D_FULL_SCREEN)
|| (FocusAssistBlocks && Core::App().settings().skipToastsInFocus());
}
void MaybeFlashBounceForCustom(Fn<void()> flashBounce) {

View file

@ -864,6 +864,27 @@ NotifyViewCheckboxes SetupNotifyViewOptions(
void SetupAdvancedNotifications(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) {
if (Platform::IsWindows()) {
const auto skipInFocus = container->add(object_ptr<Button>(
container,
tr::lng_settings_skip_in_focus(),
st::settingsButtonNoIcon
))->toggleOn(rpl::single(Core::App().settings().skipToastsInFocus()));
skipInFocus->toggledChanges(
) | rpl::filter([](bool checked) {
return (checked != Core::App().settings().skipToastsInFocus());
}) | rpl::start_with_next([=](bool checked) {
Core::App().settings().setSkipToastsInFocus(checked);
Core::App().saveSettingsDelayed();
if (checked && Platform::Notifications::SkipToastForCustom()) {
using Change = Window::Notifications::ChangeType;
Core::App().notifications().notifySettingsChanged(
Change::DesktopEnabled);
}
}, skipInFocus->lifetime());
}
Ui::AddSkip(container, st::settingsCheckboxesSkip);
Ui::AddDivider(container);
Ui::AddSkip(container, st::settingsCheckboxesSkip);