emoacht / desktoptoast Goto Github PK
View Code? Open in Web Editor NEWA library for toast notifications from desktop app
License: MIT License
A library for toast notifications from desktop app
License: MIT License
https://docs.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/toast-progress-bar?tabs=xml
`using Windows.UI.Notifications;
public void UpdateProgress()
{
// Construct a NotificationData object;
string tag = "weekly-playlist";
string group = "downloads";
// Create NotificationData and make sure the sequence number is incremented
// since last update, or assign 0 for updating regardless of order
var data = new NotificationData
{
SequenceNumber = 2
};
// Assign new values
// Note that you only need to assign values that changed. In this example
// we don't assign progressStatus since we don't need to change it
data.Values["progressValue"] = "0.7";
data.Values["progressValueString"] = "18/26 songs";
// Update the existing notification's data by using tag/group
ToastNotificationManager.CreateToastNotifier().Update(data, tag, group);
}`
I want to add a progress bar and update the percent value realtime.
Contents of "CrashAlert.xml" :-
<toast>
<visual>
<binding template="ToastGeneric">
<image placement="appLogoOverride" src="./warn.ico"/>
<text>Potential Crash Warning</text>
<text>It is Recomended to Save any Unsaved Progress within 30 Seconds.</text>
</binding>
</visual>
<audio src="ms-winsoundevent:Notification.Reminder"/>
</toast>
C# Code (modified DesktopToast.Proxy) :-
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;
namespace DesktopToast.Proxy
{
class Program
{
static void Main(string[] args)
{
if (!args.Any())
{
Console.WriteLine(" Usage :-");
Console.WriteLine(" notify.exe [AppName] [xml-file-path]");
return;
}
string xml_path = @args[1];
if (!File.Exists(xml_path))
{
Console.WriteLine("XML File Not Found !");
return;
}
string readText = XDocument.Load(xml_path).ToString();
var request = new ToastRequest
{
ToastXml = readText,
ToastTitle = "DesktopToast WPF Sample",
ToastBody = "This is a toast test.",
ShortcutFileName = args[0] + ".lnk",
ShortcutTargetFilePath = Assembly.GetExecutingAssembly().Location,
AppId = args[0],
};
ToastManager.ShowAsync(request).Wait();
}
}
}
Does this library even support Windows 10 xml toasts ? or do i need windows 8 style xml ?
EDIT : Solved it by using absolute paths, but how can i use absolute paths in xml ?
and how to change the timeout ?
I noticed you are using WMI to query the Windows version, if you don't mind me asking.. why? Does this have an advantage over using the Environment.OSVersion.Version?
I am asking, as I always want to learn better ways. I know, as the developer of Greenshot, that Windows sometimes works in mysterious ways and the most obvious way is not the best.
I currently use Environment.OSVersion.Version, as in the code (which is for the next Greenshot) here: https://github.com/dapplo/Dapplo.Windows/blob/master/src/Dapplo.Windows.Common/WindowsVersion.cs
P.S.
I do know that without having an app.manifest telling Windows that you are "version" aware, you wouldn't get to know it's Windows 10 you are running on.
If I understand it correctly, the application which wants to show toasts only needs to install the shortcut once. So to prevent running code which is only needed once, at every time the application wants to show a toast, I would suggest splitting the logic into multiple steps (and classes).
This also would improve the readability of the code.
Steps to reproduce:
The app isn't activated(by tapping or clicking the toast) when the process is running as administrator.
I tried to use DesktopToast in CHDK Utility to notify the user when the card is ejected. However, when I tried to post the zipped binaries on the forum, I noticed that there was a size limit of 1500 KB. Windows.winmd alone occupies 2.07 MB (uncompressed), so I had to remove it.
Would it be possible to use DesktopToast without Windows.winmd bundled or at least with a slimmer version that would only contain the relevant API?
Thanks!
I'm getting the following exception on Windows 7:
System.TypeLoadException: Could not find Windows Runtime type 'Windows.Data.Xml.Dom.XmlDocument'. ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
--- End of inner exception stack trace ---
at DesktopToast.ToastManager.<ShowAsync>d__0.MoveNext()
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
at DesktopToast.ToastManager.ShowAsync(ToastRequest request)
Hi, i don't understand why the executable icon is no longer shown in the windows 10 notification center.
I set the icon in the executable properties but it is not shown on the notification group.
Thanks for support.
If I want to display a toast, I must to create a shortcut?
If my program is started in response to a Toast being clicked it will be forcibly terminated after a minute or so.
I raised this on Stack Overflow here, and the answer is that CoAddRefServerProcess
should be called to notify the COM manager that the server is in use.
This library should do the call itself, as it handles the rest of the COM part.
I see no way to clear history of the toast notifications. If they user does not activate the toast then it just lingers in the notification area. In most cases that would be best but in the case of my application which logs people out after a certain amount of time and a toast alerts them this is happening then they log back in and that notification is still there.
ToastNotificationManager.History.Clear();
is what I have read up on but not working. Sorry, this is above my head.
Notifications are not sticky and if user does not act it Should go to Action Center not TimedOut
The project cannot be compiled with the following error: (VS2015)
Cannot apply indexing with [] to an expression of type 'XmlNodeList'.
CS1660 Cannot convert lambda expression to type 'TypedEventHandler<ToastNotification, object>' because it is not a delegate type.
CS1545 Property, indexer, or event 'ToastNotification.Dismissed' is not supported by the language; try directly calling accessor methods 'ToastNotification.add_Dismissed(TypedEventHandler<ToastNotification, ToastDismissedEventArgs>)' or 'ToastNotification.remove_Dismissed(EventRegistrationToken)'
and so on.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.