Don't show notification if window is focused

This commit is contained in:
miruka 2020-09-16 11:31:34 -04:00
parent a8a25d09ee
commit dcc3473ecf
3 changed files with 22 additions and 17 deletions

View File

@ -50,7 +50,7 @@ from .models.model_store import ModelStore
from .nio_callbacks import NioCallbacks from .nio_callbacks import NioCallbacks
from .presence import Presence from .presence import Presence
from .pyotherside_events import ( from .pyotherside_events import (
AlertRequested, InvalidAccessToken, LoopException, InvalidAccessToken, LoopException, NotificationRequested,
) )
if TYPE_CHECKING: if TYPE_CHECKING:
@ -2137,8 +2137,6 @@ class MatrixClient(nio.AsyncClient):
room_item.local_unreads = True room_item.local_unreads = True
if unread or highlight: if unread or highlight:
AlertRequested(high_importance=highlight)
members = self.models[self.user_id, room.room_id, "members"] members = self.models[self.user_id, room.room_id, "members"]
room_name = room.display_name room_name = room.display_name
sender = item.sender_name or item.sender_id sender = item.sender_name or item.sender_id
@ -2150,10 +2148,11 @@ class MatrixClient(nio.AsyncClient):
else: else:
body_start = f"{sender}: " body_start = f"{sender}: "
await self.backend.desktop_notify( NotificationRequested(
title = room_name, title = room_name,
body = f"{body_start}{item.inline_content}", body = f"{body_start}{item.inline_content}",
# await self.backend.media_cache.get_thumbnail( high_importance = highlight,
# image = await self.backend.media_cache.get_thumbnail(
# item.sender_avatar, 32, 32, # item.sender_avatar, 32, 32,
# ), # ),
) )

View File

@ -1,7 +1,8 @@
# SPDX-License-Identifier: LGPL-3.0-or-later # SPDX-License-Identifier: LGPL-3.0-or-later
from dataclasses import dataclass, field from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence from pathlib import Path
from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence, Union
import pyotherside import pyotherside
@ -34,14 +35,17 @@ class ExitRequested(PyOtherSideEvent):
@dataclass @dataclass
class AlertRequested(PyOtherSideEvent): class NotificationRequested(PyOtherSideEvent):
"""Request a window manager alert to be shown. """Request a notification and window manager alert to be shown.
Sets the urgency hint for compliant X11/Wayland window managers; Alerts set the urgency hint for compliant X11/Wayland window managers or
flashes the taskbar icon on Windows. flash the program's taskbar icon on Windows.
""" """
high_importance: bool = False title: str = field()
body: str = ""
image: Union[Path, str] = ""
high_importance: bool = False
@dataclass @dataclass

View File

@ -11,15 +11,17 @@ QtObject {
Qt.exit(exitCode) Qt.exit(exitCode)
} }
function onAlertRequested(highImportance) { function onNotificationRequested(title, body, image, highImportance) {
if (Qt.application.state === Qt.ApplicationActive) return
py.callCoro("desktop_notify", [title, body, image])
const msec = const msec =
highImportance ? highImportance ?
window.settings.alertOnMentionForMsec : window.settings.alertOnMentionForMsec :
window.settings.alertOnMessageForMsec window.settings.alertOnMessageForMsec
if (Qt.application.state !== Qt.ApplicationActive && msec !== 0) { if (msec) window.alert(msec === -1 ? 0 : msec) // -1 0 = no time out
window.alert(msec === -1 ? 0 : msec) // -1 0 = no time out
}
} }
function onCoroutineDone(uuid, result, error, traceback) { function onCoroutineDone(uuid, result, error, traceback) {