Exemple #1
0
        private async void FlyoutItem_CompleteItem(object sender, RoutedEventArgs e)
        {
            if (sender is MenuFlyoutItem flyout && flyout.DataContext is Item todo)
            {
                await Todoist.MarkTodoAsDone(todo);

                Items = await Todoist.GetItems();

                RedoTodos();
            }
        }
        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;
            }));
        }