コード例 #1
0
        private async void NotificationPatternSaveButton_OnClick(object sender, RoutedEventArgs args)
        {
            var playerId = OneSignal.GetPlayerId();

            if (playerId == null)
            {
                await App.ShowMessage("Device token is not available.");

                return;
            }

            SetNotificationFormEnabled(false);

            try
            {
                await SaveNotificationPattern(playerId, NotificationPatternText.Text);
            }
            catch (Exception e)
            {
                await App.ShowMessage("Failed to save RohBot subscription.");

                Debug.WriteLine($"Failed to save notification regex: {e}");
            }

            SetNotificationFormEnabled(true);
        }
コード例 #2
0
        private async void LogoutButton_OnClick(object sender, RoutedEventArgs args)
        {
            LogoutButton.IsEnabled = false;

            var playerId = OneSignal.GetPlayerId();

            if (Settings.NotificationsEnabled.Value && playerId != null)
            {
                try
                {
                    await OneSignal.SetSubscriptionAsync(false);

                    await Client.Instance.SendAsync(new NotificationUnsubscriptionRequest(playerId));
                }
                catch (Exception e)
                {
                    Debug.WriteLine($"Failed to unsubscribe on logout: {e}");
                }
            }

            Settings.LoggedIn.Value = false;
            Settings.Username.Value = null;
            Settings.Token.Value    = null;

            Settings.NotificationsEnabled.Value = false;
            Settings.NotificationPattern.Value  = "";

            Client.Instance.Connection.Disconnect();

            var rootFrame = (Frame)Window.Current.Content;

            rootFrame.Navigate(typeof(LoginPage));
        }
コード例 #3
0
        private async void NotificationToggleSwitch_OnToggled(object sender, RoutedEventArgs args)
        {
            if (_settingNotificationToggleSwitch)
            {
                _settingNotificationToggleSwitch = false;
                return;
            }

            var enabled = NotificationToggleSwitch.IsOn;

            try
            {
                var playerId = OneSignal.GetPlayerId();
                if (playerId == null)
                {
                    await App.ShowMessage("Device token is not available.");

                    return;
                }

                if (string.IsNullOrEmpty(NotificationPatternText.Text))
                {
                    NotificationPatternText.Text = Client.Instance.Name;
                }

                NotificationToggleSwitch.IsEnabled = false;

                try
                {
                    await OneSignal.SetSubscriptionAsync(enabled);
                }
                catch
                {
                    await App.ShowMessage("Failed to toggle OneSignal subscription.");

                    throw;
                }

                try
                {
                    if (enabled)
                    {
                        await SaveNotificationPattern(playerId, NotificationPatternText.Text);
                    }
                    else
                    {
                        /* TODO:
                         * unsubscribe causes a sysMessage error if we toggle within a few seconds
                         * skipping this should be fine because onesignal won't push to us, and
                         * rohbot will auto unsubscribe!
                         */
                        //await Client.Instance.SendAsync(new NotificationUnsubscriptionRequest(playerId));
                    }
                }
                catch
                {
                    await App.ShowMessage("Failed to toggle RohBot subscription.");

                    throw;
                }

                Settings.NotificationsEnabled.Value = enabled;
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Failed to toggle notifications: {e}");

                _settingNotificationToggleSwitch = true;
                NotificationToggleSwitch.IsOn    = !enabled;
            }

            NotificationToggleSwitch.IsEnabled = true;
        }