public MainWindow()
        {
            InitializeComponent();
            var p = ConsoleTextBox.Document.Blocks.FirstBlock as Paragraph;

            ConsoleTextBox.Document.Blocks.Clear();
            config = new ConfigurationBuilder <IAppSettings>()
                     .UseJsonFile(Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                            "\\AmongUsCapture\\AmongUsGUI", "Settings.json")).Build();
            context                 = new UserDataContext(DialogCoordinator.Instance, config);
            DataContext             = context;
            config.PropertyChanged += ConfigOnPropertyChanged;

            GameMemReader.getInstance().GameStateChanged += GameStateChangedHandler;
            GameMemReader.getInstance().PlayerChanged    += UserForm_PlayerChanged;
            GameMemReader.getInstance().ChatMessageAdded += OnChatMessageAdded;
            GameMemReader.getInstance().JoinedLobby      += OnJoinedLobby;
            IPCadapter.getInstance().OnToken             += (sender, token) => {
                this.BeginInvoke((w) =>
                {
                    if (!w.IsVisible)
                    {
                        w.Show();
                    }

                    if (w.WindowState == WindowState.Minimized)
                    {
                        w.WindowState = WindowState.Normal;
                    }

                    w.Activate();
                    w.Topmost = true;  // important
                    w.Topmost = false; // important
                    w.Focus();         // important

                    w.Activate();
                });
            };
            //ApplyDarkMode();
        }
Exemple #2
0
 private void SubmitConnectButton_OnClick(object sender, RoutedEventArgs e)
 {
     IPCadapter.getInstance().SendToken(config.host, config.connectCode);
     ManualConnectionFlyout.IsOpen = false;
 }
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            var args = e.Args;

            ThemeManager.Current.ThemeSyncMode = ThemeSyncMode.SyncAll;
            ThemeManager.Current.SyncTheme();
            // needs to be the first call in the program to prevent weird bugs
            if (Settings.PersistentSettings.debugConsole)
            {
                AllocConsole();
            }

            var uriStart = IPCadapter.getInstance().HandleURIStart(e.Args);

            switch (uriStart)
            {
            case URIStartResult.CLOSE:
                Environment.Exit(0);
                break;

            case URIStartResult.PARSE:
                Console.WriteLine($"Starting with args : {e.Args[0]}");
                break;

            case URIStartResult.CONTINUE:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var splashScreen = new SplashScreenWindow();

            this.MainWindow = splashScreen;
            splashScreen.Show();
            Task.Factory.StartNew(() =>
            {
                //simulate some work being done
                //System.Threading.Thread.Sleep(3000);

                //since we're not on the UI thread
                //once we're done we need to use the Dispatcher
                //to create and show the main window
                this.Dispatcher.Invoke(() =>
                {
                    //initialize the main window, set it as the application main window
                    //and close the splash screen
                    var mainWindow  = new MainWindow();
                    this.MainWindow = mainWindow;
                    AmongUsCapture.Settings.form         = mainWindow;
                    AmongUsCapture.Settings.conInterface = new FormConsole(mainWindow);
                    Program.Main();
                    mainWindow.Loaded += (sender, args2) =>
                    {
                        if (uriStart == URIStartResult.PARSE)
                        {
                            IPCadapter.getInstance().SendToken(args[0]);
                        }
                    };
                    mainWindow.Closing += (sender, args2) =>
                    {
                        Environment.Exit(0);
                    };
                    mainWindow.Show();
                    splashScreen.Close();
                });
            });
        }