コード例 #1
0
        private static async Task InitAsync(TrayIcon icon)
        {
            var deviceActiveLister          = new CachedAudioDeviceLister(DeviceState.Active);
            var deviceUnpluggedActiveLister = new CachedAudioDeviceLister(DeviceState.Active | DeviceState.Unplugged);
            await Task.WhenAll(deviceActiveLister.Refresh(), deviceUnpluggedActiveLister.Refresh());

            AppModel.Instance.ActiveAudioDeviceLister    = deviceActiveLister;
            AppModel.Instance.ActiveUnpluggedAudioLister = deviceUnpluggedActiveLister;

            AppModel.Instance.TrayIcon = icon;
            AppModel.Instance.InitializeMain();
            AppModel.Instance.NewVersionReleased += (sender, @event) =>
            {
                if (@event.UpdateMode == UpdateMode.Silent)
                {
                    new AutoUpdater("/VERYSILENT /NOCANCEL /NORESTART", ApplicationPath.Default).Update(
                        @event.Release, true);
                }
            };


            if (AppConfigs.Configuration.FirstRun)
            {
                icon.ShowSettings();
                AppConfigs.Configuration.FirstRun = false;
                Log.Information("First run");
            }
        }
コード例 #2
0
ファイル: Settings.cs プロジェクト: user135711/SoundSwitch
        public async Task AsyncInit()
        {
            // Playback and Recording
            _audioDeviceLister = new CachedAudioDeviceLister(DeviceState.All);
            await _audioDeviceLister.Refresh();

            PopulateAudioDevices();

            // Profiles
            PopulateProfiles();

            _loaded = true;
        }
