Published v1.3.1.0.
Harmony Auth Token now persisted in settings.
Various EAR view fixes.
Removed Sleep action
2 // Copyright (C) 2014-2016 Stéphane Lenclud.
4 // This file is part of SharpDisplayManager.
6 // SharpDisplayManager is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // SharpDisplayManager is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with SharpDisplayManager. If not, see <http://www.gnu.org/licenses/>.
21 using System.Collections.Generic;
22 using System.ComponentModel;
27 using System.Threading.Tasks;
28 using System.Windows.Forms;
29 using System.Diagnostics;
30 using SharpLib.Display;
33 namespace SharpDisplayClientIdle
37 /// Sharp Display Client designed to act as an idle client.
38 /// It should take care of screen saving and other such concerns.
40 public partial class FormClientIdle : Form
42 public StartParams Params { get; set; }
45 ContentAlignment iAlignment;
47 //Used to determine if screen saver need to kick in
48 private PowerManager.SettingNotifier iPowerSettingNotifier;
49 private bool MonitorPowerOn;
51 public delegate void CloseDelegate();
52 public delegate void CloseConnectionDelegate();
55 public FormClientIdle()
57 InitializeComponent();
63 /// <param name="sender"></param>
64 /// <param name="e"></param>
65 private void FormClientIdle_Load(object sender, EventArgs e)
67 //Prevents showing in the Open Task view (Windows Key + Tab)
71 iClient = new Client();
72 iClient.CloseOrderEvent += OnCloseOrder;
74 iClient.SetName("Idle");
75 iClient.SetPriority(Priorities.Background);
79 iTimer.Interval = IntervalToNextMinute();
82 //Create our power setting notifier and register the event we are interested in
83 iPowerSettingNotifier = new PowerManager.SettingNotifier(Handle);
84 iPowerSettingNotifier.OnMonitorPowerOn += OnMonitorPowerOn;
85 iPowerSettingNotifier.OnMonitorPowerOff += OnMonitorPowerOff;
86 MonitorPowerOn = true;
91 /// Broadcast messages to subscribers.
93 /// <param name="message"></param>
94 protected override void WndProc(ref Message aMessage)
96 //Hook in our power manager
97 if (iPowerSettingNotifier != null)
99 iPowerSettingNotifier.WndProc(ref aMessage);
102 base.WndProc(ref aMessage);
110 private void OnMonitorPowerOn()
112 MonitorPowerOn = true;
119 private void OnMonitorPowerOff()
121 MonitorPowerOn = false;
129 /// <returns></returns>
130 public static int IntervalToNextMinute()
132 DateTime now = DateTime.Now;
133 return 60000 - now.Millisecond;
140 /// <returns></returns>
141 public bool IsClientReady()
143 return (iClient != null && iClient.IsReady());
149 public void SetupDisplayClient()
153 //Set one column one line layout
154 TableLayout layout = new TableLayout(1, 1);
155 iClient.SetLayout(layout);
158 iAlignment = ContentAlignment.MiddleCenter;
159 iTextField = new TextField(DateTime.Now.ToString("t"), iAlignment, 0, 0);
162 iClient.CreateFields(new DataField[]
168 public void OnCloseOrder()
176 public void CloseThreadSafe()
178 if (this.InvokeRequired)
180 //Not in the proper thread, invoke ourselves
181 CloseDelegate d = new CloseDelegate(CloseThreadSafe);
182 this.Invoke(d, new object[] { });
186 //We are in the proper thread
194 public void CloseConnectionThreadSafe()
196 if (this.InvokeRequired)
198 //Not in the proper thread, invoke ourselves
199 CloseConnectionDelegate d = new CloseConnectionDelegate(CloseConnectionThreadSafe);
200 this.Invoke(d, new object[] { });
204 //We are in the proper thread
207 string sessionId = iClient.SessionId;
208 Trace.TraceInformation("Closing client: " + sessionId);
210 Trace.TraceInformation("Closed client: " + sessionId);
220 /// <param name="sender"></param>
221 /// <param name="e"></param>
222 private void FormClientIdle_FormClosing(object sender, FormClosingEventArgs e)
224 CloseConnectionThreadSafe();
231 /// <param name="sender"></param>
232 /// <param name="e"></param>
233 private void iTimer_Tick(object sender, EventArgs e)
236 iTimer.Interval = IntervalToNextMinute();
246 private void UpdateDisplay()
249 if (String.IsNullOrEmpty(iTextField.Text))
251 //Time to show our time
252 iTextField.Text = DateTime.Now.ToString("t");
256 //Do some screen saving
257 iTextField.Text = "";
261 iClient.SetField(iTextField);
263 //Now make sure we save our screen from any running system monitor
264 //We don't go into screen saving mode if our monitor is still on
265 if (String.IsNullOrEmpty(iTextField.Text) && !MonitorPowerOn)
267 //If text it empty it means we need to cool down our display even if system monitor is running
268 iClient.SetPriority(Priorities.SystemMonitor + 1);
272 //Switch back to background then, leaving system monitor if any doing its magic
273 iClient.SetPriority(Priorities.Background);
280 /// <param name="sender"></param>
281 /// <param name="e"></param>
282 private void FormClientIdle_Shown(object sender, EventArgs e)