예제 #1
0
 Bitmap GetNotifyIconFromCache(SysTrayIconTypes iconType)
 {
     if (!sysTrayIconCache.TryGetValue(iconType, out var icon))
     {
         icon = CreateNotifyIconImage(iconType);
         sysTrayIconCache.TryAdd(iconType, icon);
     }
     return(icon.Clone() as Bitmap);
 }
예제 #2
0
        void UpdateNotifyIconWorker(Action done)
        {
            if (setting.IsClosing())
            {
                done();
                return;
            }

            if (setting.IsScreenLocked())
            {
                VgcApis.Misc.Utils.RunInBackground(() =>
                {
                    VgcApis.Misc.Utils.Sleep(1000);
                    done();
                    VgcApis.Misc.Utils.Sleep(1000);
                    lazyNotifierMenuUpdater?.Postpone();
                });
                return;
            }

            var    start    = DateTime.Now.Millisecond;
            Action finished = () => VgcApis.Misc.Utils.RunInBackground(() =>
            {
                var relex = UpdateInterval - (DateTime.Now.Millisecond - start);
                VgcApis.Misc.Utils.Sleep(Math.Max(0, relex));
                done();
            });

            try
            {
                var list = servers.GetAllServersOrderByIndex()
                           .Where(s => s.GetCoreCtrl().IsCoreRunning())
                           .ToList();

                var iconType = AnalyzeSysTrayIconType(list);

                if (iconType != curSysTrayIconType)
                {
                    Invoke(() =>
                    {
                        var icon = GetNotifyIconFromCache(iconType);
                        var org  = ni.Icon;
                        ni.Icon  = Icon.FromHandle(icon.GetHicon());
                        org?.Dispose();
                    });
                    curSysTrayIconType = iconType;
                }
                UpdateNotifyIconTextThen(list, finished);
            }
            catch (Exception e)
            {
                VgcApis.Libs.Sys.FileLogger.Error($"Notifier update icon error!\n{e}");
                done();
            }
        }
예제 #3
0
        private Bitmap CreateNotifyIconImage(SysTrayIconTypes iconType)
        {
            var icon = new Bitmap(orgIcon);
            var size = icon.Size;

            using (Graphics g = Graphics.FromImage(icon))
            {
                g.InterpolationMode  = InterpolationMode.High;
                g.CompositingQuality = CompositingQuality.HighQuality;

                DrawProxyModeCornerCircle(g, size, iconType);
                DrawIsRunningCornerMark(g, size, iconType);
            }

            return(icon);
        }
예제 #4
0
        void DrawProxyModeCornerCircle(
            Graphics graphics, Size size, SysTrayIconTypes iconType)
        {
            Brush br = Brushes.ForestGreen;

            if (0 != (iconType & SysTrayIconTypes.ProxyPac))
            {
                br = Brushes.DeepPink;
            }
            else if (0 != (iconType & SysTrayIconTypes.ProxyGlobal))
            {
                br = Brushes.Blue;
            }

            var w = size.Width;
            var x = w * 0.4f;
            var s = w * 0.6f;

            graphics.FillEllipse(br, x, x, s, s);
        }
예제 #5
0
        private void DrawIsRunningCornerMark(
            Graphics graphics, Size size, SysTrayIconTypes iconType)
        {
            var w  = size.Width;
            var cx = w * 0.7f;

            if (0 != (iconType & SysTrayIconTypes.FirstServRunning))
            {
                DrawTriangle(graphics, w, cx, true);
            }
            else if (0 != (iconType & SysTrayIconTypes.OthServRunning))
            {
                DrawTriangle(graphics, w, cx, false);
            }
            else if (0 != (iconType & SysTrayIconTypes.MultiServRunning))
            {
                DrawOneLine(graphics, w, cx, false);
                DrawOneLine(graphics, w, cx, true);
            }
            else
            {
                DrawOneLine(graphics, w, cx, false);
            }
        }