Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add notification test feature. Add feature to flash taskbar on whispe…
…rs. Improve SMTP support.
  • Loading branch information
Ognjen Ivkovic committed Mar 6, 2017
1 parent a518546 commit b886ac0
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 63 deletions.
6 changes: 3 additions & 3 deletions PoEWhisperNotifier.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoEWhisperNotifier", "PoEWhisperNotifier\PoEWhisperNotifier.csproj", "{BD2DDBBA-AAD1-4D52-BA28-C243550A1F97}"
EndProject
Expand All @@ -11,8 +11,8 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BD2DDBBA-AAD1-4D52-BA28-C243550A1F97}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{BD2DDBBA-AAD1-4D52-BA28-C243550A1F97}.Debug|Any CPU.Build.0 = Release|Any CPU
{BD2DDBBA-AAD1-4D52-BA28-C243550A1F97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BD2DDBBA-AAD1-4D52-BA28-C243550A1F97}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD2DDBBA-AAD1-4D52-BA28-C243550A1F97}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD2DDBBA-AAD1-4D52-BA28-C243550A1F97}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
Expand Down
9 changes: 6 additions & 3 deletions PoEWhisperNotifier/App.config
Expand Up @@ -46,15 +46,18 @@
<setting name="LogPartyMessages" serializeAs="String">
<value>False</value>
</setting>
<setting name="LogGuildMessages" serializeAs="String">
<value>False</value>
</setting>
<setting name="LogGuildMessages" serializeAs="String">
<value>False</value>
</setting>
<setting name="PreviousSize" serializeAs="String">
<value>0, 0</value>
</setting>
<setting name="PreviousLocation" serializeAs="String">
<value>0, 0</value>
</setting>
<setting name="FlashTaskbar" serializeAs="String">
<value>True</value>
</setting>
</PoEWhisperNotifier.Properties.Settings>
</userSettings>
</configuration>
74 changes: 42 additions & 32 deletions PoEWhisperNotifier/Main.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 31 additions & 22 deletions PoEWhisperNotifier/Main.cs
Expand Up @@ -23,6 +23,7 @@ public partial class Main : Form {
[DllImport("user32.dll")]
public static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);


private bool IsMonitoring {
get { return this.Monitor != null && this.Monitor.IsMonitoring; }
}
Expand Down Expand Up @@ -151,7 +152,12 @@ public partial class Main : Form {
this.Monitor.MessageReceived -= ProcessMessage;
AppendMessage("Program stopped at " + DateTime.Now.ToShortTimeString() + ".");
}


private void testNotificationToolStripMenuItem_Click(object sender, EventArgs e) {
var Message = new MessageData(DateTime.Now, "Tester", "This is a fake whisper for testing notifications.", LogMessageType.Whisper);
SendNotification(Message, true);
}

void ProcessMessage(MessageData obj) {
if (obj.MessageType == LogMessageType.Party && !Settings.Default.LogPartyMessages)
return;
Expand All @@ -165,13 +171,17 @@ public partial class Main : Form {
}
// Otherwise, they are idle, so process the message anyways.
}
string StampedMessage = "[" + obj.Date.ToShortTimeString() + "]" + (obj.Sender == null ? "" : (" " + LogMonitor.ChatSymbolForMessageType(obj.MessageType) + obj.Sender)) + ": " + obj.Message;
string Title = "Path of Exile " + obj.MessageType;
SendNotification(obj, false);
}

private void SendNotification(MessageData Message, bool AssumeInactive) {
string StampedMessage = "[" + Message.Date.ToShortTimeString() + "]" + (Message.Sender == null ? "" : (" " + LogMonitor.ChatSymbolForMessageType(Message.MessageType) + Message.Sender)) + ": " + Message.Message;
string Title = "Path of Exile " + Message.MessageType;
Invoke(new Action(() => AppendMessage(StampedMessage)));
if(Settings.Default.TrayNotifications) {
if (Settings.Default.TrayNotifications) {
Invoke(new Action(() => {
NotificationIcon.Visible = true;
NotificationIcon.ShowBalloonTip(5000, Title, (obj.Sender == null ? "" : (obj.Sender + ": ")) + obj.Message, ToolTipIcon.Info);
NotificationIcon.ShowBalloonTip(5000, Title, (Message.Sender == null ? "" : (Message.Sender + ": ")) + Message.Message, ToolTipIcon.Info);
}));
}
if (Settings.Default.EnableSound) {
Expand All @@ -181,26 +191,35 @@ public partial class Main : Form {
AppendMessage("<Error playing sound. This usually occurs due to the Content folder being missing.\r\n Additional Info: " + ex.Message + ">");
}
}
if(Settings.Default.EnableSmtpNotifications) {
if (Settings.Default.EnableSmtpNotifications) {
// Feels wasteful to always reload, but really it should only take a millisecond or less.
var SmtpSettings = SmtpDetails.LoadFromSettings();
var SmtpAct = CheckedAction("SMTP", () => SendSmtpNotification(SmtpSettings, StampedMessage));
if (!SmtpSettings.NotifyOnlyIfIdle)
if (!SmtpSettings.NotifyOnlyIfIdle || AssumeInactive)
SmtpAct();
else
IdleManager.AddIdleAction(SmtpAct);
}
if(Settings.Default.EnablePushbullet) {
if (Settings.Default.EnablePushbullet) {
var PbSettings = PushBulletDetails.LoadFromSettings();
var PbAct = CheckedAction("PushBullet", () => {
var Client = new PushBulletClient(PbSettings);
Client.SendPush(Title, StampedMessage);
});
if (!PbSettings.NotifyOnlyIfIdle)
if (!PbSettings.NotifyOnlyIfIdle || AssumeInactive)
PbAct();
else
IdleManager.AddIdleAction(PbAct);
}
if (Settings.Default.FlashTaskbar && (!IsPoeActive() || AssumeInactive)) {
var PoeProcess = GetPoeProcess();
if (PoeProcess != null) {
var FlashAct = CheckedAction("Taskbar Flash", () => WindowFlasher.FlashWindow(PoeProcess.MainWindowHandle, FlashStyle.All));
FlashAct();
} else {
AppendMessage("<Could not find the PoE process to flash the taskbar>");
}
}
}

// Wraps an Action in a try-catch and appends to the history any errors with it.
Expand All @@ -226,8 +245,7 @@ public partial class Main : Form {
Client.Port = SmtpSettings.SmtpPort;
Client.EnableSsl = true;
Client.DeliveryMethod = SmtpDeliveryMethod.Network;
string FromAddress = SmtpSettings.Username + "@" + GuessHost(SmtpSettings.SmtpServer);
using(var Message = new MailMessage(FromAddress, SmtpSettings.Target)) {
using(var Message = new MailMessage(SmtpSettings.FromEmail, SmtpSettings.Target)) {
Message.Subject = "Path of Exile Whisper Notification";
// Limit messages to around 120 characters, some phone providers don't like more.
Message.Body = StampedMessage;
Expand All @@ -238,15 +256,6 @@ public partial class Main : Form {
};
}

private string GuessHost(string SmtpHost) {
if(!SmtpHost.Contains("."))
throw new ArgumentException("Invalid SMTP server. Ex: smtp.gmail.com");
int TldStart = SmtpHost.LastIndexOf('.');
string TLD = SmtpHost.Substring(TldStart + 1);
SmtpHost = SmtpHost.Substring(0, TldStart);
return (SmtpHost.Contains(".") ? SmtpHost.Substring(SmtpHost.LastIndexOf('.') + 1) : SmtpHost) + "." + TLD;
}

private void cmdStop_Click(object sender, EventArgs e) {
StopMonitoring();
}
Expand Down Expand Up @@ -276,7 +285,7 @@ public partial class Main : Form {
/// </summary>
internal static Process GetPoeProcess() {
// This doesn't belong in Main, but oh well.
Func<Process, bool> IsPoE = (c => c.MainWindowTitle.Equals("Path of Exile", StringComparison.InvariantCultureIgnoreCase) || c.ProcessName.Contains("PathOfExile"));
Func<Process, bool> IsPoE = (c => c.MainWindowTitle.Equals("Path of Exile", StringComparison.InvariantCultureIgnoreCase) && c.ProcessName.Contains("PathOfExile"));
return Process.GetProcesses().FirstOrDefault(IsPoE);
}

Expand Down Expand Up @@ -428,6 +437,6 @@ private void tsmLogGuildMessages_Click(object sender, EventArgs e)
}

private SoundPlayer SoundPlayer = new SoundPlayer("Content\\notify.wav");
private LogMonitor Monitor;
private LogMonitor Monitor;
}
}
1 change: 1 addition & 0 deletions PoEWhisperNotifier/PoEWhisperNotifier.csproj
Expand Up @@ -78,6 +78,7 @@
<Compile Include="PushBulletDetails.cs" />
<Compile Include="Settings.cs" />
<Compile Include="SmtpDetails.cs" />
<Compile Include="WindowFlasher.cs" />
<EmbeddedResource Include="ConfigurePushBulletDialog.resx">
<DependentUpon>ConfigurePushBulletDialog.cs</DependentUpon>
</EmbeddedResource>
Expand Down
14 changes: 13 additions & 1 deletion PoEWhisperNotifier/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions PoEWhisperNotifier/Properties/Settings.settings
Expand Up @@ -44,5 +44,8 @@
<Setting Name="PreviousLocation" Type="System.Drawing.Point" Scope="User">
<Value Profile="(Default)">0, 0</Value>
</Setting>
<Setting Name="FlashTaskbar" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>

0 comments on commit b886ac0

Please sign in to comment.