Example #1
0
        public App()
        {
            this.InitializeComponent();
            bool isDisableScale = AppTool.GetBoolSetting(Settings.DisableXboxScale);

            if (SystemInformation.DeviceFamily == "Windows.Xbox" && isDisableScale)
            {
                Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().SetDesiredBoundsMode(Windows.UI.ViewManagement.ApplicationViewBoundsMode.UseCoreWindow);
                Windows.UI.ViewManagement.ApplicationViewScaling.TrySetDisableLayoutScaling(true);
            }
            CustomXamlResourceLoader.Current = new CustomResourceLoader();
            this.Suspending    += OnSuspending;
            UnhandledException += OnUnhandleException;
            EnteredBackground  += App_EnteredBackground;
            LeavingBackground  += App_LeavingBackground;
            App.AppViewModel    = new AppViewModel();
            App.BiliViewModel   = new BiliViewModel();
            bool isThemeWithSystem = AppTool.GetBoolSetting(Settings.IsThemeWithSystem);

            _isTabletMode = AppTool.GetLocalSetting(Settings.DisplayMode, "") == "Tablet";
            if (!isThemeWithSystem)
            {
                string theme = AppTool.GetLocalSetting(Settings.Theme, "Light");
                RequestedTheme = theme == "Light" ? ApplicationTheme.Light : ApplicationTheme.Dark;
            }
        }
Example #2
0
        private async Task LoadDynamic()
        {
            if (!App.BiliViewModel.IsLogin)
            {
                DynamicCollection.Clear();
                DynamicHolderText.Visibility = Visibility.Visible;
            }
            if (!_isDynamicRequesting)
            {
                _isDynamicRequesting = true;
                Tuple <string, List <Topic> > data = null;
                if (string.IsNullOrEmpty(offset))
                {
                    string lastSeemId = AppTool.GetLocalSetting(BiliBili_Lib.Enums.Settings.LastSeemDynamicId, "0");
                    var    temp       = await _topicService.GetNewDynamicAsync(lastSeemId);

                    if (temp != null)
                    {
                        data = new Tuple <string, List <Topic> >(temp.history_offset, temp.cards);
                    }
                }
                else
                {
                    data = await _topicService.GetHistoryDynamicAsync(offset);
                }
                if (data != null)
                {
                    offset = data.Item1;
                    data.Item2.ForEach(p => TotalList.Add(p));
                    DynamicCollectionInit();
                }
                DynamicHolderText.Visibility = DynamicCollection.Count == 0 ? Visibility.Visible : Visibility.Collapsed;
                _isDynamicRequesting         = false;
            }
        }
Example #3
0
        private async void GetFollowerUnread()
        {
            if (App.BiliViewModel.IsLogin)
            {
                var count = await App.BiliViewModel._client.GetFollowerUnreadCountAsync();

                if (count > 0)
                {
                    //刷新动态
                    if (_isDynamicRequesting)
                    {
                        return;
                    }
                    _isDynamicRequesting = true;
                    string lastSeemId = AppTool.GetLocalSetting(BiliBili_Lib.Enums.Settings.LastSeemDynamicId, "0");
                    var    data       = await _topicService.GetNewDynamicAsync(lastSeemId);

                    if (data != null)
                    {
                        for (int i = data.cards.Count - 1; i >= 0; i--)
                        {
                            if (!TotalList.Contains(data.cards[i]))
                            {
                                TotalList.Insert(0, data.cards[i]);
                            }
                        }
                        DynamicCollectionInit();
                    }
                    _isDynamicRequesting = false;
                }
            }
        }
Example #4
0
        private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            var    width      = e.NewSize.Width;
            double OpenWidth  = 400 + ((App.AppViewModel.BasicFontSize - 14) * App.AppViewModel.BasicFontSize);
            double breakpoint = Convert.ToDouble(AppTool.GetLocalSetting(Settings.PagePanelDisplayBreakpoint, "1500"));

            PageSplitView.DisplayMode    = width < breakpoint ? SplitViewDisplayMode.CompactOverlay : SplitViewDisplayMode.CompactInline;
            PageSplitView.OpenPaneLength = width < OpenWidth + 200 ? width : OpenWidth;
        }
