├── .gitattributes └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Codrut's Windows Runtime for Delphi -> Notification Manager 2 | Notification Manager for advanced notifications in Windows 10/11 3 | 4 | ## Source and Dependencies 5 | This library is part of the [Codrut's Windows Runtime for Delphi](https://github.com/Codrax/Cod-Windows-Runtime), all units can be found there. 6 | 7 | Attention! The app must be registered with a TAppRegistration, for futher detalies, look at the Cod Windows Runtime docs. 8 | 9 | ## Examples 10 | ### Creating the Notification Manager 11 | ``` 12 | Manager := TNotificationManager.Create; 13 | ``` 14 | 15 | ### Creating a notification 16 | ``` 17 | // Create notification 18 | TToastContentBuilder.Create 19 | .AddText( TToastValueBindable.Create('title') ) 20 | .AddText( TToastValueString.Create('This is the new notifications engine :)') ) 21 | .AddAudio(TSoundEventValue.NotificationIM, WinFalse) 22 | .AddHeroImage(TToastValueString.Create('C:\Windows\System32\@facial-recognition-windows-hello.gif')) 23 | .AddProgressBar(TToastValueString.Create('Downloading...'), TToastValueBindable.Create('download-pos')) 24 | .AddInputTextBox('editbox-id', 'Enter value', 'Response') 25 | .AddButton('Cancel', TActivationType.Foreground, 'cancel') 26 | .AddButton('View more', TActivationType.Foreground, 'view') 27 | .SetActivationType(TActivationType.Protocol) 28 | .SetLaunchURI('ms-settings:account') 29 | .CreateNotificationAndFree(Notif); 30 | 31 | // Set tag 32 | Notif.Tag := 'notification1'; 33 | 34 | // Data binded values 35 | Notif.Data := TNotificationData.Create; 36 | Notif.Data['title'] := 'Hello world!'; 37 | Notif.Data['download-pos'] := '0'; 38 | 39 | // Events (must be defined in your form class) 40 | Notif.OnActivated := NotifActivated; 41 | Notif.OnDismissed := NotifDismissed; 42 | ``` 43 | 44 | ### Pushing notification 45 | ``` 46 | Manager.ShowNotification(Notif); 47 | ``` 48 | 49 | 50 | ### Hiding notification 51 | ``` 52 | Manager.HideNotification(Notif); 53 | ``` 54 | 55 | ### Updating notification contents 56 | ``` 57 | const DownloadValue = Notif.Data['download-pos'].ToSingle+0.1; 58 | Notif.Data['download-pos'] := DownloadValue.ToString; 59 | if DownloadValue >= 1 then 60 | Notif.Data['title'] := 'Download finalised!'; 61 | 62 | // Update 63 | Manager.UpdateNotification(Notif); 64 | ``` 65 | 66 | ### Reading event data 67 | ``` 68 | procedure TForm1.NotifActivated(Sender: TNotification; Arguments: string; UserInput: TUserInputMap); 69 | var 70 | Value: string; 71 | begin 72 | // Get button id 73 | if Arguments = 'view' then 74 | // Get value of edit box (if there is one with this id) 75 | Value := UserInput.GetStringValue('editbox-id'); 76 | end; 77 | ``` 78 | 79 | ## Pictures 80 | ![image](https://github.com/user-attachments/assets/d612e2e9-f706-469a-ac4e-85ee5b434c04) 81 | ![anim](https://github.com/Codrax/Cod-Notification-Manager/assets/68193064/33026b0f-b11a-4c27-993e-69f6850db506) 82 | 83 | ## Important notes 84 | - Do not free the `TNotificationManager` until the app will no longer send notification. 85 | - Do not free the notification until It is no longer needed, because you will no longer be able to hide It. The notification can be reset using the `Reset()` 86 | method 87 | --------------------------------------------------------------------------------