ysfchn / toasted

Rich toast notifications library for Windows 10/11 for Python, supports all elements provided by Windows.
MIT License
16 stars 0 forks source link

App icon not showing in toaster? #5

Closed ItsCubeTime closed 2 days ago

ItsCubeTime commented 2 weeks ago

Following snippet:

import toasted, pathlib, contextlib, threading, asyncio
class data:
    appID="foobarSystems.foobarApp"
    appName="Foo Bar App"
    appIcon=str(pathlib.Path(__file__).absolute().parent/'icon.ico').replace('\\','/')
APP_ID = None

def getAppId():
    global APP_ID
    if APP_ID:
        return APP_ID
    APP_ID=registerApp()
    return APP_ID

def registerApp():
    with contextlib.suppress(Exception):
        toasted.Toast.unregister_app_id(data.appID)
    toasted.Toast.register_app_id(
        handle = data.appID,
        display_name = data.appName,
        icon_uri = data.appIcon
    )
    global APP_ID
    return data.appID

def sendToasterNotification(title:str="", message: str=""):
    toast = toasted.Toast(
        app_id = getAppId()
    )
    toast.elements = [
        toasted.Text(title),
        toasted.Text(message)
    ]
    threading.Thread(target=lambda: asyncio.run(toast.show())).start()
print(f"""\
data.appID:   {data.appID}
data.appName: {data.appName}
data.appIcon: {data.appIcon}""")
sendToasterNotification("Hello", "there")

With the following file next to above script (github wouldnt let me attach an .ico, so you will need to extract the .zip): icon.zip

Results in the following toaster: image

And the following text printed in terminal:

python -u "c:\Users\olliv\Desktop\TimeGuardian\TimeGuardian\veryToasty.py"
data.appID:   foobarSystems.foobarApp
data.appName: Foo Bar App
data.appIcon: c:/Users/olliv/Desktop/TimeGuardian/TimeGuardian/icon.ico

❓ Shouldnt the icon appear in the top left of the toaster?

ItsCubeTime commented 2 weeks ago

Or is something wrong with my ico file (would appreciate if someone could test this with an icon they know is perfectly valid because Im not 100% certain mine is!)?

ItsCubeTime commented 2 weeks ago

@c0ffincolors Hi, I believe your account may have become compromised. I would recommend changing your password as quickly as possible!

In case the message gets edited out: image

ysfchn commented 2 weeks ago

Does it still happen after you restart your computer after registering the app ID?

I also removed that comment, thanks.

ItsCubeTime commented 2 weeks ago

I havent restarted my device since first testing it out, no.

I will try later 👍

ItsCubeTime commented 2 days ago

Does it still happen after you restart your computer after registering the app ID?

I also removed that comment, thanks.

Yeah the icon shows fine after restarting! I guess this is a limitation with Windows as opposed to the library then?

ysfchn commented 9 hours ago

Yeah the icon shows fine after restarting! I guess this is a limitation with Windows as opposed to the library then?

I guess so, but there is a issue #4 for suggesting to create keys as volatile on Windows Registry, so maybe this can resolve some potential problems.