Skip to content

Commit 2398a40

Browse files
committed
Delayed FlashConnect & PM focused on first run...
1 parent 1f945cc commit 2398a40

File tree

2 files changed

+79
-58
lines changed

2 files changed

+79
-58
lines changed

External/Plugins/FlashConnect/PluginMain.cs

Lines changed: 71 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
using System;
2-
using System.ComponentModel;
32
using System.IO;
4-
using System.Net.Sockets;
5-
using System.Text;
3+
using System.Xml;
64
using System.Web;
5+
using System.Text;
6+
using System.Net.Sockets;
7+
using System.ComponentModel;
78
using System.Windows.Forms;
8-
using System.Xml;
9-
using PluginCore;
10-
using PluginCore.Helpers;
9+
using WeifenLuo.WinFormsUI;
1110
using PluginCore.Localization;
12-
using PluginCore.Managers;
1311
using PluginCore.Utilities;
12+
using PluginCore.Managers;
13+
using PluginCore.Helpers;
14+
using PluginCore;
1415

1516
namespace FlashConnect
1617
{
@@ -24,6 +25,7 @@ public class PluginMain : IPlugin
2425
private String settingFilename;
2526
private Settings settingObject;
2627
private XmlSocket xmlSocket;
28+
private Timer pendingSetup;
2729

2830
#region Required Properties
2931

@@ -103,6 +105,11 @@ public void Initialize()
103105
/// </summary>
104106
public void Dispose()
105107
{
108+
if (this.pendingSetup != null)
109+
{
110+
this.pendingSetup.Stop();
111+
this.pendingSetup = null;
112+
}
106113
this.SaveSettings();
107114
}
108115

@@ -115,9 +122,9 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority)
115122
}
116123

117124
#endregion
118-
125+
119126
#region Custom Methods
120-
127+
121128
// Response messages and errors
122129
private readonly Byte[] RESULT_INVALID = Encoding.Default.GetBytes("<flashconnect status=\"1\"/>\0");
123130
private readonly Byte[] RESULT_NOTFOUND = Encoding.Default.GetBytes("<flashconnect status=\"2\"/>\0");
@@ -139,57 +146,65 @@ private void InitBasics()
139146
/// </summary>
140147
private void SetupSocket()
141148
{
142-
if (this.settingObject.Enabled && !SingleInstanceApp.AlreadyExists)
149+
this.pendingSetup = new Timer();
150+
this.pendingSetup.Interval = 5000;
151+
this.pendingSetup.Tick += (sender, e) =>
143152
{
144-
this.xmlSocket = new XmlSocket(this.settingObject.Host, this.settingObject.Port);
145-
this.xmlSocket.XmlReceived += new XmlReceivedEventHandler(this.HandleXml);
146-
}
153+
this.pendingSetup.Stop();
154+
this.pendingSetup = null;
155+
if (this.settingObject.Enabled && !SingleInstanceApp.AlreadyExists)
156+
{
157+
this.xmlSocket = new XmlSocket(this.settingObject.Host, this.settingObject.Port);
158+
this.xmlSocket.XmlReceived += new XmlReceivedEventHandler(this.HandleXml);
159+
}
160+
};
161+
this.pendingSetup.Start();
147162
}
148-
163+
149164
/// <summary>
150165
/// Handles the incoming xml message
151166
/// </summary>
152167
public void HandleXml(Object sender, XmlReceivedEventArgs e)
153168
{
154169
if (PluginBase.MainForm.MenuStrip.InvokeRequired) PluginBase.MainForm.MenuStrip.BeginInvoke((MethodInvoker)delegate
155-
{
156-
try
157170
{
158-
XmlDocument message = e.XmlDocument;
159-
XmlNode mainNode = message.FirstChild;
160-
for (Int32 i = 0; i < mainNode.ChildNodes.Count; i++)
171+
try
161172
{
162-
XmlNode cmdNode = mainNode.ChildNodes[i];
163-
if (XmlHelper.HasAttribute(cmdNode, "cmd"))
173+
XmlDocument message = e.XmlDocument;
174+
XmlNode mainNode = message.FirstChild;
175+
for (Int32 i = 0; i < mainNode.ChildNodes.Count; i++)
164176
{
165-
String cmd = XmlHelper.GetAttribute(cmdNode, "cmd");
166-
switch (cmd)
177+
XmlNode cmdNode = mainNode.ChildNodes[i];
178+
if (XmlHelper.HasAttribute(cmdNode, "cmd"))
167179
{
168-
case "call":
169-
this.HandleCallMsg(cmdNode, e.Socket);
170-
break;
171-
case "trace":
172-
this.HandleTraceMsg(cmdNode, e.Socket);
173-
break;
174-
case "notify":
175-
this.HandleNotifyMsg(cmdNode, e.Socket);
176-
break;
177-
case "return":
178-
this.HandleReturnMsg(cmdNode, e.Socket);
179-
break;
180-
default:
181-
ErrorManager.ShowError(INVALID_MSG);
182-
break;
180+
String cmd = XmlHelper.GetAttribute(cmdNode, "cmd");
181+
switch (cmd)
182+
{
183+
case "call":
184+
this.HandleCallMsg(cmdNode, e.Socket);
185+
break;
186+
case "trace":
187+
this.HandleTraceMsg(cmdNode, e.Socket);
188+
break;
189+
case "notify":
190+
this.HandleNotifyMsg(cmdNode, e.Socket);
191+
break;
192+
case "return":
193+
this.HandleReturnMsg(cmdNode, e.Socket);
194+
break;
195+
default:
196+
ErrorManager.ShowError(INVALID_MSG);
197+
break;
198+
}
183199
}
200+
else ErrorManager.ShowError(INVALID_MSG);
184201
}
185-
else ErrorManager.ShowError(INVALID_MSG);
186202
}
187-
}
188-
catch (Exception ex)
189-
{
190-
ErrorManager.ShowError(ex);
191-
}
192-
});
203+
catch (Exception ex)
204+
{
205+
ErrorManager.ShowError(ex);
206+
}
207+
});
193208
}
194209

