macOS: re-add deprecated notification API

The new User Notifications Framework is only available on macOS 10.14 and above, while the old NSUserNotification API is deprecated in macOS 11 (Big Sur) and will probably be removed in the future.
This commit compiles a simple test program to see if the Framework is available and then uses either the new or the old API.
This commit is contained in:
Luflosi
2020-09-28 01:33:40 +02:00
parent a5918b50f8
commit 0ae1f9906f
2 changed files with 77 additions and 10 deletions

View File

@@ -213,7 +213,8 @@ def get_sanitize_args(cc: str, ccver: Tuple[int, int]) -> List[str]:
def test_compile(cc: str, *cflags: str, src: Optional[str] = None) -> bool:
src = src or 'int main(void) { return 0; }'
p = subprocess.Popen([cc] + list(cflags) + ['-x', 'c', '-o', os.devnull, '-'], stdin=subprocess.PIPE)
p = subprocess.Popen([cc] + list(cflags) + ['-x', 'c', '-o', os.devnull, '-'],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=subprocess.PIPE)
stdin = p.stdin
assert stdin is not None
try:
@@ -336,8 +337,12 @@ def kitty_env() -> Env:
if is_macos:
platform_libs = [
'-framework', 'CoreText', '-framework', 'CoreGraphics',
'-framework', 'UserNotifications'
]
user_notifications_framework = first_successful_compile(ans.cc, '-framework UserNotifications')
if user_notifications_framework != '':
platform_libs.extend(shlex.split(user_notifications_framework))
else:
cppflags.append('-DKITTY_USE_DEPRECATED_MACOS_NOTIFICATION_API')
# Apple deprecated OpenGL in Mojave (10.14) silence the endless
# warnings about it
cppflags.append('-DGL_SILENCE_DEPRECATION')