mirror of https://github.com/procxx/kepka.git
Respecting Quite Hours in Windows.
Also closing current chat on window close or passcode lock.
This commit is contained in:
parent
cf247384d3
commit
0902741b85
|
@ -43,6 +43,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
||||||
#include "observer_peer.h"
|
#include "observer_peer.h"
|
||||||
#include "window/chat_background.h"
|
#include "window/chat_background.h"
|
||||||
#include "window/notifications_manager.h"
|
#include "window/notifications_manager.h"
|
||||||
|
#include "platform/platform_notifications_manager.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
App::LaunchState _launchState = App::Launched;
|
App::LaunchState _launchState = App::Launched;
|
||||||
|
@ -2399,7 +2400,9 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
void playSound() {
|
void playSound() {
|
||||||
if (Global::SoundNotify() && !psSkipAudioNotify()) audioPlayNotify();
|
if (Global::SoundNotify() && !Platform::Notifications::skipAudio()) {
|
||||||
|
audioPlayNotify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkImageCacheSize() {
|
void checkImageCacheSize() {
|
||||||
|
|
|
@ -1886,7 +1886,7 @@ void DialogsWidget::step_show(float64 ms, bool timer) {
|
||||||
_a_show.stop();
|
_a_show.stop();
|
||||||
|
|
||||||
onFilterUpdate();
|
onFilterUpdate();
|
||||||
activate();
|
if (App::wnd()) App::wnd()->setInnerFocus();
|
||||||
|
|
||||||
if (App::app()) App::app()->mtpUnpause();
|
if (App::app()) App::app()->mtpUnpause();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -285,11 +285,15 @@ bool hideWindowNoQuit() {
|
||||||
if (!App::quitting()) {
|
if (!App::quitting()) {
|
||||||
if (auto w = App::wnd()) {
|
if (auto w = App::wnd()) {
|
||||||
if (cWorkMode() == dbiwmTrayOnly || cWorkMode() == dbiwmWindowAndTray) {
|
if (cWorkMode() == dbiwmTrayOnly || cWorkMode() == dbiwmWindowAndTray) {
|
||||||
return w->minimizeToTray();
|
if (w->minimizeToTray()) {
|
||||||
|
Ui::showChatsList();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
} else if (cPlatform() == dbipMac || cPlatform() == dbipMacOld) {
|
} else if (cPlatform() == dbipMac || cPlatform() == dbipMacOld) {
|
||||||
w->closeWithoutDestroy();
|
w->closeWithoutDestroy();
|
||||||
w->updateIsActive(Global::OfflineBlurTimeout());
|
w->updateIsActive(Global::OfflineBlurTimeout());
|
||||||
w->updateGlobalMenu();
|
w->updateGlobalMenu();
|
||||||
|
Ui::showChatsList();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "settings/settings_widget.h"
|
#include "settings/settings_widget.h"
|
||||||
#include "window/notifications_manager.h"
|
#include "window/notifications_manager.h"
|
||||||
|
#include "platform/platform_notifications_manager.h"
|
||||||
|
|
||||||
ConnectingWidget::ConnectingWidget(QWidget *parent, const QString &text, const QString &reconnect) : QWidget(parent)
|
ConnectingWidget::ConnectingWidget(QWidget *parent, const QString &text, const QString &reconnect) : QWidget(parent)
|
||||||
, _shadow(st::boxShadow)
|
, _shadow(st::boxShadow)
|
||||||
|
@ -1120,11 +1121,10 @@ void MainWindow::notifySchedule(History *history, HistoryItem *item) {
|
||||||
} else if (cOtherOnline() >= t) {
|
} else if (cOtherOnline() >= t) {
|
||||||
delay = Global::NotifyDefaultDelay();
|
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;
|
uint64 when = ms + delay;
|
||||||
_notifyWhenAlerts[history].insert(when, notifyByFrom);
|
_notifyWhenAlerts[history].insert(when, notifyByFrom);
|
||||||
if (Global::DesktopNotify() && !psSkipDesktopNotify()) {
|
if (Global::DesktopNotify() && !Platform::Notifications::skipToast()) {
|
||||||
NotifyWhenMaps::iterator i = _notifyWhenMaps.find(history);
|
NotifyWhenMaps::iterator i = _notifyWhenMaps.find(history);
|
||||||
if (i == _notifyWhenMaps.end()) {
|
if (i == _notifyWhenMaps.end()) {
|
||||||
i = _notifyWhenMaps.insert(history, NotifyWhenMap());
|
i = _notifyWhenMaps.insert(history, NotifyWhenMap());
|
||||||
|
@ -1254,7 +1254,7 @@ void MainWindow::notifyShowNext() {
|
||||||
App::playSound();
|
App::playSound();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_notifyWaiters.isEmpty() || !Global::DesktopNotify() || psSkipDesktopNotify()) {
|
if (_notifyWaiters.isEmpty() || !Global::DesktopNotify() || Platform::Notifications::skipToast()) {
|
||||||
if (nextAlert) {
|
if (nextAlert) {
|
||||||
_notifyWaitTimer.start(nextAlert - ms);
|
_notifyWaitTimer.start(nextAlert - ms);
|
||||||
}
|
}
|
||||||
|
|
|
@ -531,7 +531,7 @@ void OverviewInner::dragActionFinish(const QPoint &screenPos, Qt::MouseButton bu
|
||||||
auto sel = _selected.cbegin().value();
|
auto sel = _selected.cbegin().value();
|
||||||
if (sel != FullSelection && sel.from == sel.to) {
|
if (sel != FullSelection && sel.from == sel.to) {
|
||||||
_selected.clear();
|
_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::wnd()) App::wnd()->setInnerFocus();
|
||||||
|
|
||||||
if (App::app()) App::app()->mtpUnpause();
|
if (App::app()) App::app()->mtpUnpause();
|
||||||
|
|
||||||
|
Ui::showChatsList();
|
||||||
} else {
|
} else {
|
||||||
a_coordUnder.update(dt, st::slideFunction);
|
a_coordUnder.update(dt, st::slideFunction);
|
||||||
a_coordOver.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 Platform {
|
||||||
namespace Notifications {
|
namespace Notifications {
|
||||||
|
|
||||||
|
inline void defaultNotificationShown(QWidget *widget) {
|
||||||
|
}
|
||||||
|
inline bool skipAudio() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
inline bool skipToast() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
class Manager;
|
class Manager;
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
|
@ -32,9 +41,6 @@ Manager *manager();
|
||||||
bool supported();
|
bool supported();
|
||||||
void finish();
|
void finish();
|
||||||
|
|
||||||
inline void defaultNotificationShown(QWidget *widget) {
|
|
||||||
}
|
|
||||||
|
|
||||||
class Manager : public Window::Notifications::NativeManager {
|
class Manager : public Window::Notifications::NativeManager {
|
||||||
public:
|
public:
|
||||||
Manager();
|
Manager();
|
||||||
|
|
|
@ -25,14 +25,20 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
namespace Notifications {
|
namespace Notifications {
|
||||||
|
|
||||||
|
void defaultNotificationShown(QWidget *widget);
|
||||||
|
inline bool skipAudio() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
inline bool skipToast() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
class Manager;
|
class Manager;
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
Manager *manager();
|
Manager *manager();
|
||||||
void finish();
|
void finish();
|
||||||
|
|
||||||
void defaultNotificationShown(QWidget *widget);
|
|
||||||
|
|
||||||
class Manager : public Window::Notifications::NativeManager {
|
class Manager : public Window::Notifications::NativeManager {
|
||||||
public:
|
public:
|
||||||
Manager();
|
Manager();
|
||||||
|
|
|
@ -23,6 +23,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
||||||
|
|
||||||
#include "window/notifications_utilities.h"
|
#include "window/notifications_utilities.h"
|
||||||
#include "platform/win/windows_app_user_model_id.h"
|
#include "platform/win/windows_app_user_model_id.h"
|
||||||
|
#include "platform/win/windows_event_filter.h"
|
||||||
#include "platform/win/windows_dlls.h"
|
#include "platform/win/windows_dlls.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
@ -534,5 +535,87 @@ void Manager::onAfterNotificationActivated(PeerId peerId, MsgId msgId) {
|
||||||
_impl->afterNotificationActivated(peerId, 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 Notifications
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
|
|
@ -25,6 +25,11 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
namespace Notifications {
|
namespace Notifications {
|
||||||
|
|
||||||
|
inline void defaultNotificationShown(QWidget *widget) {
|
||||||
|
}
|
||||||
|
bool skipAudio();
|
||||||
|
bool skipToast();
|
||||||
|
|
||||||
class Manager;
|
class Manager;
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
|
@ -32,9 +37,6 @@ Manager *manager();
|
||||||
bool supported();
|
bool supported();
|
||||||
void finish();
|
void finish();
|
||||||
|
|
||||||
inline void defaultNotificationShown(QWidget *widget) {
|
|
||||||
}
|
|
||||||
|
|
||||||
class Manager : public Window::Notifications::NativeManager {
|
class Manager : public Window::Notifications::NativeManager {
|
||||||
public:
|
public:
|
||||||
Manager();
|
Manager();
|
||||||
|
|
|
@ -294,14 +294,6 @@ uint64 psIdleTime() {
|
||||||
return getms(true) - _lastUserAction;
|
return getms(true) - _lastUserAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool psSkipAudioNotify() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool psSkipDesktopNotify() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void psActivateProcess(uint64 pid) {
|
void psActivateProcess(uint64 pid) {
|
||||||
// objc_activateProgram();
|
// objc_activateProgram();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,9 +39,6 @@ void psUserActionDone();
|
||||||
bool psIdleSupported();
|
bool psIdleSupported();
|
||||||
uint64 psIdleTime();
|
uint64 psIdleTime();
|
||||||
|
|
||||||
bool psSkipAudioNotify();
|
|
||||||
bool psSkipDesktopNotify();
|
|
||||||
|
|
||||||
QStringList psInitLogs();
|
QStringList psInitLogs();
|
||||||
void psClearInitLogs();
|
void psClearInitLogs();
|
||||||
|
|
||||||
|
|
|
@ -302,14 +302,6 @@ uint64 psIdleTime() {
|
||||||
return objc_idleTime(idleTime) ? idleTime : (getms(true) - _lastUserAction);
|
return objc_idleTime(idleTime) ? idleTime : (getms(true) - _lastUserAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool psSkipAudioNotify() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool psSkipDesktopNotify() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList psInitLogs() {
|
QStringList psInitLogs() {
|
||||||
return _initLogs;
|
return _initLogs;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,9 +42,6 @@ void psUserActionDone();
|
||||||
bool psIdleSupported();
|
bool psIdleSupported();
|
||||||
uint64 psIdleTime();
|
uint64 psIdleTime();
|
||||||
|
|
||||||
bool psSkipAudioNotify();
|
|
||||||
bool psSkipDesktopNotify();
|
|
||||||
|
|
||||||
QStringList psInitLogs();
|
QStringList psInitLogs();
|
||||||
void psClearInitLogs();
|
void psClearInitLogs();
|
||||||
|
|
||||||
|
|
|
@ -176,22 +176,6 @@ uint64 psIdleTime() {
|
||||||
return GetLastInputInfo(&lii) ? (GetTickCount() - lii.dwTime) : (getms(true) - _lastUserAction);
|
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() {
|
QStringList psInitLogs() {
|
||||||
return _initLogs;
|
return _initLogs;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,9 +38,6 @@ void psUserActionDone();
|
||||||
bool psIdleSupported();
|
bool psIdleSupported();
|
||||||
uint64 psIdleTime();
|
uint64 psIdleTime();
|
||||||
|
|
||||||
bool psSkipAudioNotify();
|
|
||||||
bool psSkipDesktopNotify();
|
|
||||||
|
|
||||||
QStringList psInitLogs();
|
QStringList psInitLogs();
|
||||||
void psClearInitLogs();
|
void psClearInitLogs();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue