Esempio n. 1
0
        private void OnNameChange(ServiceOwnerChangedEventArgs obj)
        {
            if (_isDisposed)
            {
                return;
            }

            if (!_serviceConnected & obj.NewOwner != null)
            {
                _serviceConnected = true;
                InitializeSNWService();

                DestroyTrayIcon();

                if (_isVisible)
                {
                    CreateTrayIcon();
                }
            }
            else if (_serviceConnected & obj.NewOwner is null)
            {
                DestroyTrayIcon();
                _serviceConnected = false;
            }
        }
        private async void OnNameChange(ServiceOwnerChangedEventArgs args)
        {
            if (args.NewOwner != null && _currentName == null)
            {
                _onlineNamesQueue.Enqueue(args.ServiceName);
                if (!_connecting)
                {
                    _connecting = true;
                    try
                    {
                        while (_onlineNamesQueue.Count > 0)
                        {
                            var name = _onlineNamesQueue.Dequeue();
                            try
                            {
                                if (await Connect(name))
                                {
                                    _onlineNamesQueue.Clear();
                                    _currentName = name;
                                    return;
                                }
                            }
                            catch (Exception e)
                            {
                                Logger.TryGet(LogEventLevel.Error, "IME")
                                ?.Log(this, "Unable to create IME input context:\n" + e);
                            }
                        }
                    }
                    finally
                    {
                        _connecting = false;
                    }
                }
            }

            // IME has crashed
            if (args.NewOwner == null && args.ServiceName == _currentName)
            {
                _currentName = null;
                foreach (var s in _disposables)
                {
                    s.Dispose();
                }
                _disposables.Clear();

                OnDisconnected();
                Reset();

                // Watch again
                Watch();
            }
        }