Example #1
0
        public async Task <bool> StartupAsync()
        {
            var splash = new SplashScreen();

            splash.Show();

            _vm = new MainViewModel()
            {
                AddDropCommand    = new RelayCommand(() => _vm.DiscordDrops.Insert(0, new DiscordDropViewModel())),
                RemoveDropCommand = new RelayCommand <DiscordDropViewModel>(drop => _vm.DiscordDrops.Remove(drop))
            };
            HotkeyManager.HotkeyFired += OnHotkeyFired;

            splash.DisplayTask(LoadingTask.LoadingSettings);
            _settings = await Task.Factory.StartNew(_serializer.Deserialize) ?? new Settings();

            splash.DisplayTask(LoadingTask.RegisteringHotkeys);
            if (_settings?.DiscordDrops != null)
            {
                foreach (var drop in _settings.DiscordDrops)
                {
                    if (HotkeyManager.Register(drop.HotKey, drop.Modifier, out int id))
                    {
                        drop.HotkeyId = id;
                        _vm.DiscordDrops.Add(drop);
                    }
                }
            }

            splash.DisplayTask(LoadingTask.LaunchingSelfBot);
            _discordWrapper        = new DiscordWrapper(_settings.TargetChannelId);
            _dropLimiter.FireDrop += (_, drop) => _discordWrapper.FireDrop(drop);
            if (!await _discordWrapper.LoginAsync(_settings, splash))
            {
                return(false);
            }

            splash.DisplayTask(LoadingTask.LoadingTaskbarIcon);
            _taskBarIcon = new TaskbarIcon(ShowHotkeyWindow);
            _taskBarIcon.Show();

            splash.Close();
            return(true);
        }