|
1 | 1 | import os
|
2 | 2 | import platform
|
3 |
| -import shlex |
4 | 3 | import subprocess
|
5 | 4 | import time
|
6 | 5 | from collections import OrderedDict, defaultdict
|
@@ -591,39 +590,21 @@ def canonicalize_color(color: str) -> str:
|
591 | 590 | def notify(title: str, html_text: str) -> str:
|
592 | 591 | document = lxml.html.document_fromstring(html_text)
|
593 | 592 | text = document.text_content()
|
594 |
| - quoted_text = shlex.quote(text) |
595 |
| - |
596 |
| - quoted_title = shlex.quote(title) |
597 | 593 |
|
598 | 594 | command_list = None
|
599 |
| - if WSL: # NOTE Tested and should work! |
600 |
| - # Escaping of quotes in powershell is done using ` instead of \ |
601 |
| - escaped_text = text.replace('\'', '`\'').replace('\"', '`\"') |
602 |
| - quoted_text = '\"' + escaped_text + '\"' |
| 595 | + if MACOS: |
603 | 596 | command_list = [
|
604 |
| - 'powershell.exe', |
605 |
| - "New-BurntToastNotification -Text {}, {}" |
606 |
| - .format(quoted_title, quoted_text) |
| 597 | + "osascript", |
| 598 | + "-e", "on run(argv)", |
| 599 | + "-e", "return display notification item 1 of argv with title " |
| 600 | + 'item 2 of argv sound name "ZT_NOTIFICATION_SOUND"', |
| 601 | + "-e", "end", |
| 602 | + "--", text, title |
607 | 603 | ]
|
608 |
| - expected_length = 2 |
609 |
| - elif MACOS: # NOTE Tested and should work! |
610 |
| - command_list = shlex.split( |
611 |
| - "osascript -e " |
612 |
| - "'display notification \"\'{}\'\" with title \"\'{}\'\" " |
613 |
| - " sound name \"ZT_NOTIFICATION_SOUND\"'" |
614 |
| - .format(quoted_text, quoted_title) |
615 |
| - ) |
616 |
| - expected_length = 3 |
617 | 604 | elif LINUX:
|
618 |
| - command_list = shlex.split( |
619 |
| - 'notify-send {} {}'.format(quoted_title, quoted_text) |
620 |
| - ) |
621 |
| - expected_length = 3 |
| 605 | + command_list = ["notify-send", "--", title, text] |
622 | 606 |
|
623 | 607 | if command_list is not None:
|
624 |
| - # NOTE: We assert this in tests, but this signals unexpected breakage |
625 |
| - assert len(command_list) == expected_length |
626 |
| - |
627 | 608 | try:
|
628 | 609 | subprocess.run(command_list, stdout=subprocess.DEVNULL,
|
629 | 610 | stderr=subprocess.DEVNULL)
|
|
0 commit comments