mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 02:01:40 -05:00
Respecting Quite Hours in Windows.
Also closing current chat on window close or passcode lock.
This commit is contained in:
parent
cf247384d3
commit
0902741b85
16 changed files with 121 additions and 56 deletions
|
@ -43,6 +43,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
|||
#include "observer_peer.h"
|
||||
#include "window/chat_background.h"
|
||||
#include "window/notifications_manager.h"
|
||||
#include "platform/platform_notifications_manager.h"
|
||||
|
||||
namespace {
|
||||
App::LaunchState _launchState = App::Launched;
|
||||
|
@ -2399,7 +2400,9 @@ namespace {
|
|||
}
|
||||
|
||||
void playSound() {
|
||||
if (Global::SoundNotify() && !psSkipAudioNotify()) audioPlayNotify();
|
||||
if (Global::SoundNotify() && !Platform::Notifications::skipAudio()) {
|
||||
audioPlayNotify();
|
||||
}
|
||||
}
|
||||
|
||||
void checkImageCacheSize() {
|
||||
|
|
|
@ -1886,7 +1886,7 @@ void DialogsWidget::step_show(float64 ms, bool timer) {
|
|||
_a_show.stop();
|
||||
|
||||
onFilterUpdate();
|
||||
activate();
|
||||
if (App::wnd()) App::wnd()->setInnerFocus();
|
||||
|
||||
if (App::app()) App::app()->mtpUnpause();
|
||||
} else {
|
||||
|
|
|
@ -285,11 +285,15 @@ bool hideWindowNoQuit() {
|
|||
if (!App::quitting()) {
|
||||
if (auto w = App::wnd()) {
|
||||
if (cWorkMode() == dbiwmTrayOnly || cWorkMode() == dbiwmWindowAndTray) {
|
||||
return w->minimizeToTray();
|
||||
if (w->minimizeToTray()) {
|
||||
Ui::showChatsList();
|
||||
return true;
|
||||
}
|
||||
} else if (cPlatform() == dbipMac || cPlatform() == dbipMacOld) {
|
||||
w->closeWithoutDestroy();
|
||||
w->updateIsActive(Global::OfflineBlurTimeout());
|
||||
w->updateGlobalMenu();
|
||||
Ui::showChatsList();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
|||
#include "apiwrap.h"
|
||||
#include "settings/settings_widget.h"
|
||||
#include "window/notifications_manager.h"
|
||||
#include "platform/platform_notifications_manager.h"
|
||||
|
||||
ConnectingWidget::ConnectingWidget(QWidget *parent, const QString &text, const QString &reconnect) : QWidget(parent)
|
||||
, _shadow(st::boxShadow)
|
||||
|
@ -1120,11 +1121,10 @@ void MainWindow::notifySchedule(History *history, HistoryItem *item) {
|
|||
} else if (cOtherOnline() >= t) {
|
||||
delay = Global::NotifyDefaultDelay();
|
||||
}
|
||||
// LOG(("Is online: %1, otherOnline: %2, currentTime: %3, otherNotOld: %4, otherLaterThanMe: %5").arg(Logs::b(isOnline)).arg(cOtherOnline()).arg(t).arg(Logs::b(otherNotOld)).arg(Logs::b(otherLaterThanMe)));
|
||||
|
||||
uint64 when = ms + delay;
|
||||
_notifyWhenAlerts[history].insert(when, notifyByFrom);
|
||||
if (Global::DesktopNotify() && !psSkipDesktopNotify()) {
|
||||
if (Global::DesktopNotify() && !Platform::Notifications::skipToast()) {
|
||||
NotifyWhenMaps::iterator i = _notifyWhenMaps.find(history);
|
||||
if (i == _notifyWhenMaps.end()) {
|
||||
i = _notifyWhenMaps.insert(history, NotifyWhenMap());
|
||||
|
@ -1254,7 +1254,7 @@ void MainWindow::notifyShowNext() {
|
|||
App::playSound();
|
||||
}
|
||||
|
||||
if (_notifyWaiters.isEmpty() || !Global::DesktopNotify() || psSkipDesktopNotify()) {
|
||||
if (_notifyWaiters.isEmpty() || !Global::DesktopNotify() || Platform::Notifications::skipToast()) {
|
||||
if (nextAlert) {
|
||||
_notifyWaitTimer.start(nextAlert - ms);
|
||||
}
|
||||
|
|
|
@ -531,7 +531,7 @@ void OverviewInner::dragActionFinish(const QPoint &screenPos, Qt::MouseButton bu
|
|||
auto sel = _selected.cbegin().value();
|
||||
if (sel != FullSelection && sel.from == sel.to) {
|
||||
_selected.clear();
|
||||
App::main()->activate();
|
||||
App::wnd()->setInnerFocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,6 +142,8 @@ void PasscodeWidget::step_show(float64 ms, bool timer) {
|
|||
if (App::wnd()) App::wnd()->setInnerFocus();
|
||||
|
||||
if (App::app()) App::app()->mtpUnpause();
|
||||
|
||||
Ui::showChatsList();
|
||||
} else {
|
||||
a_coordUnder.update(dt, st::slideFunction);
|
||||
a_coordOver.update(dt, st::slideFunction);
|
||||
|
|
|
@ -25,6 +25,15 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
|||
namespace Platform {
|
||||
namespace Notifications {
|
||||
|
||||
inline void defaultNotificationShown(QWidget *widget) {
|
||||
}
|
||||
inline bool skipAudio() {
|
||||
return false;
|
||||
}
|
||||
inline bool skipToast() {
|
||||
return false;
|
||||
}
|
||||
|
||||
class Manager;
|
||||
|
||||
void start();
|
||||
|
@ -32,9 +41,6 @@ Manager *manager();
|
|||
bool supported();
|
||||
void finish();
|
||||
|
||||
inline void defaultNotificationShown(QWidget *widget) {
|
||||
}
|
||||
|
||||
class Manager : public Window::Notifications::NativeManager {
|
||||
public:
|
||||
Manager();
|
||||
|
|
|
@ -25,14 +25,20 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
|||
namespace Platform {
|
||||
namespace Notifications {
|
||||
|
||||
void defaultNotificationShown(QWidget *widget);
|
||||
inline bool skipAudio() {
|
||||
return false;
|
||||
}
|
||||
inline bool skipToast() {
|
||||
return false;
|
||||
}
|
||||
|
||||
class Manager;
|
||||
|
||||
void start();
|
||||
Manager *manager();
|
||||
void finish();
|
||||
|
||||
void defaultNotificationShown(QWidget *widget);
|
||||
|
||||
class Manager : public Window::Notifications::NativeManager {
|
||||
public:
|
||||
Manager();
|
||||
|
|
|
@ -23,6 +23,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
|||
|
||||
#include "window/notifications_utilities.h"
|
||||
#include "platform/win/windows_app_user_model_id.h"
|
||||
#include "platform/win/windows_event_filter.h"
|
||||
#include "platform/win/windows_dlls.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
|
@ -534,5 +535,87 @@ void Manager::onAfterNotificationActivated(PeerId peerId, MsgId msgId) {
|
|||
_impl->afterNotificationActivated(peerId, msgId);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
bool QuiteHoursEnabled = false;
|
||||
DWORD QuiteHoursValue = 0;
|
||||
|
||||
void queryQuiteHours() {
|
||||
LPTSTR lpKeyName = L"Software\\Microsoft\\Windows\\CurrentVersion\\Notifications\\Settings";
|
||||
LPTSTR lpValueName = L"NOC_GLOBAL_SETTING_TOASTS_ENABLED";
|
||||
HKEY key;
|
||||
auto result = RegOpenKeyEx(HKEY_CURRENT_USER, lpKeyName, 0, KEY_READ, &key);
|
||||
if (result != ERROR_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD value = 0, type = 0, size = sizeof(value);
|
||||
result = RegQueryValueEx(key, lpValueName, 0, &type, (LPBYTE)&value, &size);
|
||||
RegCloseKey(key);
|
||||
|
||||
auto quiteHoursEnabled = (result == ERROR_SUCCESS);
|
||||
if (QuiteHoursEnabled != quiteHoursEnabled) {
|
||||
QuiteHoursEnabled = quiteHoursEnabled;
|
||||
QuiteHoursValue = value;
|
||||
LOG(("Quite hours changed, entry value: %1").arg(value));
|
||||
} else if (QuiteHoursValue != value) {
|
||||
QuiteHoursValue = value;
|
||||
LOG(("Quite hours value changed, was value: %1, entry value: %2").arg(QuiteHoursValue).arg(value));
|
||||
}
|
||||
}
|
||||
|
||||
QUERY_USER_NOTIFICATION_STATE UserNotificationState = QUNS_ACCEPTS_NOTIFICATIONS;
|
||||
|
||||
void queryUserNotificationState() {
|
||||
if (Dlls::SHQueryUserNotificationState != nullptr) {
|
||||
QUERY_USER_NOTIFICATION_STATE state;
|
||||
if (SUCCEEDED(Dlls::SHQueryUserNotificationState(&state))) {
|
||||
UserNotificationState = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr int QuerySettingsEachMs = 1000;
|
||||
uint64 LastSettingsQueryMs = 0;
|
||||
|
||||
void querySystemNotificationSettings() {
|
||||
auto ms = getms(true);
|
||||
if (LastSettingsQueryMs > 0 && ms <= LastSettingsQueryMs + QuerySettingsEachMs) {
|
||||
return;
|
||||
}
|
||||
LastSettingsQueryMs = ms;
|
||||
queryQuiteHours();
|
||||
queryUserNotificationState();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool skipAudio() {
|
||||
querySystemNotificationSettings();
|
||||
|
||||
if (UserNotificationState == QUNS_NOT_PRESENT || UserNotificationState == QUNS_PRESENTATION_MODE) {
|
||||
return true;
|
||||
}
|
||||
if (QuiteHoursEnabled) {
|
||||
return true;
|
||||
}
|
||||
if (EventFilter::getInstance()->sessionLoggedOff()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool skipToast() {
|
||||
querySystemNotificationSettings();
|
||||
|
||||
if (UserNotificationState == QUNS_PRESENTATION_MODE || UserNotificationState == QUNS_RUNNING_D3D_FULL_SCREEN/* || UserNotificationState == QUNS_BUSY*/) {
|
||||
return true;
|
||||
}
|
||||
if (QuiteHoursEnabled) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace Notifications
|
||||
} // namespace Platform
|
||||
|
|
|
@ -25,6 +25,11 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
|||
namespace Platform {
|
||||
namespace Notifications {
|
||||
|
||||
inline void defaultNotificationShown(QWidget *widget) {
|
||||
}
|
||||
bool skipAudio();
|
||||
bool skipToast();
|
||||
|
||||
class Manager;
|
||||
|
||||
void start();
|
||||
|
@ -32,9 +37,6 @@ Manager *manager();
|
|||
bool supported();
|
||||
void finish();
|
||||
|
||||
inline void defaultNotificationShown(QWidget *widget) {
|
||||
}
|
||||
|
||||
class Manager : public Window::Notifications::NativeManager {
|
||||
public:
|
||||
Manager();
|
||||
|
|
|
@ -294,14 +294,6 @@ uint64 psIdleTime() {
|
|||
return getms(true) - _lastUserAction;
|
||||
}
|
||||
|
||||
bool psSkipAudioNotify() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool psSkipDesktopNotify() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void psActivateProcess(uint64 pid) {
|
||||
// objc_activateProgram();
|
||||
}
|
||||
|
|
|
@ -39,9 +39,6 @@ void psUserActionDone();
|
|||
bool psIdleSupported();
|
||||
uint64 psIdleTime();
|
||||
|
||||
bool psSkipAudioNotify();
|
||||
bool psSkipDesktopNotify();
|
||||
|
||||
QStringList psInitLogs();
|
||||
void psClearInitLogs();
|
||||
|
||||
|
|
|
@ -302,14 +302,6 @@ uint64 psIdleTime() {
|
|||
return objc_idleTime(idleTime) ? idleTime : (getms(true) - _lastUserAction);
|
||||
}
|
||||
|
||||
bool psSkipAudioNotify() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool psSkipDesktopNotify() {
|
||||
return false;
|
||||
}
|
||||
|
||||
QStringList psInitLogs() {
|
||||
return _initLogs;
|
||||
}
|
||||
|
|
|
@ -42,9 +42,6 @@ void psUserActionDone();
|
|||
bool psIdleSupported();
|
||||
uint64 psIdleTime();
|
||||
|
||||
bool psSkipAudioNotify();
|
||||
bool psSkipDesktopNotify();
|
||||
|
||||
QStringList psInitLogs();
|
||||
void psClearInitLogs();
|
||||
|
||||
|
|
|
@ -176,22 +176,6 @@ uint64 psIdleTime() {
|
|||
return GetLastInputInfo(&lii) ? (GetTickCount() - lii.dwTime) : (getms(true) - _lastUserAction);
|
||||
}
|
||||
|
||||
bool psSkipAudioNotify() {
|
||||
QUERY_USER_NOTIFICATION_STATE state;
|
||||
if (useShellapi && SUCCEEDED(Dlls::SHQueryUserNotificationState(&state))) {
|
||||
if (state == QUNS_NOT_PRESENT || state == QUNS_PRESENTATION_MODE) return true;
|
||||
}
|
||||
return EventFilter::getInstance()->sessionLoggedOff();
|
||||
}
|
||||
|
||||
bool psSkipDesktopNotify() {
|
||||
QUERY_USER_NOTIFICATION_STATE state;
|
||||
if (useShellapi && SUCCEEDED(Dlls::SHQueryUserNotificationState(&state))) {
|
||||
if (state == QUNS_PRESENTATION_MODE || state == QUNS_RUNNING_D3D_FULL_SCREEN/* || state == QUNS_BUSY*/) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QStringList psInitLogs() {
|
||||
return _initLogs;
|
||||
}
|
||||
|
|
|
@ -38,9 +38,6 @@ void psUserActionDone();
|
|||
bool psIdleSupported();
|
||||
uint64 psIdleTime();
|
||||
|
||||
bool psSkipAudioNotify();
|
||||
bool psSkipDesktopNotify();
|
||||
|
||||
QStringList psInitLogs();
|
||||
void psClearInitLogs();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue