<commit_before>﻿using Microsoft.Toolkit.Uwp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Template10.Utils;
using Windows.ApplicationModel.Background;
using Windows.UI.Xaml;

namespace Mazui.Services
{
    public class SettingsService
    {
        public static SettingsService Instance { get; } = new SettingsService();
        Template10.Services.SettingsService.ISettingsHelper _helper;
        private SettingsService()
        {
            _helper = new Template10.Services.SettingsService.SettingsHelper();
        }

        public bool ShowEmbeddedTweets
        {
            get { return _helper.Read<bool>(nameof(ShowEmbeddedTweets), true); }
            set
            {
                _helper.Write(nameof(ShowEmbeddedTweets), value);
            }
        }

        public bool AutoplayGif
        {
            get { return _helper.Read<bool>(nameof(AutoplayGif), true); }
            set
            {
                _helper.Write(nameof(AutoplayGif), value);
            }
        }

        public bool OpenThreadsInNewWindow
        {
            get { return _helper.Read<bool>(nameof(OpenThreadsInNewWindow), false); }
            set
            {
                _helper.Write(nameof(OpenThreadsInNewWindow), value);
            }
        }

        public bool ShowEmbeddedVideo
        {
            get { return _helper.Read<bool>(nameof(ShowEmbeddedVideo), true); }
            set
            {
                _helper.Write(nameof(ShowEmbeddedVideo), value);
            }
        }
        public bool ShowEmbeddedGifv
        {
            get { return _helper.Read<bool>(nameof(ShowEmbeddedVideo), true); }
            set
            {
                _helper.Write(nameof(ShowEmbeddedVideo), value);
            }
        }

        public bool BackgroundEnable
        {
            get { return _helper.Read<bool>(nameof(BackgroundEnable), false); }
            set
            {
                _helper.Write(nameof(BackgroundEnable), value);
                ChangeBookmarkLiveTileBackgroundStatus(value);
            }
        }

        public bool TransparentThreadListBackground
        {
            get { return _helper.Read<bool>(nameof(TransparentThreadListBackground), false); }
            set
            {
                _helper.Write(nameof(TransparentThreadListBackground), value);
            }
        }

        public bool BookmarkBackground
        {
            get { return _helper.Read<bool>(nameof(BookmarkBackground), false); }
            set
            {
                _helper.Write(nameof(BookmarkBackground), value);
                ChangeBookmarkLiveTileBackgroundStatus(value);
            }
        }

        public bool BookmarkNotifications
        {
            get { return _helper.Read<bool>(nameof(BookmarkNotifications), false); }
            set
            {
                _helper.Write(nameof(BookmarkNotifications), value);
                ChangeBookmarkNotifyBackgroundStatus(value);
            }
        }

        public bool ImgurSignedIn
        {
            get { return _helper.Read<bool>(nameof(ImgurSignedIn), false); }
            set
            {
                _helper.Write(nameof(ImgurSignedIn), value);
            }
        }

        public string ImgurUsername
        {
            get { return _helper.Read<string>(nameof(ImgurUsername), string.Empty); }
            set
            {
                _helper.Write(nameof(ImgurUsername), value);
            }
        }

        public DateTime LastRefresh
        {
            get { return _helper.Read<DateTime>(nameof(LastRefresh), DateTime.Now); }
            set
            {
                _helper.Write(nameof(LastRefresh), value);
            }
        }

        public void ChangeBookmarkLiveTileBackgroundStatus(bool value)
        {
            if (value)
            {
                BackgroundTaskRegistration registered = BackgroundTaskHelper.Register("BookmarkBackgroundActivity", new TimeTrigger(15, true));
            }
            else
            {
                BackgroundTaskHelper.Unregister("BookmarkBackgroundActivity");
            }
        }

        public void ChangeBookmarkNotifyBackgroundStatus(bool value)
        {
            if (value)
            {
                BackgroundTaskRegistration registered = BackgroundTaskHelper.Register("BookmarkNotifyBackgroundActivity", new TimeTrigger(15, true));
            }
            else
            {
                BackgroundTaskHelper.Unregister("BookmarkNotifyBackgroundActivity");
            }
        }

        public delegate void ChangedAppTheme();

        public event ChangedAppTheme ChangedAppThemeHandler;

