ZianTT / BHYG

B站 会员购 抢票 脚本
601 stars 106 forks source link

feat: display alert on special events #142

Open Wynn-Zeng opened 1 month ago

Wynn-Zeng commented 1 month ago

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:

Benefits:

ZianTT commented 1 month ago

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.