private void EvaluateActivationArgs()
        {
            // Initially started?
            if (!Storage.Classes.Settings.GetSettingBoolean(SettingsConsts.INITIALLY_STARTED))
            {
                PerformInitialStartSetup();

                ROOT_FRAME.Navigate(typeof(AddAccountPage), typeof(ChatPage));
            }
            else if (ACTIVATION_ARGS is ProtocolActivatedEventArgs protocolActivationArgs)
            {
                Logger.Info("App activated by protocol activation with: " + protocolActivationArgs.Uri.ToString());

                // If we're currently not on a page, navigate to the main page:
                ROOT_FRAME.Navigate(typeof(ChatPage), UriUtils.parse(protocolActivationArgs.Uri));
            }
            else if (ACTIVATION_ARGS is ToastNotificationActivatedEventArgs toastActivationArgs)
            {
                Logger.Info("App activated by toast with: " + toastActivationArgs.Argument);
                // If empty args, no specific action (just launch the app):
                if (string.IsNullOrEmpty(toastActivationArgs.Argument))
                {
                    Logger.Warn("Toast activation with no argument!");
                    if (ROOT_FRAME.Content is null)
                    {
                        ROOT_FRAME.Navigate(typeof(ChatPage));
                    }
                    else
                    {
                        ROOT_FRAME.Navigate(typeof(ChatPage));
                    }
                }
                else
                {
                    ROOT_FRAME.Navigate(typeof(ChatPage), ToastActivationArgumentParser.ParseArguments(toastActivationArgs.Argument));
                }
                if (ROOT_FRAME.BackStack.Count == 0)
                {
                    ROOT_FRAME.BackStack.Add(new PageStackEntry(typeof(ChatPage), null, null));
                }
            }
            else if (ACTIVATION_ARGS is LaunchActivatedEventArgs launchActivationArgs)
            {
                Microsoft.AppCenter.Push.Push.CheckLaunchedFromNotification(launchActivationArgs);

                // If launched with arguments (not a normal primary tile/applist launch)
                if (launchActivationArgs.Arguments.Length > 0)
                {
                    Logger.Debug(launchActivationArgs.Arguments);
                    // TODO: Handle arguments for cases = launching from secondary Tile, so we navigate to the correct page
                    //throw new NotImplementedException();
                }

                // If we're currently not on a page, navigate to the main page
                ROOT_FRAME.Navigate(typeof(ChatPage));
            }
        }
Ejemplo n.º 2
0
        protected override async void OnBackgroundActivated(BackgroundActivatedEventArgs args)
        {
            BackgroundTaskDeferral deferral = args.TaskInstance.GetDeferral();

            switch (args.TaskInstance.Task.Name)
            {
            case BackgroundTaskHelper.TOAST_BACKGROUND_TASK_NAME:
                if (args.TaskInstance.TriggerDetails is ToastNotificationActionTriggerDetail details)
                {
                    InitLogger();

                    string   arguments = details.Argument;
                    ValueSet userInput = details.UserInput;

                    Logger.Debug("App activated in background through toast with: " + arguments);
                    AbstractToastActivation abstractToastActivation = ToastActivationArgumentParser.ParseArguments(arguments);

                    if (abstractToastActivation is null)
                    {
                        Logger.Warn("Unable to evaluate toast activation string - unknown format");
                    }
                    else if (abstractToastActivation is MarkChatAsReadToastActivation markChatAsRead)
                    {
                        ToastHelper.RemoveToastGroup(markChatAsRead.CHAT_ID.ToString());
                        DataCache.INSTANCE.MarkAllChatMessagesAsRead(markChatAsRead.CHAT_ID);
                    }
                    else if (abstractToastActivation is MarkMessageAsReadToastActivation markMessageAsRead)
                    {
                        DataCache.INSTANCE.MarkChatMessageAsRead(markMessageAsRead.CHAT_ID, markMessageAsRead.CHAT_MESSAGE_ID);
                    }
                    else if (abstractToastActivation is SendReplyToastActivation sendReply)
                    {
                        ChatModel chat;
                        using (SemaLock semaLock = DataCache.INSTANCE.NewChatSemaLock())
                        {
                            chat = DataCache.INSTANCE.GetChat(sendReply.CHAT_ID, semaLock);
                        }
                        if (chat is not null && userInput[ToastHelper.TEXT_BOX_ID] is string text)
                        {
                            string trimedText = text.Trim(UiUtils.TRIM_CHARS);
                            await SendChatMessageAsync(chat, trimedText);
                        }
                        DataCache.INSTANCE.MarkChatMessageAsRead(sendReply.CHAT_ID, sendReply.CHAT_MESSAGE_ID);
                    }

                    ToastHelper.UpdateBadgeNumber();
                }
                break;

            default:
                break;
            }

            deferral.Complete();
        }
