Пример #1
0
        public void loadInitData()
        {
            new Thread(() =>
            {
                var DataKit             = new DataKit();
                var monitorSettingQuery = from c in DataKit.Realm.All <BackgroundSettingsByMonitor>() where c.MonitorDeviceName == MainWindow.MonitorDeviceName select c;
                BackgroundSettingsByMonitor monitorSetting = monitorSettingQuery.First();

                int backgroundType      = monitorSetting.backgroundType;
                string imgPath          = monitorSetting.imgPath;
                string solidColor       = monitorSetting.SolidColor;
                string youtubeVideoCode = monitorSetting.YoutubeURL;

                this.Dispatcher.Invoke(new Action(() =>
                {
                    backgroundToggle.IsChecked = backgroundType == BackgroundSettingsByMonitor.BackgroundType.STILL_IMAGE;
                    solidToggle.IsChecked      = backgroundType == BackgroundSettingsByMonitor.BackgroundType.SOLID;
                    youtubeToggle.IsChecked    = backgroundType == BackgroundSettingsByMonitor.BackgroundType.YOUTUBE_VIDEO;

                    if (imgPath != "" && imgPath != null)
                    {
                        if (File.Exists(imgPath))
                        {
                            stillImage.Source  = new BitmapImage(new Uri(imgPath));
                            stillImage.Stretch = Stretch.UniformToFill;
                        }
                    }
                    else
                    {
                        stillImage.Source = null;
                    }

                    BrushConverter bc = new BrushConverter();
                    if (solidColor != null && solidColor != "")
                    {
                        solidColorContainer.Background = (Brush)bc.ConvertFrom("#" + solidColor);
                    }
                    else
                    {
                        solidColorContainer.Background = (Brush)bc.ConvertFrom("#10FFFFFF");
                    }

                    youtubeVideoCodeTextBox.Text = youtubeVideoCode;

                    if (!backgroundToggle.IsChecked ?? false)
                    {
                        stillImageBorder.Opacity = 0.3;
                    }
                    else
                    {
                        stillImageBorder.Opacity = 1;
                    }

                    if (!solidToggle.IsChecked ?? false)
                    {
                        solidImageBorder.Opacity = 0.3;
                    }
                    else
                    {
                        solidImageBorder.Opacity = 1;
                    }

                    if (!youtubeToggle.IsChecked ?? false)
                    {
                        youtubeVideoCodeTextBox.Opacity   = 0.3;
                        youtubeVideoCodeTextBox.IsEnabled = false;
                    }
                    else
                    {
                        youtubeVideoCodeTextBox.Opacity   = 1;
                        youtubeVideoCodeTextBox.IsEnabled = true;
                    }
                }));
            }).Start();
        }
