private void Update(object arg) { if (!isEnabled) { Status.Message = "Himawari\nLast update: {0,HH:mm:ss}.\nUpdating disabled"; notify.SetNotifyIconText(Status.Message); return; } bool success = true; Status.TotalCount++; Status.LastAttempt = DateTime.Now; Status.NowUpdating = true; notify.SetNotifyIconText(Status.GetReport()); Image img = null; try { string url = getUrl(); img = DownloadImg(url); if (!ImgIsNotEmpty(img)) { throw new Exception("The invalid image (\"No Image\") was received"); } setWallpaper(img); } catch (Exception e) { Status.Message = e.GetType().ToString() + '\n'; Status.Message += e.Message; success = false; } Status.NowUpdating = false; if (success) { Status.LastSuccess = DateTime.Now; Status.SuccesCount++; notify.SetNotifyIconText(Status.GetReport()); } else { notify.SetNotifyIconText(Status.Message + "\n Next try: " + Status.LastAttempt.AddMinutes(10).ToString("HH:mm::ss")); } if (img != null) { img.Dispose(); } GC.Collect(); }
private void UpdateTrayIcon() { int dpi; Graphics graphics = Graphics.FromHwnd(IntPtr.Zero); dpi = (int)graphics.DpiX; graphics.Dispose(); icon_baseBitmap = null; if (dpi < 97) { // dpi = 96; icon_baseBitmap = Resources.ss16; } else if (dpi < 121) { // dpi = 120; icon_baseBitmap = Resources.ss20; } else if (dpi < 192) { // dpi = 120; icon_baseBitmap = Resources.ss24; } else { icon_baseBitmap = Resources.ss48; } Configuration config = controller.GetConfigurationCopy(); bool enabled = config.enabled; bool global = config.global; icon_baseBitmap = getTrayIconByState(icon_baseBitmap, enabled, global); icon_base = Icon.FromHandle(icon_baseBitmap.GetHicon()); targetIcon = icon_base; icon_in = Icon.FromHandle(AddBitmapOverlay(icon_baseBitmap, dpi > 190 ? Resources.ssIn48 : Resources.ssIn24).GetHicon()); icon_out = Icon.FromHandle(AddBitmapOverlay(icon_baseBitmap, dpi > 190 ? Resources.ssOut48 : Resources.ssOut24).GetHicon()); icon_both = Icon.FromHandle(AddBitmapOverlay(icon_baseBitmap, dpi > 190 ? Resources.ssIn48 : Resources.ssIn24, dpi > 190 ? Resources.ssOut48 : Resources.ssOut24).GetHicon()); _notifyIcon.Icon = targetIcon; string serverInfo = null; if (controller.GetCurrentStrategy() != null) { serverInfo = controller.GetCurrentStrategy().Name; } else { serverInfo = config.GetCurrentServer().FriendlyName(); } // show more info by hacking the P/Invoke declaration for NOTIFYICONDATA inside Windows Forms string text = I18N.GetString("Shadowsocks") + " " + Program.Version + "\n" + (enabled ? I18N.GetString("System Proxy On: ") + (global ? I18N.GetString("Global") : I18N.GetString("PAC")) : String.Format(I18N.GetString("Running: Port {0}"), config.localPort)) // this feedback is very important because they need to know Shadowsocks is running + "\n" + serverInfo; _notifyIcon.SetNotifyIconText(text); }
private void UpdateTrayIcon() { _notifyIcon.Icon = Resources.v2ray; Configuration config = controller.GetConfigurationCopy(); bool enabled = config.enabled; bool global = config.global; string serverInfo = config.GetCurrentServer().ps; string text = I18N.GetString("V2RayShell") + " " + Global.Version + "\n" + (enabled ? I18N.GetString("System Proxy On: ") + (global ? I18N.GetString("Global") : I18N.GetString("PAC")) : String.Format(I18N.GetString("Running: Port {0}"), $"{config.corePort}/{config.localPort}")) + "\n" + serverInfo; _notifyIcon.SetNotifyIconText(text); }
public AppContext() { AutostartEnable = AutostartIsEnable(); isEnabled = true; notify = new NotifyIcon(); notify.Icon = Properties.Resources.image; notify.Text = "Himawari"; notify.Visible = true; notify.Click += (o, e) => notify.SetNotifyIconText(Status.GetReport()); notify.ContextMenu = CreateContextMenu(); timer = new System.Threading.Timer(Update, null, 0, UPDATE_PERIOD); }
private void UpdateTrayIcon() { int dpi; using (var graphics = Graphics.FromHwnd(IntPtr.Zero)) { dpi = (int)graphics.DpiX; } iconBase = null; if (dpi < 96) { //72 iconBase = Resources.T18; } else if (dpi < 192) { //96 iconBase = Resources.T24; } else { //192 iconBase = Resources.T48; } var config = controller.GetConfigurationCopy(); var enabled = config.enabled; var global = config.global; iconBase = getTrayIconByState(iconBase, enabled, global); trayIcon = Icon.FromHandle(iconBase.GetHicon()); _notifyIcon.Icon = trayIcon; var serverInfo = config.GetCurrentServer().ps; var text = I18N.GetString("V2RayShell") + " " + Global.Version + "\n" + (enabled ? I18N.GetString("System Proxy On: ") + (global ? I18N.GetString("Global") : I18N.GetString("PAC")) : String.Format(I18N.GetString("Running: Port {0}"), $"{config.corePort}/{config.localPort}")) + "\n" + serverInfo; _notifyIcon.SetNotifyIconText(text); }