Example #5
0
        public void ClientInit()
        {
            _webClient = new BiliWebClient();
            _secure    = new BiliSecure();
            string _access  = AppTool.GetLocalSetting(Settings.AccessToken, "");
            string _refresh = AppTool.GetLocalSetting(Settings.RefreshToken, "");
            int    _expiry  = Convert.ToInt32(AppTool.GetLocalSetting(Settings.TokenExpiry, "0"));

            _client = new BiliBiliClient(_access, _refresh, _expiry);
            _client.Account.TokenChanged += TokenChanged;
        }
        /// <summary>
        /// 初始化标题栏
        /// </summary>
        public static void SetTitleBarColor()
        {
            var view = ApplicationView.GetForCurrentView();

            CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
            var Theme = AppTool.GetLocalSetting(Settings.Theme, "Light");

            if (Theme == "Dark")
            {
                // active
                view.TitleBar.BackgroundColor = Colors.Transparent;
                view.TitleBar.ForegroundColor = Colors.White;

                // inactive
                view.TitleBar.InactiveBackgroundColor = Colors.Transparent;
                view.TitleBar.InactiveForegroundColor = Colors.Gray;
                // button
                view.TitleBar.ButtonBackgroundColor = Colors.Transparent;
                view.TitleBar.ButtonForegroundColor = Colors.White;

                view.TitleBar.ButtonHoverBackgroundColor = Windows.UI.Color.FromArgb(255, 33, 42, 67);
                view.TitleBar.ButtonHoverForegroundColor = Colors.White;

                view.TitleBar.ButtonPressedBackgroundColor = Windows.UI.Color.FromArgb(255, 255, 86, 86);
                view.TitleBar.ButtonPressedForegroundColor = Colors.White;

                view.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
                view.TitleBar.ButtonInactiveForegroundColor = Colors.Gray;
            }
            else
            {
                // active
                view.TitleBar.BackgroundColor = Colors.Transparent;
                view.TitleBar.ForegroundColor = Colors.Black;

                // inactive
                view.TitleBar.InactiveBackgroundColor = Colors.Transparent;
                view.TitleBar.InactiveForegroundColor = Colors.Gray;
                // button
                view.TitleBar.ButtonBackgroundColor = Colors.Transparent;
                view.TitleBar.ButtonForegroundColor = Colors.DarkGray;

                view.TitleBar.ButtonHoverBackgroundColor = Windows.UI.Color.FromArgb(255, 63, 63, 63);
                view.TitleBar.ButtonHoverForegroundColor = Colors.DarkGray;

                view.TitleBar.ButtonPressedBackgroundColor = Windows.UI.Color.FromArgb(255, 63, 63, 63);
                view.TitleBar.ButtonPressedForegroundColor = Colors.DarkGray;

                view.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
                view.TitleBar.ButtonInactiveForegroundColor = Colors.Gray;
            }
        }
Example #7
0
 private void FontInit()
 {
     FontComboBox.IsEnabled = false;
     if (FontCollection != null && FontCollection.Count > 0)
     {
         string fontName = AppTool.GetLocalSetting(Settings.FontFamily, "微软雅黑");
         var    font     = FontCollection.Where(p => p.Name == fontName).FirstOrDefault();
         if (font != null)
         {
             FontComboBox.SelectedItem = font;
         }
     }
     FontComboBox.IsEnabled = true;
 }
Example #8
0
        private async void FontComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!_isInit)
            {
                return;
            }
            var    item    = FontComboBox.SelectedItem as SystemFont;
            string oldFont = AppTool.GetLocalSetting(Settings.FontFamily, "微软雅黑");

            if (item.Name != oldFont)
            {
                AppTool.WriteLocalSetting(Settings.FontFamily, item.Name);
                await ShowRestartDialog();
            }
        }
Example #9
0
        private async void ThemeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!_isInit)
            {
                return;
            }
            var    item     = (ThemeComboBox.SelectedItem as ComboBoxItem).Tag.ToString();
            string oldTheme = AppTool.GetLocalSetting(Settings.Theme, "Light");

            if (oldTheme != item)
            {
                AppTool.WriteLocalSetting(Settings.Theme, item);
                await ShowRestartDialog();
            }
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var    def      = taskInstance.GetDeferral();
            string _access  = AppTool.GetLocalSetting(Settings.AccessToken, "");
            string _refresh = AppTool.GetLocalSetting(Settings.RefreshToken, "");
            int    _expiry  = Convert.ToInt32(AppTool.GetLocalSetting(Settings.TokenExpiry, "0"));

            if (!string.IsNullOrEmpty(_access))
            {
                var    _client    = new BiliBiliClient(_access, _refresh, _expiry);
                string lastId     = AppTool.GetLocalSetting(Settings.LastSeemDynamicId, "0");
                var    newDynamic = await _client.Topic.GetNewDynamicAsync(lastId.ToString());

                if (newDynamic.update_num > 0)
                {
                    var toastItems = new List <NotificationModel>();
                    var lastItem   = newDynamic.cards.Where(p => p.desc.dynamic_id_str == lastId.ToString()).FirstOrDefault();
                    int lastStamp  = 0;
                    if (lastItem != null)
                    {
                        lastStamp = lastItem.desc.timestamp;
                    }
                    foreach (var item in newDynamic.cards)
                    {
                        if (item.desc.timestamp > lastStamp && (item.desc.type == 8 || item.desc.type == 512))
                        {
                            if (item.desc.type == 8)
                            {
                                var video = JsonConvert.DeserializeObject <VideoDynamic>(item.card);
                                toastItems.Add(new NotificationModel(video.title, video.desc, video.pic, $"action=video&aid={video.aid}", video.owner.face));
                            }
                            else
                            {
                                var anime = JsonConvert.DeserializeObject <AnimeDynamic>(item.card);
                                toastItems.Add(new NotificationModel(anime.show_title, anime.season.type_name, anime.cover, $"action=bangumi&epid={anime.episode_id}"));
                            }
                        }
                    }
                    if (toastItems.Count > 0)
                    {
                        NotificationTool.SendDynamicToast(toastItems);
                    }
                }
            }
            def.Complete();
        }
        /// <summary>
        /// 包装HTML页面
        /// </summary>
        /// <param name="content">文章主题</param>
        /// <returns></returns>
        private async Task <string> PackageHTML(string content)
        {
            content = content.Replace("=\"//", "=\"http://");
            content = content.Replace("data-src", "src");
            string html = await FileIO.ReadTextAsync(await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Components/HTML/ShowPage.html")));

            string theme = Application.Current.RequestedTheme.ToString();
            string css   = await FileIO.ReadTextAsync(await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Components/HTML/{theme}.css")));

            string fontFamily = AppTool.GetLocalSetting(Settings.FontFamily, "微软雅黑");
            string fontSize   = AppTool.GetLocalSetting(Settings.BasicFontSize, "14");

            css = css.Replace("$FontFamily$", fontFamily).Replace("$FontSize$", fontSize);
            string result = html.Replace("$theme$", theme.ToLower()).Replace("$style$", css).Replace("$body$", content);

            result = result.Replace("$noscroll$", "style=\"-ms-overflow-style: none;\"");
            result = result.Replace("$return$", "");
            return(result);
        }
Example #12
0
        public async void CheckAppUpdate()
        {
            string localVersion = AppTool.GetLocalSetting(Settings.LocalVersion, "");
            string nowVersion   = string.Format("{0}.{1}.{2}.{3}", Package.Current.Id.Version.Major, Package.Current.Id.Version.Minor, Package.Current.Id.Version.Build, Package.Current.Id.Version.Revision);

            if (localVersion != nowVersion)
            {
                var updateFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Others/Update.txt"));

                string updateInfo = await FileIO.ReadTextAsync(updateFile);

                if (_updatePopup == null)
                {
                    _updatePopup = new UpdatePopup(updateInfo);
                }
                _updatePopup.ShowPopup();
                AppTool.WriteLocalSetting(Settings.LocalVersion, nowVersion);
            }
        }
Example #13
0
        public App()
        {
            this.InitializeComponent();

            CustomXamlResourceLoader.Current = new CustomResourceLoader();
            this.Suspending    += OnSuspending;
            UnhandledException += OnUnhandleException;
            EnteredBackground  += App_EnteredBackground;
            LeavingBackground  += App_LeavingBackground;
            App.AppViewModel    = new AppViewModel();
            App.BiliViewModel   = new BiliViewModel();
            bool isThemeWithSystem = AppTool.GetBoolSetting(Settings.IsThemeWithSystem);

            _isTabletMode = AppTool.GetLocalSetting(Settings.DisplayMode, "") == "Tablet";
            if (!isThemeWithSystem)
            {
                string theme = AppTool.GetLocalSetting(Settings.Theme, "Light");
                RequestedTheme = theme == "Light" ? ApplicationTheme.Light : ApplicationTheme.Dark;
            }
        }
 protected override object GetResource(string resourceId, string objectType, string propertyName, string propertyType)
 {
     if (resourceId == "Basic")
     {
         return(new FontFamily(AppTool.GetLocalSetting(Settings.FontFamily, "微软雅黑")));
     }
     else if (resourceId.Contains("Font"))
     {
         double NormalSize = Convert.ToDouble(AppTool.GetLocalSetting(Settings.BasicFontSize, "14"));
         if (resourceId == "BasicFontSize")
         {
             return(NormalSize);
         }
         else if (resourceId == "SmallFontSize")
         {
             return(NormalSize * 0.85);
         }
         else if (resourceId == "MiniFontSize")
         {
             return(NormalSize * 0.7);
         }
         else if (resourceId == "BodyFontSize")
         {
             return(NormalSize * 1.1);
         }
         else if (resourceId == "SubFontSize")
         {
             return(NormalSize * 1.5);
         }
         else if (resourceId == "HeaderFontSize")
         {
             return(NormalSize * 2);
         }
         else if (resourceId == "LargeFontSize")
         {
             return(NormalSize * 2.5);
         }
     }
     return(null);
 }
Example #15
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (_isInit || e.NavigationMode == NavigationMode.Back)
            {
                return;
            }

            #region 基础设置
            bool isThemeWithSystem = AppTool.GetBoolSetting(Settings.IsThemeWithSystem);
            ThemeWithSystemSwitch.IsOn = isThemeWithSystem;
            ThemeComboBox.Visibility   = isThemeWithSystem ? Visibility.Collapsed : Visibility.Visible;
            string theme = AppTool.GetLocalSetting(Settings.Theme, "Light");
            ThemeComboBox.SelectedIndex = theme == "Light" ? 0 : 1;
            string displayMode = AppTool.GetLocalSetting(Settings.DisplayMode, "Desktop");
            switch (displayMode)
            {
            case "Desktop":
                DisplayModeComboBox.SelectedIndex = 0;
                break;

            case "Tablet":
                DisplayModeComboBox.SelectedIndex = 1;
                break;

            default:
                break;
            }
            double pageBreakpoint = Convert.ToDouble(AppTool.GetLocalSetting(Settings.PagePanelDisplayBreakpoint, "1500"));
            PagePaneDisplayBreakpointBox.Value = pageBreakpoint;
            bool isEnableAnimation = AppTool.GetBoolSetting(Settings.EnableAnimation);
            EnableAnimationSwitch.IsOn = isEnableAnimation;
            StartupTask startupTask = await StartupTask.GetAsync("RichasyBiliBili");

            bool isEnableStartup = startupTask.State.ToString().Contains("Enable");
            EnableStartupSwitch.IsOn = isEnableStartup;
            double fontSize = Convert.ToDouble(AppTool.GetLocalSetting(Settings.BasicFontSize, "14"));
            FontSizeBox.Value = fontSize;
            DisableScaleInXboxSwitch.IsEnabled = SystemInformation.DeviceFamily == "Windows.Xbox";
            bool disableScale = AppTool.GetBoolSetting(Settings.DisableXboxScale);
            DisableScaleInXboxSwitch.IsOn = disableScale;
            #endregion

            #region 播放器设置
            bool isAutoPlay = AppTool.GetBoolSetting(Settings.IsAutoPlay);
            AutoPlaySwitch.IsOn = isAutoPlay;
            bool isAutoNextPart = AppTool.GetBoolSetting(Settings.IsAutoNextPart, false);
            AutoNextPartSwitch.IsOn = isAutoNextPart;
            bool isManualMTC = AppTool.GetBoolSetting(Settings.IsManualMediaTransportControls, false);
            ManualMTCSwitch.IsOn = isManualMTC;
            double playerSkipStep = Convert.ToDouble(AppTool.GetLocalSetting(Settings.PlayerSkipStep, "30"));
            PlayerSkipStepBox.Value = playerSkipStep;
            bool isFirst4K = AppTool.GetBoolSetting(Settings.IsFirst4K, false);
            First4KSwitch.IsOn = isFirst4K;
            bool isShowDanmakuBarInFullWindow = AppTool.GetBoolSetting(Settings.IsShowDanmakuBarInFullWindow);
            OpenDanmakuBarInFullWindowSwitch.IsOn = isShowDanmakuBarInFullWindow;
            bool isShowDanmakuBarInCinema = AppTool.GetBoolSetting(Settings.IsShowDanmakuBarInCinema);
            OpenDanmakuBarInCinemaSwitch.IsOn = isShowDanmakuBarInCinema;
            bool isShowDanmakuBarInCompact = AppTool.GetBoolSetting(Settings.IsShowDanmakuBarInCompactOverlay);
            OpenDanmakuBarInCompactSwitch.IsOn = isShowDanmakuBarInCompact;
            bool isShowDanmakuBarInSeparate = AppTool.GetBoolSetting(Settings.IsShowDanmakuBarInSeparate);
            OpenDanmakuBarInSeparateSwitch.IsOn = isShowDanmakuBarInSeparate;
            bool isShowDanmakuInCompact = AppTool.GetBoolSetting(Settings.IsShowDanmakuInCompactOverlay);
            OpenDanmakuInCompactSwitch.IsOn = isShowDanmakuInCompact;
            bool isStopInBackground = AppTool.GetBoolSetting(Settings.IsStopInBackground);
            StopPlayInBackgroundSwitch.IsOn = isStopInBackground;
            string playerMode = AppTool.GetLocalSetting(Settings.PlayerMode, "Default");
            switch (playerMode)
            {
            case "Default":
            default:
                PlayerModeComboBox.SelectedIndex = 0;
                break;

            case "Cinema":
                PlayerModeComboBox.SelectedIndex = 1;
                break;

            case "Full":
                PlayerModeComboBox.SelectedIndex = 2;
                break;
            }
            #endregion

            #region 通知设置
            bool isOpenDynamicToast = AppTool.GetBoolSetting(Settings.IsOpenNewDynamicNotification, false);
            NewDynamicToastSwitch.IsOn = isOpenDynamicToast;
            #endregion

            base.OnNavigatedTo(e);
            _isInit = true;
        }
Example #16
0
        private void OnLaunchedOrActivated(IActivatedEventArgs e)
        {
            try
            {
                Frame rootFrame = Window.Current.Content as Frame;

                // Do not repeat app initialization when the Window already has content,
                // just ensure that the window is active
                if (rootFrame == null)
                {
                    SYEngine.Core.Initialize();
                    // Create a Frame to act as the navigation context and navigate to the first page
                    rootFrame = new Frame();

                    rootFrame.NavigationFailed += OnNavigationFailed;

                    // Place the frame in the current Window
                    Window.Current.Content = rootFrame;
                }

                BackgroundTaskHelper.Register("ToastBackgroundTask", new ToastNotificationActionTrigger());
                if (e is LaunchActivatedEventArgs && (e as LaunchActivatedEventArgs).PrelaunchActivated == false)
                {
                    if (rootFrame.Content == null)
                    {
                        string display = AppTool.GetLocalSetting(Settings.DisplayMode, "");
                        if (string.IsNullOrEmpty(display))
                        {
                            rootFrame.Navigate(typeof(WelcomePage), (e as LaunchActivatedEventArgs).Arguments);
                        }
                        else
                        {
                            if (_isTabletMode)
                            {
                                rootFrame.Navigate(typeof(TabletMainPage), (e as LaunchActivatedEventArgs).Arguments);
                            }
                            else
                            {
                                rootFrame.Navigate(typeof(DesktopMainPage), (e as LaunchActivatedEventArgs).Arguments);
                            }
                        }
                    }
                    // Ensure the current window is active
                }
                else if (e.Kind == ActivationKind.StartupTask)
                {
                    if (rootFrame.Content == null)
                    {
                        if (_isTabletMode)
                        {
                            rootFrame.Navigate(typeof(TabletMainPage), null);
                        }
                        else
                        {
                            rootFrame.Navigate(typeof(DesktopMainPage), null);
                        }
                    }
                }
                else if (e is ToastNotificationActivatedEventArgs toastActivationArgs)
                {
                    if (rootFrame.Content == null)
                    {
                        if (_isTabletMode)
                        {
                            rootFrame.Navigate(typeof(TabletMainPage), toastActivationArgs.Argument);
                        }
                        else
                        {
                            rootFrame.Navigate(typeof(DesktopMainPage), toastActivationArgs.Argument);
                        }
                    }
                    else
                    {
                        AppViewModel.AppInitByActivated(toastActivationArgs.Argument);
                    }
                }
                else if (e is ProtocolActivatedEventArgs protocalArgs)
                {
                    string arg = protocalArgs.Uri.Query.Replace("?", "");
                    if (rootFrame.Content == null)
                    {
                        if (_isTabletMode)
                        {
                            rootFrame.Navigate(typeof(TabletMainPage), arg);
                        }
                        else
                        {
                            rootFrame.Navigate(typeof(DesktopMainPage), arg);
                        }
                    }
                    else
                    {
                        AppViewModel.AppInitByActivated(arg);
                    }
                }
                Window.Current.Activate();
                UIHelper.SetTitleBarColor();
            }
            catch (Exception ex)
            {
                _logger.Error("启动出错", ex);
            }
        }