Пример #2
0
        private void CheckBackgroundChange()
        {
            DataKit DataKit = new DataKit();

            while (true)
            {
                DataKit.Realm.Refresh();
                BackgroundSettingsByMonitor backgroundSetting = DataKit.Realm.All <BackgroundSettingsByMonitor>().Where(c => c.MonitorDeviceName == Renderer.MonitorDeviceName).First();

                bool isSolid   = backgroundSetting.backgroundType == BackgroundSettingsByMonitor.BackgroundType.SOLID;
                bool isYoutube = backgroundSetting.backgroundType == BackgroundSettingsByMonitor.BackgroundType.YOUTUBE_VIDEO;

                // caption-window;
                if (isYoutube)
                {
                    youtubeView.GetBrowser().MainFrame.EvaluateScriptAsync("if (typeof css === 'undefined') { var css = '.ytp-caption-window-bottom { display: none !important }', head = document.head, style = document.createElement('style'); style.type = 'text/css'; style.appendChild(document.createTextNode(css)); head.appendChild(style); }");
                    youtubeView.GetBrowser().MainFrame.EvaluateScriptAsync("if (typeof css2 === 'undefined') { var css2 = '.video-annotations { display: none !important }', head = document.head, style = document.createElement('style'); style.type = 'text/css'; style.appendChild(document.createTextNode(css2)); head.appendChild(style); }");
                }

                Dispatcher.Invoke(new Action(() =>
                {
                    if (!isSolid)
                    {
                        BrushConverter bc      = new BrushConverter();
                        overlayView.Background = (Brush)bc.ConvertFrom("#10000000");
                    }
                }));

                if (backgroundSetting.backgroundType == BackgroundSettingsByMonitor.BackgroundType.DEFAULT)
                {
                    string path = DesktopWallpaperGenerator.GetBackgroud();

                    if (systemBackgroundPath != path)
                    {
                        Dispatcher.Invoke(new Action(() =>
                        {
                            backgroundImage.Source = new BitmapImage(new Uri(path));

                            youtubeView.Address    = "";
                            youtubeView.Visibility = Visibility.Hidden;
                        }));

                        systemBackgroundPath = path;
                        backgroundPath       = "";
                        youtubeVCode         = "";
                        solidColor           = "";
                    }
                }
                else if (backgroundSetting.backgroundType == BackgroundSettingsByMonitor.BackgroundType.STILL_IMAGE)
                {
                    string path = backgroundSetting.imgPath;

                    if (File.Exists(path))
                    {
                        if (backgroundPath != path)
                        {
                            backgroundPath = backgroundSetting.imgPath;

                            Dispatcher.Invoke(new Action(() =>
                            {
                                if (File.Exists(backgroundPath))
                                {
                                    backgroundImage.Source = new BitmapImage(new Uri(backgroundPath));
                                }
                                else
                                {
                                    systemBackgroundPath   = DesktopWallpaperGenerator.GetBackgroud();
                                    backgroundImage.Source = new BitmapImage(new Uri(systemBackgroundPath));
                                }

                                BrushConverter bc      = new BrushConverter();
                                overlayView.Background = (Brush)bc.ConvertFrom("#10000000");

                                youtubeView.Address    = "";
                                youtubeView.Visibility = Visibility.Hidden;

                                systemBackgroundPath = "";
                                youtubeVCode         = "";
                                solidColor           = "";
                            }));
                        }
                    }
                    else
                    {
                        string spath = DesktopWallpaperGenerator.GetBackgroud();

                        if (systemBackgroundPath != spath)
                        {
                            Dispatcher.Invoke(new Action(() =>
                            {
                                backgroundImage.Source = new BitmapImage(new Uri(spath));

                                systemBackgroundPath = spath;

                                youtubeView.Address    = "";
                                youtubeView.Visibility = Visibility.Hidden;
                            }));

                            backgroundPath = "";
                            youtubeVCode   = "";
                            solidColor     = "";
                        }
                    }
                }
                else if (backgroundSetting.backgroundType == BackgroundSettingsByMonitor.BackgroundType.SOLID)
                {
                    string solid = backgroundSetting.SolidColor;

                    if (solidColor != solid)
                    {
                        solidColor = solid;
                        Dispatcher.Invoke(new Action(() =>
                        {
                            // backgroundImage.Source = null;

                            BrushConverter bc      = new BrushConverter();
                            overlayView.Background = (Brush)bc.ConvertFrom("#" + solidColor);

                            youtubeView.Address    = "";
                            youtubeView.Visibility = Visibility.Hidden;

                            systemBackgroundPath = "";
                            backgroundPath       = "";
                            youtubeVCode         = "";
                        }));
                    }
                }
                else
                {
                    string youtubeVideo = backgroundSetting.YoutubeURL;

                    if (youtubeVCode != youtubeVideo)
                    {
                        youtubeVCode = youtubeVideo;
                        Dispatcher.Invoke(new Action(() =>
                        {
                            if (youtubeVideo == "" || youtubeVideo == null)
                            {
                                backgroundPath         = DesktopWallpaperGenerator.GetBackgroud();
                                backgroundImage.Source = new BitmapImage(new Uri(backgroundPath));
                            }
                            else
                            {
                                youtubeView.Visibility = Visibility.Visible;
                                youtubeView.Address    = string.Format("https://www.youtube.com/embed/{0}?controls=0&showinfo=0&rel=0&autoplay=1&loop=1&mute=1&cc_load_policy=3&playlist={0}", youtubeVCode);
                                // youtubeView.GetBrowser().MainFrame.EvaluateScriptAsync("setInterval(() => { document.getElementsByClassName('caption-window ytp-caption-window-bottom')[0].style.display = 'none'; console.clear(); }, 100);");
                            }

                            BrushConverter bc      = new BrushConverter();
                            overlayView.Background = (Brush)bc.ConvertFrom("#10000000");

                            systemBackgroundPath = "";
                            backgroundPath       = "";
                            solidColor           = "";
                        }));
                    }
                }

                // Console.WriteLine("Communicating HangulClock Data Kit...");

                try
                {
                    Thread.Sleep(5000);
                }
                catch (ThreadInterruptedException)
                {
                }
            }
        }
Пример #3
0
        public static void initFirstData()
        {
            new Thread(() =>
            {
                var DataKit = new DataKit();

                var hangulClockCommonSetting = DataKit.Realm.All <HangulClockCommonSetting>();
                if (hangulClockCommonSetting.Count() <= 0)
                {
                    var setting = new HangulClockCommonSetting();
                    setting.hu  = RandomString(16);

                    DataKit.Realm.Write(() =>
                    {
                        DataKit.Realm.Add(setting);
                    });
                }

                var screens = System.Windows.Forms.Screen.AllScreens;

                foreach (var screen in screens)
                {
                    var clockSetting = from c in DataKit.Realm.All <ClockSettingsByMonitor>() where c.MonitorDeviceName == screen.DeviceName select c;
                    if (clockSetting.Count() <= 0)
                    {
                        var setting = new ClockSettingsByMonitor();

                        DataKit.Realm.Write(() =>
                        {
                            setting.IsWhiteClock      = true;
                            setting.MonitorDeviceName = screen.DeviceName;
                            setting.ClockSize         = 100;
                            setting.YoutubeURL        = "";

                            DataKit.Realm.Add(setting);
                        });
                    }

                    var commentSetting = from c in DataKit.Realm.All <CommentSettingsByMonitor>() where c.MonitorDeviceName == screen.DeviceName select c;
                    if (commentSetting.Count() <= 0)
                    {
                        var setting = new CommentSettingsByMonitor();

                        DataKit.Realm.Write(() =>
                        {
                            setting.MonitorDeviceName       = screen.DeviceName;
                            setting.IsEnabled               = false;
                            setting.IsEnabledLoadFromServer = false;

                            setting.Name    = "";
                            setting.Comment = "";

                            DataKit.Realm.Add(setting);
                        });
                    }

                    var backgroundSetting = from c in DataKit.Realm.All <BackgroundSettingsByMonitor>() where c.MonitorDeviceName == screen.DeviceName select c;
                    if (backgroundSetting.Count() <= 0)
                    {
                        var setting = new BackgroundSettingsByMonitor();

                        DataKit.Realm.Write(() =>
                        {
                            setting.MonitorDeviceName = screen.DeviceName;
                            setting.backgroundType    = BackgroundSettingsByMonitor.BackgroundType.DEFAULT;

                            DataKit.Realm.Add(setting);
                        });
                    }
                }
            }).Start();
        }
Пример #4
0
        private void Desktop_Loaded(object sender, RoutedEventArgs e)
        {
            HideWindowFromAltTab();

            new Thread(() =>
            {
                DataKit DataKit = new DataKit();
                BackgroundSettingsByMonitor backgroundSetting = DataKit.Realm.All <BackgroundSettingsByMonitor>().Where(c => c.MonitorDeviceName == Renderer.MonitorDeviceName).First();

                if (backgroundSetting.backgroundType == BackgroundSettingsByMonitor.BackgroundType.DEFAULT)
                {
                    Dispatcher.Invoke(new Action(() =>
                    {
                        systemBackgroundPath   = DesktopWallpaperGenerator.GetBackgroud();
                        backgroundImage.Source = new BitmapImage(new Uri(systemBackgroundPath));

                        youtubeView.Address    = "";
                        youtubeView.Visibility = Visibility.Hidden;
                    }));
                }
                else if (backgroundSetting.backgroundType == BackgroundSettingsByMonitor.BackgroundType.STILL_IMAGE)
                {
                    backgroundPath = backgroundSetting.imgPath;

                    Dispatcher.Invoke(new Action(() =>
                    {
                        if (File.Exists(backgroundPath))
                        {
                            backgroundImage.Source = new BitmapImage(new Uri(backgroundPath));
                        }
                        else
                        {
                            systemBackgroundPath   = DesktopWallpaperGenerator.GetBackgroud();
                            backgroundImage.Source = new BitmapImage(new Uri(systemBackgroundPath));
                        }

                        youtubeView.Address    = "";
                        youtubeView.Visibility = Visibility.Hidden;
                    }));
                }
                else if (backgroundSetting.backgroundType == BackgroundSettingsByMonitor.BackgroundType.SOLID)
                {
                    solidColor = backgroundSetting.SolidColor;
                    Dispatcher.Invoke(new Action(() =>
                    {
                        // backgroundImage.Source = null;
                        BrushConverter bc = new BrushConverter();

                        if (solidColor != null && solidColor != "")
                        {
                            overlayView.Background = (Brush)bc.ConvertFrom("#" + solidColor);
                        }
                        else
                        {
                            overlayView.Background = (Brush)bc.ConvertFrom("#000000");
                        }

                        youtubeView.Address    = "";
                        youtubeView.Visibility = Visibility.Hidden;
                    }));
                }
                else
                {
                    youtubeVCode = backgroundSetting.YoutubeURL;
                    Dispatcher.Invoke(new Action(() =>
                    {
                        if (youtubeVCode == "" || youtubeVCode == null)
                        {
                            backgroundPath         = DesktopWallpaperGenerator.GetBackgroud();
                            backgroundImage.Source = new BitmapImage(new Uri(backgroundPath));
                        }
                        else
                        {
                            youtubeView.Visibility = Visibility.Visible;
                            youtubeView.Address    = string.Format("https://www.youtube.com/embed/{0}?controls=0&showinfo=0&rel=0&autoplay=1&loop=1&cc_load_policy=3&mute=1&playlist={0}", youtubeVCode);
                        }
                    }));
                }

                new Thread(CheckBackgroundChange).Start();
            }).Start();
        }