Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display alert on special events #142

Open
Wynn-Zeng opened this issue Jul 7, 2024 · 1 comment
Open

feat: display alert on special events #142

Wynn-Zeng opened this issue Jul 7, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Wynn-Zeng
Copy link

Summary:

When special events occur (e.g., triggering risk control, encountering errors), it would be beneficial to display a MessageBox or Notification to alert the user. This would improve the user experience by providing immediate feedback and necessary information about the event.

Description:

Special events such as risk control triggers or errors are critical moments that require the user's attention. Displaying a MessageBox or Notification would ensure that the user is promptly informed and can take appropriate action. This feature should be implemented in a cross-platform manner to support users on various operating systems.

Sample Code:

import sys

if sys.platform == "win32":
    import ctypes
    from win10toast import ToastNotifier

    def show_message_box(title, message):
        ctypes.windll.user32.MessageBoxW(0, message, title, 1)

    def show_notification(title, message):
        toaster = ToastNotifier()
        toaster.show_toast(title, message, duration=10)

elif sys.platform == "darwin":
    import subprocess

    def show_message_box(title, message):
        script = f'display dialog "{message}" with title "{title}" buttons {{"OK"}} default button "OK"'
        subprocess.run(["osascript", "-e", script])

    def show_notification(title, message):
        script = f'display notification "{message}" with title "{title}"'
        subprocess.run(["osascript", "-e", script])

else:  # Assume Linux
    from gi.repository import Notify

    def show_message_box(title, message):
        Notify.init("App")
        notification = Notify.Notification.new(title, message)
        notification.show()

    def show_notification(title, message):
        Notify.init("App")
        notification = Notify.Notification.new(title, message)
        notification.show()

# Example usage:
event = "error"  # This can be any special event like "risk_control" or "error" or something else. 

if event == "risk_control":
    #show_message_box("触发风控", "类型:手机号验证,请尽快查看")
    show_notification("触发风控", "类型:手机号验证,请尽快查看")
elif event == "error":
    #show_message_box("出现错误", "发生错误,请尝试重启应用")
    show_notification("出现错误", "发生错误,请尝试重启应用")
#...

Additional Notes:

  • This implementation uses ctypes and win10toast for Windows, osascript for macOS, and gi.repository.Notify for Linux.
  • The MessageBox provides a blocking alert that requires user acknowledgment, while the Notification provides a non-blocking alert.

Benefits:

  • Immediate user feedback on critical events.
  • Enhanced user experience through timely and clear notifications.
@ZianTT ZianTT added the enhancement New feature or request label Jul 7, 2024
@ZianTT
Copy link
Owner

ZianTT commented Jul 7, 2024

Received. It won't appear in next few versions, but if I receive a large number of requests for this feature, I'll consider adding it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants