Skip to content

Commit efc1946

Browse files
♻️ move ringtone to notification class
1 parent c2d73ad commit efc1946

File tree

2 files changed

+40
-25
lines changed

2 files changed

+40
-25
lines changed

code/Inbox.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5-
using System.Media;
65
using System.Net;
76
using System.Text.RegularExpressions;
87
using System.Threading.Tasks;
@@ -141,11 +140,6 @@ public async Task Sync(bool manual = true, bool token = false) {
141140
// manage unread spams
142141
if (UnreadSpams > 0) {
143142

144-
// play a sound on unread spams
145-
if (Settings.Default.AudioNotification) {
146-
SystemSounds.Exclamation.Play();
147-
}
148-
149143
// display a balloon tip in the systray with the total of unread threads
150144
UI.NotificationService.Tip($"{UnreadSpams} {(UnreadSpams > 1 ? Translation.unreadSpams : Translation.unreadSpam)}", Translation.newUnreadSpam, Notification.Type.Error);
151145

@@ -184,25 +178,6 @@ public async Task Sync(bool manual = true, bool token = false) {
184178
// manage message notification
185179
if (Settings.Default.MessageNotification) {
186180

187-
// play a sound on unread threads
188-
if (Settings.Default.AudioNotification) {
189-
190-
// play a ringtone based on user setting
191-
if (Settings.Default.Ringtone) {
192-
193-
// switch to the default ringtone if the audio file can't be found
194-
if (File.Exists(Settings.Default.RingtoneFile)) {
195-
using (SoundPlayer player = new SoundPlayer(Settings.Default.RingtoneFile)) {
196-
player.Play();
197-
}
198-
} else {
199-
Settings.Default.Ringtone = false;
200-
}
201-
} else {
202-
SystemSounds.Asterisk.Play();
203-
}
204-
}
205-
206181
// get the message details
207182
UsersResource.MessagesResource.ListRequest messages = User.Messages.List("me");
208183
messages.LabelIds = "UNREAD";

code/Notification.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
22
using System.Diagnostics;
3+
using System.IO;
4+
using System.Media;
35
using System.Threading.Tasks;
46
using System.Windows.Forms;
57
using notifier.Languages;
@@ -65,6 +67,9 @@ public Notification(ref Main form) {
6567
/// <param name="duration">How long the notification is displayed</param>
6668
public void Tip(string title, string text, Type icon = Type.Info, int duration = 450) {
6769
UI.notifyIcon.ShowBalloonTip(duration, title, text, (ToolTipIcon)icon);
70+
71+
// play audio based on balloon type
72+
Ringtone(icon);
6873
}
6974

7075
/// <summary>
@@ -238,6 +243,41 @@ public void Reset() {
238243
UI.menuItemMarkAsRead.Enabled = false;
239244
}
240245

246+
/// <summary>
247+
/// Play ringtone based on displayed notification
248+
/// </summary>
249+
/// <param name="type"></param>
250+
private void Ringtone(Type type = Type.Info) {
251+
if (!Settings.Default.AudioNotification) {
252+
return;
253+
}
254+
255+
//
256+
switch (type) {
257+
case Type.Info:
258+
259+
// play a ringtone based on user setting
260+
if (Settings.Default.Ringtone) {
261+
262+
// switch to the default ringtone if the audio file can't be found
263+
if (File.Exists(Settings.Default.RingtoneFile)) {
264+
using (SoundPlayer player = new SoundPlayer(Settings.Default.RingtoneFile)) {
265+
player.Play();
266+
}
267+
} else {
268+
Settings.Default.Ringtone = false;
269+
}
270+
} else {
271+
SystemSounds.Asterisk.Play();
272+
}
273+
274+
break;
275+
case Type.Error:
276+
SystemSounds.Exclamation.Play();
277+
break;
278+
}
279+
}
280+
241281
/// <summary>
242282
/// Return the Gmail base URL depending on the notification behavior
243283
/// </summary>

0 commit comments

Comments
 (0)