public override Task RunAsyncInternal(IBackgroundTaskInstance taskInstance)
        {
            if (taskInstance == null)
            {
                return(null);
            }

            _deferral = taskInstance.GetDeferral();

            return(Task.Run(async() =>
            {
                var details = taskInstance.TriggerDetails as ToastNotificationActionTriggerDetail;
                Settings settings = await new UwpMemory().Read <Settings>("settings.json");
                var Todoist = new TodoistService(settings.TodoistKey, settings.TodoistUserAgent);

                if (details != null)
                {
                    string arguments = details.Argument;
                    var userInput = details.UserInput;

                    if (arguments.StartsWith("complete"))
                    {
                        TodoistService todoist = Todoist;
                        await todoist.MarkTodoAsDone(long.Parse(details.Argument.Remove(0, 9)));
                    }

                    if (arguments.StartsWith("remove"))
                    {
                        TodoistService todoist = Todoist;
                        ItemUpdate update = new ItemUpdate(long.Parse(details.Argument.Remove(0, 7)))
                        {
                            Labels = new List <long>()
                        };
                        await todoist.Update(update);
                    }

                    // Perform tasks
                }

                //// TODO WTS: Insert the code that should be executed in the background task here.
                //// This sample initializes a timer that counts to 100 in steps of 10.  It updates Message each time.

                //// Documentation:
                ////      * General: https://docs.microsoft.com/en-us/windows/uwp/launch-resume/support-your-app-with-background-tasks
                ////      * Debug: https://docs.microsoft.com/en-us/windows/uwp/launch-resume/debug-a-background-task
                ////      * Monitoring: https://docs.microsoft.com/windows/uwp/launch-resume/monitor-background-task-progress-and-completion

                //// To show the background progress and message on any page in the application,
                //// subscribe to the Progress and Completed events.
                //// You can do this via "BackgroundTaskService.GetBackgroundTasksRegistration"
                _deferral.Complete();
                _taskInstance = taskInstance;
            }));
        }
Example #2
0
        private async void Grid_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            if (sender is Grid grid && grid.DataContext is Item item)
            {
                Label yesterday = Labels.First(i => i.Name == "yesterday");
                if (item.Labels.Contains(todayLabel.Id))
                {
                    item.Labels.Remove(todayLabel.Id);

                    var col = GetColor(item);
                    col.A           = Convert.ToByte(100);
                    grid.Background = new SolidColorBrush(Colors.Transparent);

                    await Todoist.Update(new ItemUpdate(item.Id)
                    {
                        Labels = item.Labels
                    });
                }
                else
                {
                    item.Labels.Add(todayLabel.Id);

                    if (item.Labels.Contains(yesterday.Id))
                    {
                        item.Labels.Remove(yesterday.Id);
                    }

                    var col = GetColor(item);
                    col.A           = Convert.ToByte(100);
                    grid.Background = new SolidColorBrush(col);

                    await Todoist.Update(new ItemUpdate(item.Id)
                    {
                        Labels = item.Labels
                    });
                }

                await new NotificationHandler().UpdateNotifications(Todoist);
            }
        }