Exemplo n.º 1
0
        public Program(string settingsPath)
        {
            settings = new SettingsContainer(settingsPath ?? Path.Combine(
                                                 Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                                 "EtherSound", "Settings.json"));
            viewModel = new RootModel(settings.Settings);
            sessions  = new SessionManager(settings.Settings);
            wsServer  = new Server(viewModel, sessions, settings.Settings.WebSocketEndpoint);
            ready     = false;

            SetTimer(out saveTimer, 3000, delegate { if (ready && suspendSaving == 0)
                                                     {
                                                         viewModel.UpdateSettings(); settings.Save();
                                                     }
                     });
            SetTimer(out cursorTimer, 1000, delegate { viewModel.UpdateCursor(); });
            SetTimer(out pollTimer, 5, delegate { viewModel.Poll(); });

            tapThread = new Thread(RunTapThread)
            {
                IsBackground = true
            };
            tapThread.Start();

            trayIcon = new TrayIcon(viewModel);

            viewModel.PropertyChanged     += ModelPropertyChanged;
            trayIcon.VolumeControlClicked += delegate { OpenVolumeControlWindow(); };
            trayIcon.SettingsClicked      += delegate { OpenSettingsWindow(); };
            trayIcon.ResetClicked         += async delegate { await sessions.RefreshDevices().ConfigureAwait(true); sessions.RestartAll(); };
        }