195210
/// <summary>
@@ -217,18 +232,18 @@ public void HandleCallMsg(XmlNode msgNode, Socket client)
217232
/// </summary>
218233
public void HandleTraceMsg(XmlNode msgNode, Socket client)
219234
{
220-
try
235+
try
221236
{
222237
String message = HttpUtility.UrlDecode(XmlHelper.GetValue(msgNode));
223238
Int32 state = Convert.ToInt32(XmlHelper.GetAttribute(msgNode, "state"));
224239
TraceManager.Add(message, state);
225-
}
240+
}
226241
catch
227242
{
228243
client.Send(RESULT_INVALID);
229244
}
230245
}
231-
246+
232247
/// <summary>
233248
/// Handles the notify message
234249
/// </summary>
@@ -237,7 +252,7 @@ public void HandleNotifyMsg(XmlNode msgNode, Socket client)
237252
String message;
238253
String guid;
239254
IPlugin plugin;
240-
try
255+
try
241256
{
242257
message = HttpUtility.UrlDecode(XmlHelper.GetValue(msgNode));
243258
guid = XmlHelper.GetAttribute(msgNode, "guid");
@@ -248,23 +263,23 @@ public void HandleNotifyMsg(XmlNode msgNode, Socket client)
248263
plugin.HandleEvent(client, de, HandlingPriority.High);
249264
}
250265
else client.Send(RESULT_NOTFOUND);
251-
}
266+
}
252267
catch
253268
{
254269
client.Send(RESULT_INVALID);
255270
}
256271
}
257-
272+
258273
/// <summary>
259274
/// Handles the return message
260275
/// </summary>
261276
public void HandleReturnMsg(XmlNode msgNode, Socket client)
262277
{
263-
try
278+
try
264279
{
265280
Byte[] data = Encoding.ASCII.GetBytes(msgNode.InnerXml + "\0");
266281
client.Send(data);
267-
}
282+
}
268283
catch
269284
{
270285
client.Send(RESULT_INVALID);
@@ -299,7 +314,7 @@ public void SaveSettings()
299314
}
300315

301316
#endregion
302-
317+
303318
}
304-
305-
}
319+
320+
}

External/Plugins/ProjectManager/PluginMain.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public class PluginMain : IPlugin
8686
private Timer buildTimer;
8787
private bool listenToPathChange;
8888
private ProjectManagerUIStatus uiStatus = ProjectManagerUIStatus.NotBuilding;
89+
private bool firstRun;
8990

9091
private ProjectTreeView Tree { get { return pluginUI.Tree; } }
9192
public static IMainForm MainForm { get { return PluginBase.MainForm; } }
@@ -104,7 +105,11 @@ public void LoadSettings()
104105
{
105106
Settings = new ProjectManagerSettings();
106107
if (!Directory.Exists(SettingsDir)) Directory.CreateDirectory(SettingsDir);
107-
if (!File.Exists(SettingsPath)) this.SaveSettings();
108+
if (!File.Exists(SettingsPath))
109+
{
110+
this.SaveSettings();
111+
firstRun = true;
112+
}
108113
else
109114
{
110115
Object obj = ObjectSerializer.Deserialize(SettingsPath, Settings);
@@ -356,7 +361,8 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority)
356361
{
357362
BroadcastMenuInfo();
358363
BroadcastToolBarInfo();
359-
OpenLastProject();
364+
OpenLastProject();
365+
if (firstRun) pluginPanel.Show();
360366
});
361367
break;
362368

0 commit comments

Comments
 (0)