simple notifications

This commit is contained in:
2020-04-24 17:10:48 +03:00
parent a5fafb4e6e
commit 53b5fef2dc
2 changed files with 46 additions and 2 deletions

View File

@@ -17,6 +17,8 @@ using Windows.UI.Xaml.Navigation;
using Windows.Storage; using Windows.Storage;
using Windows.System.Threading; using Windows.System.Threading;
using Windows.UI.Core; using Windows.UI.Core;
using Microsoft.Toolkit.Uwp.Notifications;
using Windows.UI.Notifications;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
@@ -136,6 +138,7 @@ namespace PomoTime
default: default:
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
} }
SendToast();
} }
else else
{ {
@@ -148,6 +151,48 @@ namespace PomoTime
} }
} }
void SendToast()
{
string header;
switch (runningState.CurrentPeriod)
{
case Period.LongBreak:
header = "Long break time!";
break;
case Period.ShortBreak:
header = "Short break time!";
break;
case Period.Work:
header = "Work time!";
break;
default:
throw new ArgumentOutOfRangeException();
}
ToastVisual visual = new ToastVisual()
{
BindingGeneric = new ToastBindingGeneric()
{
Children =
{
new AdaptiveText()
{
Text = header
},
},
}
};
ToastContent toastContent = new ToastContent()
{
Visual = visual,
};
var toast = new ToastNotification(toastContent.GetXml());
toast.ExpirationTime = DateTime.Now.AddMinutes(runningState.MinutesLeft);
ToastNotificationManager.CreateToastNotifier().Show(toast);
}
private void PlayButton_Click(object sender, RoutedEventArgs e) private void PlayButton_Click(object sender, RoutedEventArgs e)
{ {

View File

@@ -32,8 +32,7 @@ namespace PomoTime
output = "Work"; output = "Work";
break; break;
default: default:
output = "Something wrong"; throw new ArgumentOutOfRangeException();
break;
} }
// Return the month value to pass to the target. // Return the month value to pass to the target.