/// <summary> /// Send an e-mail message to the Pebble /// </summary> /// <param name="obj"></param> /// <returns></returns> internal async Task SendEmailMessage(IAccessoryNotificationTriggerDetails obj) { try { EmailNotificationTriggerDetails _entd = obj as EmailNotificationTriggerDetails; String From = _entd.SenderName; String Subject = _entd.EmailMessage.Subject; String Body = _entd.EmailMessage.Body; if (From.Length > 255) { From = From.Substring(0, 255); } if (Subject.Length > 255) { Subject = Subject.Substring(0, 255); } if (Body.Length > 2048) { Body = Body.Substring(0, 2048); } String Details = Subject + Environment.NewLine + Environment.NewLine + Body; //Send Message await SendToastMessageToPebble(From, Details, P3bble.Constants.Icons.mail); } catch (Exception) { } }
/// <summary> /// Send the battery saver state /// </summary> /// <param name="_tntd"></param> /// <returns></returns> internal async Task SendBatterySaverMessage(IAccessoryNotificationTriggerDetails _tntd) { try { String Header = "Battery saver"; String Details = AccessoryManager.BatterySaverState ? "Enabled" : "Disabled"; await SendToastMessageToPebble(Header, Details, P3bble.Constants.Icons.lightning_bolt); } catch (Exception) { } }
/// <summary> /// Process the toast message /// </summary> /// <param name="obj"></param> /// <returns></returns> internal async Task ProcessToastMessage(IAccessoryNotificationTriggerDetails obj) { ToastNotificationTriggerDetails _tntd = obj as ToastNotificationTriggerDetails; try { switch (_tntd.AppDisplayName.ToLower()) { case "messaging": case "whatsapp": await SendTextOrChatMessage(_tntd); break; case "twitter": await SendToastMessage(_tntd, P3bble.Constants.Icons.twitter); break; case "facebook": await SendToastMessage(_tntd, P3bble.Constants.Icons.facebook); break; case "skype": await SendToastMessage(_tntd, P3bble.Constants.Icons.skype); break; default: await SendToastMessage(_tntd, P3bble.Constants.Icons.bell); break; } } catch (Exception) { } }
/// <summary> /// Process the notification trigger /// </summary> /// <param name="nextTriggerDetails"></param> /// <returns></returns> public async Task ProcessNotifications(IAccessoryNotificationTriggerDetails nextTriggerDetails) { System.Diagnostics.Debug.WriteLine(nextTriggerDetails.AppDisplayName); byte[] Cookie = new byte[4]; bool KeepConnectionAlive = false; bool Talking = false; await Connect(); while (nextTriggerDetails != null || KeepConnectionAlive) { if (nextTriggerDetails != null) { try { AccessoryNotificationType accessoryNotificationType = nextTriggerDetails.AccessoryNotificationType; System.Diagnostics.Debug.WriteLine("Notification: " + accessoryNotificationType.ToString()); switch (accessoryNotificationType) { case AccessoryNotificationType.Email: await SendEmailMessage(nextTriggerDetails); break; case AccessoryNotificationType.Toast: await ProcessToastMessage(nextTriggerDetails); break; case AccessoryNotificationType.BatterySaver: await SendBatterySaverMessage(nextTriggerDetails); break; case AccessoryNotificationType.Alarm: await SendAlarmMessage((AlarmNotificationTriggerDetails)nextTriggerDetails); break; case AccessoryNotificationType.CortanaTile: await SendCortanaMessage((CortanaTileNotificationTriggerDetails)nextTriggerDetails); break; case AccessoryNotificationType.Phone: PhoneNotificationTriggerDetails entd = (PhoneNotificationTriggerDetails)nextTriggerDetails; if (entd.PhoneNotificationType != PhoneNotificationType.LineChanged) { System.Diagnostics.Debug.WriteLine("Phone - " + entd.CallDetails.State.ToString()); switch (entd.CallDetails.State) { case PhoneCallState.Ringing: Cookie = BitConverter.GetBytes(_pc.GetNextMessageIdentifier()); await _pc.Pebble.PhoneCallAsync(entd.CallDetails.ContactName, entd.CallDetails.PhoneNumber, Cookie); KeepConnectionAlive = true; // _pc.Pebble._protocol.StartRun(); break; case PhoneCallState.Ended: await _pc.Pebble.EndCallAsync(Cookie); KeepConnectionAlive = false; break; case PhoneCallState.Talking: if (!Talking) { await _pc.Pebble.StartCallAsync(Cookie); Talking = true; } break; default: KeepConnectionAlive = false; break; } } break; default: break; } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("ProcessNotifications Exception: " + e.Message); } /*if (KeepConnectionAlive) * { * Task.Delay(500).Wait(); * * P3bble.P3bbleMessage msg = await _pc.Pebble._protocol.ReceiveMessage(0); * * if (msg != null) * { * String abc = msg.Endpoint.ToString(); * } * else * { * System.Diagnostics.Debug.WriteLine("ReceiveMessage: none"); * } * }*/ AccessoryManager.ProcessTriggerDetails(nextTriggerDetails); } nextTriggerDetails = AccessoryManager.GetNextTriggerDetails(); } if (!KeepConnectionAlive) { Disconnect(); } LastNotifications = DateTime.Now; }