        public ApplicationTheme AppTheme
        {
            get
            {
                var theme = Application.Current.RequestedTheme;
                var value = _helper.Read<string>(nameof(AppTheme), theme.ToString());
                return Enum.TryParse<ApplicationTheme>(value, out theme) ? theme : ApplicationTheme.Dark;
            }
            set
            {
                _helper.Write(nameof(AppTheme), value.ToString());
                (Window.Current.Content as FrameworkElement).RequestedTheme = value.ToElementTheme();
                Views.Shell.HamburgerMenu.RefreshStyles(value, true);<commit_msg>Force Internet to be enabled for background tasks<commit_after>﻿using Microsoft.Toolkit.Uwp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Template10.Utils;
using Windows.ApplicationModel.Background;
using Windows.UI.Xaml;

namespace Mazui.Services
{
    public class SettingsService
    {
        public static SettingsService Instance { get; } = new SettingsService();
        Template10.Services.SettingsService.ISettingsHelper _helper;
        private SettingsService()
        {
            _helper = new Template10.Services.SettingsService.SettingsHelper();
        }

        public bool ShowEmbeddedTweets
        {
            get { return _helper.Read<bool>(nameof(ShowEmbeddedTweets), true); }
            set
            {
                _helper.Write(nameof(ShowEmbeddedTweets), value);
            }
        }

        public bool AutoplayGif
        {
            get { return _helper.Read<bool>(nameof(AutoplayGif), true); }
            set
            {
                _helper.Write(nameof(AutoplayGif), value);
            }
        }

        public bool OpenThreadsInNewWindow
        {
            get { return _helper.Read<bool>(nameof(OpenThreadsInNewWindow), false); }
            set
            {
                _helper.Write(nameof(OpenThreadsInNewWindow), value);
            }
        }

        public bool ShowEmbeddedVideo
        {
            get { return _helper.Read<bool>(nameof(ShowEmbeddedVideo), true); }
            set
            {
                _helper.Write(nameof(ShowEmbeddedVideo), value);
            }
        }
        public bool ShowEmbeddedGifv
        {
            get { return _helper.Read<bool>(nameof(ShowEmbeddedVideo), true); }
            set
            {
                _helper.Write(nameof(ShowEmbeddedVideo), value);
            }
        }

        public bool BackgroundEnable
        {
            get { return _helper.Read<bool>(nameof(BackgroundEnable), false); }
            set
            {
                _helper.Write(nameof(BackgroundEnable), value);
                ChangeBookmarkLiveTileBackgroundStatus(value);
            }
        }

        public bool TransparentThreadListBackground
        {
            get { return _helper.Read<bool>(nameof(TransparentThreadListBackground), false); }
            set
            {
                _helper.Write(nameof(TransparentThreadListBackground), value);
            }
        }

        public bool BookmarkBackground
        {
            get { return _helper.Read<bool>(nameof(BookmarkBackground), false); }
            set
            {
                _helper.Write(nameof(BookmarkBackground), value);
                ChangeBookmarkLiveTileBackgroundStatus(value);
            }
        }

        public bool BookmarkNotifications
        {
            get { return _helper.Read<bool>(nameof(BookmarkNotifications), false); }
            set
            {
                _helper.Write(nameof(BookmarkNotifications), value);
                ChangeBookmarkNotifyBackgroundStatus(value);
            }
        }

        public bool ImgurSignedIn
        {
            get { return _helper.Read<bool>(nameof(ImgurSignedIn), false); }
            set
            {
                _helper.Write(nameof(ImgurSignedIn), value);
            }
        }

        public string ImgurUsername
        {
            get { return _helper.Read<string>(nameof(ImgurUsername), string.Empty); }
            set
            {
                _helper.Write(nameof(ImgurUsername), value);
            }
        }

        public DateTime LastRefresh
        {
            get { return _helper.Read<DateTime>(nameof(LastRefresh), DateTime.Now); }
            set
            {
                _helper.Write(nameof(LastRefresh), value);
            }
        }

        public void ChangeBookmarkLiveTileBackgroundStatus(bool value)
        {
            if (value)
            {
                BackgroundTaskRegistration registered = BackgroundTaskHelper.Register("BookmarkBackgroundActivity", new TimeTrigger(15, true), false, true, new SystemCondition(SystemConditionType.InternetAvailable));
            }
            else
            {
                BackgroundTaskHelper.Unregister("BookmarkBackgroundActivity");
            }
        }

        public void ChangeBookmarkNotifyBackgroundStatus(bool value)
        {
            if (value)
            {
                BackgroundTaskRegistration registered = BackgroundTaskHelper.Register("BookmarkNotifyBackgroundActivity", new TimeTrigger(15, true), false, true, new SystemCondition(SystemConditionType.InternetAvailable));
            }
            else
            {
                BackgroundTaskHelper.Unregister("BookmarkNotifyBackgroundActivity");
            }
        }

        public delegate void ChangedAppTheme();

        public event ChangedAppTheme ChangedAppThemeHandler;

        public ApplicationTheme AppTheme
        {
            get
            {
                var theme = Application.Current.RequestedTheme;
                var value = _helper.Read<string>(nameof(AppTheme), theme.ToString());
                return Enum.TryParse<ApplicationTheme>(value, out theme) ? theme : ApplicationTheme.Dark;
            }
            set
            {
                _helper.Write(nameof(AppTheme), value.ToString());
                (Window.Current.Content as FrameworkElement).RequestedTheme = value.ToElementTheme();
                Views.Shell.HamburgerMenu.RefreshStyles(value, true);
{'fraction_non_alphanumeric': 0.08182648401826484, 'fraction_numerical': 0.0018264840182648401, 'mean_word_length': 1.7066238260009887, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6324757', 'n_tokens_mistral': 2728, 'n_tokens_neox': 2617, 'n_words': 458}