コード例 #3
0
ファイル: Settings.cs プロジェクト: youyeyuki/SoundSwitch
        public SettingsForm()
        {
            // Form itself
            InitializeComponent();
            Icon = RessourceSettingsIcon;
            Text = AssemblyUtils.GetReleaseState() == AssemblyUtils.ReleaseState.Beta
                ? $"{SettingsStrings.settings} {AssemblyUtils.GetReleaseState()}"
                : SettingsStrings.settings;
            LocalizeForm();

            var closeToolTip = new ToolTip();

            closeToolTip.SetToolTip(closeButton, SettingsStrings.closeTooltip);

            hotkeysTextBox.Text = AppConfigs.Configuration.PlaybackHotKeys.Display();
            hotkeysTextBox.Tag  =
                new Tuple <DataFlow, HotKeys>(DataFlow.Render, AppConfigs.Configuration.PlaybackHotKeys);
            hotkeysTextBox.Enabled  = hotkeysCheckBox.Checked = AppConfigs.Configuration.PlaybackHotKeys.Enabled;
            hotkeysTextBox.KeyDown += (sender, args) => SetHotkey(args);
            var hotkeysToolTip = new ToolTip();

            hotkeysToolTip.SetToolTip(hotkeysCheckBox, SettingsStrings.hotkeysTooltip);

            // Settings - Basic
            startWithWindowsCheckBox.Checked   = AppModel.Instance.RunAtStartup;
            keepSystemTrayIconCheckBox.Checked = AppConfigs.Configuration.KeepSystrayIcon;

            var keepSystemTrayIconToolTip = new ToolTip();

            keepSystemTrayIconToolTip.SetToolTip(keepSystemTrayIconCheckBox, SettingsStrings.keepSystemTrayIconTooltip);

            // Settings - Audio
            switchCommunicationDeviceCheckBox.Checked = AppModel.Instance.SetCommunications;


            var switchCommunicationsDeviceToolTip = new ToolTip();

            switchCommunicationsDeviceToolTip.SetToolTip(switchCommunicationDeviceCheckBox,
                                                         SettingsStrings.communicationsDeviceTooltip);

            var notificationToolTip = new ToolTip();

            notificationToolTip.SetToolTip(notificationComboBox, SettingsStrings.notificationTooltip);

            var notificationFactory = new NotificationFactory();

            notificationFactory.ConfigureListControl(notificationComboBox);
            notificationComboBox.SelectedValue = AppModel.Instance.NotificationSettings;

            selectSoundFileDialog.Filter          = SettingsStrings.audioFiles + @" (*.wav;*.mp3)|*.wav;*.mp3;*.aiff";
            selectSoundFileDialog.FileOk         += SelectSoundFileDialogOnFileOk;
            selectSoundFileDialog.CheckFileExists = true;
            selectSoundFileDialog.CheckPathExists = true;

            var soundSupported = notificationFactory.Get(AppModel.Instance.NotificationSettings).SupportCustomSound() !=
                                 NotificationCustomSoundEnum.NotSupported;

            selectSoundButton.Visible = soundSupported;

            var removeCustomSoundToolTip = new ToolTip();

            removeCustomSoundToolTip.SetToolTip(deleteSoundButton, SettingsStrings.disableCustomSoundTooltip);
            try
            {
                deleteSoundButton.Visible = soundSupported && AppModel.Instance.CustomNotificationSound != null;
            }
            catch (CachedSoundFileNotExistsException)
            {
            }

            var selectSoundButtonToolTip = new ToolTip();

            selectSoundButtonToolTip.SetToolTip(selectSoundButton, SettingsStrings.selectSoundButtonTooltip);

            new TooltipInfoFactory().ConfigureListControl(tooltipInfoComboBox);
            tooltipInfoComboBox.SelectedValue = TooltipInfoManager.CurrentTooltipInfo;

            new DeviceCyclerFactory().ConfigureListControl(cycleThroughComboBox);
            cycleThroughComboBox.SelectedValue = DeviceCyclerManager.CurrentCycler;

            var cycleThroughToolTip = new ToolTip();

            cycleThroughToolTip.SetToolTip(cycleThroughComboBox, SettingsStrings.cycleThroughTooltip);

            foregroundAppCheckbox.Checked = AppModel.Instance.SwitchForegroundProgram;

            var foregroundAppToolTip = new ToolTip();

            foregroundAppToolTip.SetToolTip(foregroundAppCheckbox, SettingsStrings.foregroundAppTooltip);

            // Settings - Update
            includeBetaVersionsCheckBox.Checked = AppModel.Instance.IncludeBetaVersions;

            switch (AppModel.Instance.UpdateMode)
            {
            case UpdateMode.Silent:
                updateSilentRadioButton.Checked = true;
                break;

            case UpdateMode.Notify:
                updateNotifyRadioButton.Checked = true;
                break;

            case UpdateMode.Never:
                updateNeverRadioButton.Checked = true;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var updateSilentToolTip = new ToolTip();

            updateSilentToolTip.SetToolTip(updateSilentRadioButton, SettingsStrings.updateInstallAutomaticallyTooltip);
            var updateNotifyToolTip = new ToolTip();

            updateNotifyToolTip.SetToolTip(updateNotifyRadioButton, SettingsStrings.updateNotifyTooltip);
            var updateNeverToolTip = new ToolTip();

            updateNeverToolTip.SetToolTip(updateNeverRadioButton, SettingsStrings.updateNeverTooltip);

            var includeBetaVersionsToolTip = new ToolTip();

            includeBetaVersionsToolTip.SetToolTip(includeBetaVersionsCheckBox,
                                                  SettingsStrings.updateIncludeBetaVersionsTooltip);

            // Settings - Language
            languageComboBox.Items.AddRange(Enum.GetNames(typeof(Language)));
            languageComboBox.SelectedIndex = (int)AppConfigs.Configuration.Language;

            // Playback and Recording
            using (var audioDeviceLister = new CachedAudioDeviceLister(DeviceState.All))
            {
                PopulateAudioList(playbackListView, AppModel.Instance.SelectedDevices,
                                  audioDeviceLister.PlaybackDevices);
                PopulateAudioList(recordingListView, AppModel.Instance.SelectedDevices,
                                  audioDeviceLister.RecordingDevices);
            }

            _loaded = true;
        }
コード例 #4
0
        private static void Main()
        {
            bool createdNew;

            InitializeLogger();
            Log.Information("Application Starts");
            using (var audioDeviceLister = new CachedAudioDeviceLister(DeviceState.Active))
            {
                var recordingDevices = audioDeviceLister.RecordingDevices;
                Log.Information("Devices Recording {device}", recordingDevices);
                var playbackDevices = audioDeviceLister.PlaybackDevices;

                Log.Information("Devices Playback {device}", playbackDevices);
            }
#if !DEBUG
            AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
            {
                HandleException((Exception)args.ExceptionObject);
            };

            Log.Information("Set Exception Handler");
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
            WindowsAPIAdapter.Start(Application_ThreadException);
#else
            WindowsAPIAdapter.Start();
#endif
            Thread.CurrentThread.CurrentUICulture = LanguageParser.ParseLanguage(AppModel.Instance.Language);

            using (new Mutex(true, Application.ProductName, out createdNew))
            {
                if (!createdNew)
                {
                    Log.Warning("Application already started");
                    using (var client = new IPCClient(AppConfigs.IPCConfiguration.ClientUrl()))
                    {
                        try
                        {
                            var service = client.GetService();
                            service.StopApplication();
                            RestartApp();
                            return;
                        }
                        catch (RemotingException e)
                        {
                            Log.Error(e, "Unable to stop another running application");
                            Application.Exit();
                            return;
                        }
                    }
                }

                AppModel.Instance.ActiveAudioDeviceLister = new CachedAudioDeviceLister(DeviceState.Active);

                // Windows Vista or newer.
                if (Environment.OSVersion.Version.Major >= 6)
                {
                    SetProcessDPIAware();
                }

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                // Manage the Closing events send by Windows
                // Since this app don't use a Form as "main window" the app doesn't close
                // when it should without this.
                WindowsAPIAdapter.RestartManagerTriggered += (sender, @event) =>
                {
                    Log.Debug("Restart Event received: {Event}", @event);
                    switch (@event.Type)
                    {
                    case WindowsAPIAdapter.RestartManagerEventType.Query:
                        @event.Result = new IntPtr(1);

                        break;

                    case WindowsAPIAdapter.RestartManagerEventType.EndSession:
                    case WindowsAPIAdapter.RestartManagerEventType.ForceClose:
                        Log.Debug("Close Application");
                        Application.Exit();
                        break;
                    }
                };

                Log.Information("Set Tray Icon with Main");
#if !DEBUG
                try
                {
#endif
                MMNotificationClient.Instance.Register();
                using (var ipcServer = new IPCServer(AppConfigs.IPCConfiguration.ServerUrl()))
                    using (var icon = new TrayIcon())
                    {
                        var available = false;
                        while (!available)
                        {
                            try
                            {
                                ipcServer.InitServer();
                                available = true;
                            }
                            catch (RemotingException)
                            {
                                Thread.Sleep(250);
                            }
                        }

                        AppModel.Instance.TrayIcon = icon;
                        AppModel.Instance.InitializeMain();
                        AppModel.Instance.NewVersionReleased += (sender, @event) =>
                        {
                            if (@event.UpdateMode == UpdateMode.Silent)
                            {
                                new AutoUpdater("/VERYSILENT /NOCANCEL /NORESTART", ApplicationPath.Default).Update(
                                    @event.Release, true);
                            }
                        };
                        if (AppConfigs.Configuration.FirstRun)
                        {
                            icon.ShowSettings();
                            AppConfigs.Configuration.FirstRun = false;
                            Log.Information("First run");
                        }

                        Application.Run();
                    }
#if !DEBUG
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
#endif
            }

            AppModel.Instance.ActiveAudioDeviceLister.Dispose();
            MMNotificationClient.Instance.UnRegister();
            WindowsAPIAdapter.Stop();
            Log.CloseAndFlush();
        }