Skip to content

Commit

Permalink
Basic implementation of local macOS notifications Pythagora-io#1095
Browse files Browse the repository at this point in the history
  • Loading branch information
dmatora committed Sep 22, 2024
1 parent dcdb1b6 commit 22e753b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions core/ui/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

log = get_logger(__name__)

try:
from rubicon.objc import ObjCClass
NSUserNotification = ObjCClass("NSUserNotification")
NSUserNotificationCenter = ObjCClass("NSUserNotificationCenter")
NOTIFICATIONS_AVAILABLE = True
except ImportError:
log.warning("rubicon.objc not found, macOS notifications disabled")
NOTIFICATIONS_AVAILABLE = False


class PlainConsoleUI(UIBase):
"""
Expand Down Expand Up @@ -53,6 +62,13 @@ async def send_feature_finished(
):
pass

async def send_notification(self, title: str, message: str):
if NOTIFICATIONS_AVAILABLE:
notification = NSUserNotification.alloc().init()
notification.title = title
notification.informativeText = message
NSUserNotificationCenter.defaultUserNotificationCenter.deliverNotification_(notification)

async def ask_question(
self,
question: str,
Expand All @@ -65,6 +81,9 @@ async def ask_question(
initial_text: Optional[str] = None,
source: Optional[UISource] = None,
) -> UserInput:
# Send notification
await self.send_notification("GPT Pilot Input Required", question)

if source:
print(f"[{source}] {question}")
else:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ tqdm==4.66.4
typing-extensions==4.12.1
urllib3==2.2.1
wcwidth==0.2.13
rubicon-objc=0.4.9

0 comments on commit 22e753b

Please sign in to comment.