Merge pull request #5 from usaatyuk/notifications

simple notifications
This commit is contained in:
2020-04-24 17:11:17 +03:00
committed by GitHub
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.System.Threading;
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
@@ -136,6 +138,7 @@ namespace PomoTime
default:
throw new ArgumentOutOfRangeException();
}
SendToast();
}
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)
{

View File

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