From 4d4d08710a7fb063908b361a19a5c4f62ca8c5c1 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Wed, 10 Sep 2014 21:07:58 +0400 Subject: [PATCH] Vibration basic support --- app/js/controllers.js | 15 ++++++++++++++- app/js/services.js | 17 +++++++++++++++-- app/partials/mobile/settings_modal.html | 7 +++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/app/js/controllers.js b/app/js/controllers.js index 89dc8424..9a6e37f9 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -1963,7 +1963,7 @@ angular.module('myApp.controllers', []) }); }; - Storage.get('notify_nodesktop', 'notify_nosound', 'send_ctrlenter', 'notify_volume').then(function (settings) { + Storage.get('notify_nodesktop', 'notify_nosound', 'send_ctrlenter', 'notify_volume', 'notify_novibrate').then(function (settings) { $scope.notify.desktop = !settings[0]; $scope.send.enter = settings[2] ? '' : '1'; @@ -1975,6 +1975,9 @@ angular.module('myApp.controllers', []) $scope.notify.volume = 5; } + $scope.notify.canVibrate = NotificationsManager.getVibrateSupport(); + $scope.notify.vibrate = !settings[4]; + $scope.notify.volumeOf4 = function () { return 1 + Math.ceil(($scope.notify.volume - 1) / 3.3); }; @@ -2014,6 +2017,16 @@ angular.module('myApp.controllers', []) } } + $scope.toggleVibrate = function () { + $scope.notify.vibrate = !$scope.notify.vibrate; + + if ($scope.notify.vibrate) { + Storage.remove('notify_novibrate'); + } else { + Storage.set({notify_novibrate: true}); + } + } + $scope.toggleCtrlEnter = function (newValue) { $scope.send.enter = newValue; diff --git a/app/js/services.js b/app/js/services.js index 18af8424..e0445435 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -3400,10 +3400,13 @@ angular.module('myApp.services', []) .service('NotificationsManager', function ($rootScope, $window, $timeout, $interval, $q, MtpApiManager, AppPeersManager, IdleManager, Storage) { + navigator.vibrate = navigator.vibrate || navigator.mozVibrate || navigator.webkitVibrate; + var notificationsUiSupport = ('Notification' in window) || ('mozNotification' in navigator); var notificationsShown = {}; var notificationIndex = 0; var notificationsCount = 0; + var vibrateSupport = !!navigator.vibrate; var peerSettings = {}; var faviconBackupEl = $('link[rel="icon"]'), faviconNewEl = $(''); @@ -3476,6 +3479,7 @@ angular.module('myApp.services', []) getPeerMuted: getPeerMuted, savePeerSettings: savePeerSettings, updatePeerSettings: updatePeerSettings, + getVibrateSupport: getVibrateSupport, testSound: playSound }; @@ -3561,8 +3565,13 @@ angular.module('myApp.services', []) } }) - Storage.get('notify_nodesktop').then(function (noShow) { - if (noShow) { + + Storage.get('notify_nodesktop', 'notify_novibrate').then(function (settings) { + if (settings[0]) { + if (vibrateSupport && !settings[1]) { + navigator.vibrate([200, 100, 200]); + return; + } return; } var idx = ++notificationIndex, @@ -3694,6 +3703,10 @@ angular.module('myApp.services', []) }) } + function getVibrateSupport () { + return vibrateSupport; + } + }) diff --git a/app/partials/mobile/settings_modal.html b/app/partials/mobile/settings_modal.html index 282d4ea4..3771f4a6 100644 --- a/app/partials/mobile/settings_modal.html +++ b/app/partials/mobile/settings_modal.html @@ -79,6 +79,13 @@ +
+ + + Vibrate + +
+