Ejemplo n.º 3
0
        protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
        {
            var deferral = args.TaskInstance.GetDeferral();

            switch (args.TaskInstance.Task.Name)
            {
            case BackgroundTaskHelper.TOAST_BACKGROUND_TASK_NAME:
                ToastNotificationActionTriggerDetail details = args.TaskInstance.TriggerDetails as ToastNotificationActionTriggerDetail;
                if (details != null)
                {
                    initLogLevel();

                    string arguments = details.Argument;
                    var    userInput = details.UserInput;

                    Logger.Debug("App activated in background through toast with: " + arguments);
                    AbstractToastActivation abstractToastActivation = ToastActivationArgumentParser.parseArguments(arguments);

                    if (abstractToastActivation is MarkChatAsReadToastActivation markChatAsRead)
                    {
                        ToastHelper.removeToastGroup(markChatAsRead.CHAT_ID);
                        ChatDBManager.INSTANCE.markAllMessagesAsRead(markChatAsRead.CHAT_ID);
                    }
                    else if (abstractToastActivation is MarkMessageAsReadToastActivation markMessageAsRead)
                    {
                        ChatDBManager.INSTANCE.markMessageAsRead(markMessageAsRead.CHAT_MESSAGE_ID);
                    }
                    else if (abstractToastActivation is SendReplyToastActivation sendReply)
                    {
                        ChatTable chat = ChatDBManager.INSTANCE.getChat(sendReply.CHAT_ID);
                        if (chat != null && userInput[ToastHelper.TEXT_BOX_ID] != null)
                        {
                            if (isRunning)
                            {
                            }
                            else
                            {
                            }
                        }
                    }
                }
                break;
            }

            deferral.Complete();
        }
Ejemplo n.º 4
0
        private async Task onActivatedOrLaunchedAsync(IActivatedEventArgs args)
        {
            // Sets the log level:
            initLogLevel();

            // Register background tasks:
            Logger.Info("Registering background tasks...");
            await BackgroundTaskHelper.registerToastBackgroundTaskAsync();

            Logger.Info("Finished registering background tasks.");

            // Init all db managers to force event subscriptions:
            initAllDBManagers();

            // Set default background:
            if (!Settings.getSettingBoolean(SettingsConsts.INITIALLY_STARTED))
            {
                Settings.setSetting(SettingsConsts.CHAT_EXAMPLE_BACKGROUND_IMAGE_NAME, "light_bulb.jpeg");
            }
            // Loads all background images into the cache:
            BackgroundImageCache.loadCache();

            // Setup push server connection:
            if (!Settings.getSettingBoolean(SettingsConsts.DISABLE_PUSH))
            {
                Push_App_Server.Classes.PushManager.init();
            }

            isRunning = true;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (!(Window.Current.Content is Frame rootFrame))
            {
                // Create a Frame to act as the navigation context and navigate to the first page:
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (args is ToastNotificationActivatedEventArgs)
            {
                var toastActivationArgs = args as ToastNotificationActivatedEventArgs;
                Logger.Info("App activated by toast with: " + toastActivationArgs.Argument);
                // If empty args, no specific action (just launch the app)
                if (string.IsNullOrEmpty(toastActivationArgs.Argument))
                {
                    if (rootFrame.Content == null)
                    {
                        if (!Settings.getSettingBoolean(SettingsConsts.INITIALLY_STARTED))
                        {
                            rootFrame.Navigate(typeof(AddAccountPage), "App.xaml.cs");
                        }
                        else
                        {
                            rootFrame.Navigate(typeof(ChatPage), "App.xaml.cs");
                        }
                    }
                }
                else
                {
                    rootFrame.Navigate(typeof(ChatPage), ToastActivationArgumentParser.parseArguments(toastActivationArgs.Argument));
                }
                if (rootFrame.BackStack.Count == 0)
                {
                    rootFrame.BackStack.Add(new PageStackEntry(typeof(ChatPage), null, null));
                }
            }
            else if (args is LaunchActivatedEventArgs)
            {
                var launchActivationArgs = args as LaunchActivatedEventArgs;

                Push.CheckLaunchedFromNotification(launchActivationArgs);

                // If launched with arguments (not a normal primary tile/applist launch)
                if (launchActivationArgs.Arguments.Length > 0)
                {
                    Logger.Debug(launchActivationArgs.Arguments);
                    // TODO: Handle arguments for cases = launching from secondary Tile, so we navigate to the correct page
                    //throw new NotImplementedException();
                }

                // If we're currently not on a page, navigate to the main page
                if (rootFrame.Content == null)
                {
                    if (!Settings.getSettingBoolean(SettingsConsts.INITIALLY_STARTED))
                    {
                        rootFrame.Navigate(typeof(AddAccountPage), "App.xaml.cs");
                    }
                    else
                    {
                        rootFrame.Navigate(typeof(ChatPage), "App.xaml.cs");
                    }
                }
            }

            // Set requested theme:
            string       themeString = Settings.getSettingString(SettingsConsts.APP_REQUESTED_THEME);
            ElementTheme theme       = ElementTheme.Dark;

            if (themeString != null)
            {
                bool b = Enum.TryParse(themeString, out theme);
            }
            RootTheme = theme;

            Window.Current.Activate();

            // Connect to all clients:
            ConnectionHandler.INSTANCE.connectAll();
        }