Skip to content

Commit

Permalink
Modified window class and alert function to automatically switch betw…
Browse files Browse the repository at this point in the history
…een light or dark mode based on what the user's system is displaying.
  • Loading branch information
cheerlessDreamer committed Jun 8, 2021
1 parent 5a868f4 commit 42ce8db
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions rumps/rumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import AppKit

from Foundation import (NSDate, NSTimer, NSRunLoop, NSDefaultRunLoopMode, NSSearchPathForDirectoriesInDomains,
NSMakeRect, NSLog, NSObject, NSMutableDictionary, NSString)
NSMakeRect, NSLog, NSObject, NSMutableDictionary, NSString, NSUserDefaults)
from AppKit import NSApplication, NSStatusBar, NSMenu, NSMenuItem, NSAlert, NSTextField, NSSecureTextField, NSImage, NSSlider, NSSize, NSWorkspace, NSWorkspaceWillSleepNotification, NSWorkspaceDidWakeNotification
from PyObjCTools import AppHelper

Expand Down Expand Up @@ -75,7 +75,8 @@ def alert(title=None, message='', ok=None, cancel=None, other=None, icon_path=No
cancel = 'Cancel' if cancel else None
alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
title, ok, cancel, other, message)
alert.window().setAppearance_(AppKit.NSAppearance.currentAppearance())
if NSUserDefaults.standardUserDefaults().stringForKey_('AppleInterfaceStyle') == 'Dark':
alert.window().setAppearance_(AppKit.NSAppearance.appearanceNamed_('NSAppearanceNameVibrantDark'))
alert.setAlertStyle_(0) # informational style
if icon_path is not None:
icon = _nsimage_from_file(icon_path)
Expand Down Expand Up @@ -847,7 +848,8 @@ def run(self):
:return: a :class:`rumps.rumps.Response` object that contains the text and the button clicked as an integer.
"""
_log(self)
self._alert.window().setAppearance_(AppKit.NSAppearance.currentAppearance())
if NSUserDefaults.standardUserDefaults().stringForKey_('AppleInterfaceStyle') == 'Dark':
self._alert.window().setAppearance_(AppKit.NSAppearance.appearanceNamed_('NSAppearanceNameVibrantDark'))
clicked = self._alert.runModal() % 999
if clicked > 2 and self._cancel:
clicked -= 1
Expand Down

0 comments on commit 42ce8db

Please sign in to comment.