예제 #1
0
        private void DoAppStartup()
        {
            ((Manager)Resources["ThemeManager"]).Load();

            _mixerWindow    = new WindowHolder(CreateMixerExperience);
            _settingsWindow = new WindowHolder(CreateSettingsExperience);

            PlaybackDevicesViewModel        = new DeviceCollectionViewModel(WindowsAudioFactory.Create(AudioDeviceKind.Playback));
            PlaybackDevicesViewModel.Ready += OnMainViewModelReady;

            FlyoutViewModel = new FlyoutViewModel(PlaybackDevicesViewModel);
            FlyoutWindow    = new FlyoutWindow(FlyoutViewModel);

            TrayViewModel              = new TrayViewModel(PlaybackDevicesViewModel);
            TrayViewModel.LeftClick    = new RelayCommand(() => FlyoutViewModel.OpenFlyout(FlyoutShowOptions.Pointer));
            TrayViewModel.OpenMixer    = new RelayCommand(_mixerWindow.OpenOrBringToFront);
            TrayViewModel.OpenSettings = new RelayCommand(_settingsWindow.OpenOrBringToFront);
            FlyoutWindow.DpiChanged   += (_, __) => TrayViewModel.Refresh();

            _trayIcon = new TrayIcon(TrayViewModel);

            SettingsService.RegisterHotkeys();
            HotkeyManager.Current.KeyPressed += OnHotKeyPressed;

            MaybeShowFirstRunExperience();
        }
예제 #2
0
        private static void DebugAddMockDevice()
        {
            var id               = Guid.NewGuid().ToString();
            var devManager       = WindowsAudioFactory.Create(AudioDeviceKind.Playback);
            var devManagerNotify = (Interop.MMDeviceAPI.IMMNotificationClient)devManager;

            var mockDevice = new DataModel.Audio.Mocks.AudioDevice(id, devManager);

            AddMockApp(mockDevice,
                       "System Sounds",
                       "*SystemSounds",
                       AppInformationFactory.CreateForProcess(0).SmallLogoPath);
            AddMockApp(mockDevice,
                       "Firefaux",
                       "Firefaux",
                       @"%ProgramFiles%\Mozilla Firefox\firefox.exe");
            AddMockApp(mockDevice,
                       "Chr0me",
                       "Chr0me",
                       @"%ProgramFilesx86%\Google\Chrome\Application\chrome.exe");

            var addInfo = devManager.GetType().GetMethod("Add", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);

            addInfo.Invoke(devManager, new object[] { mockDevice });
        }
예제 #3
0
        public static void DumpAndShowData()
        {
            var allText = DumpDevices(WindowsAudioFactory.Create(AudioDeviceKind.Playback));

            allText += DumpDevices(WindowsAudioFactory.Create(AudioDeviceKind.Recording));
            allText += Environment.NewLine;
            allText += $"App: {App.Current.GetVersion()}" + Environment.NewLine;
            allText += $"HasIdentity: {App.Current.HasIdentity()}" + Environment.NewLine;
            allText += $"CurrentCulture: {CultureInfo.CurrentCulture.Name}" + Environment.NewLine;
            allText += $"CurrentUICulture: {CultureInfo.CurrentUICulture.Name}" + Environment.NewLine;
            allText += $"BuildLabel: {SystemSettings.BuildLabel}" + Environment.NewLine;
            allText += $"Loaded Addons: {string.Join(" ", Extensibility.Hosting.AddonManager.Current.All.Select(a => a.DisplayName))}" + Environment.NewLine;
            allText += $"IsLightTheme: {SystemSettings.IsLightTheme}" + Environment.NewLine;
            allText += $"IsSystemLightTheme: {SystemSettings.IsSystemLightTheme}" + Environment.NewLine;
            allText += $"RTL: {SystemSettings.IsRTL}" + Environment.NewLine;
            allText += $"IsTransparencyEnabled: {SystemSettings.IsTransparencyEnabled}" + Environment.NewLine;
            allText += $"UseAccentColor: {SystemSettings.UseAccentColor}" + Environment.NewLine;
            allText += $"AnimationsEnabled: {SystemParameters.MenuAnimation}" + Environment.NewLine;
            allText += Environment.NewLine;
            allText += AppTrace.GetLogText();

            var fileName = $"{Path.GetTempFileName()}.txt";

            File.WriteAllText(fileName, allText);
            ProcessHelper.StartNoThrow(fileName);
        }
예제 #4
0
        private static void DebugRemoveAllDevices()
        {
            var devManager       = WindowsAudioFactory.Create(AudioDeviceKind.Playback);
            var devManagerNotify = (Interop.MMDeviceAPI.IMMNotificationClient)devManager;

            foreach (var dev in devManager.Devices.ToArray())
            {
                devManagerNotify.OnDeviceRemoved(dev.Id);
            }
            devManagerNotify.OnDefaultDeviceChanged(Interop.MMDeviceAPI.EDataFlow.eRender, Interop.MMDeviceAPI.ERole.eMultimedia, null);
            devManagerNotify.OnDefaultDeviceChanged(Interop.MMDeviceAPI.EDataFlow.eRender, Interop.MMDeviceAPI.ERole.eConsole, null);
        }
예제 #5
0
        public AudioTriggerManager()
        {
            _playbackManager = PlaybackDataModelHost.Current;
            _playbackManager.AppPropertyChanged           += OnAppPropertyChanged;
            _playbackManager.AppAdded                     += (a) => OnAppAddOrRemove(a, AudioAppEventKind.Added);
            _playbackManager.AppRemoved                   += (a) => OnAppAddOrRemove(a, AudioAppEventKind.Removed);
            _playbackManager.DeviceAdded                  += (d) => OnDeviceAddOrRemove(d, AudioDeviceEventKind.Added);
            _playbackManager.DeviceRemoved                += (d) => OnDeviceAddOrRemove(d, AudioDeviceEventKind.Removed);
            _playbackManager.DeviceManager.DefaultChanged += PlaybackDeviceManager_DefaultChanged;
            _defaultPlaybackDevice = _playbackManager.DeviceManager.Default;

            _recordingManager = WindowsAudioFactory.Create(AudioDeviceKind.Recording);
            _recordingManager.DefaultChanged += RecordingMgr_DefaultChanged;
            _defaultRecordingDevice           = _recordingManager.Default;
        }
예제 #6
0
        public static void DumpAndShowData(string logText)
        {
            var ret = new StringBuilder();

            Populate(ret, SnapshotData.App);
            Populate(ret, SnapshotData.Device);
            Populate(ret, SnapshotData.AppSettings);
            Populate(ret, SnapshotData.LocalOnly);
            ret.AppendLine(LineText);
            DumpDeviceManager(ret, WindowsAudioFactory.Create(AudioDeviceKind.Playback));
            ret.AppendLine(logText);

            var fileName = $"{Path.GetTempFileName()}.txt";

            File.WriteAllText(fileName, ret.ToString());
            ProcessHelper.StartNoThrow(fileName);
        }
예제 #7
0
        public void GetApps(AppKind flags)
        {
            if ((flags & AppKind.EveryApp) == AppKind.EveryApp)
            {
                All.Add(new EveryAppViewModel());
            }

            if ((flags & AppKind.ForegroundApp) == AppKind.ForegroundApp)
            {
                All.Add(new ForegroundAppViewModel());
            }

            foreach (var app in WindowsAudioFactory.Create(AudioDeviceKind.Playback).Devices.SelectMany(d => d.Groups).Distinct(IAudioDeviceSessionComparer.Instance).OrderBy(d => d.DisplayName).OrderBy(d => d.DisplayName))
            {
                All.Add(new SettingsAppItemViewModel(app));
            }
        }
예제 #8
0
        public static void DumpAndShowData(string logText, string addons)
        {
            var ret = new StringBuilder();

            ret.AppendLine(DumpDevices(WindowsAudioFactory.Create(AudioDeviceKind.Playback)));
            ret.AppendLine(DumpDevices(WindowsAudioFactory.Create(AudioDeviceKind.Recording)));
            Populate(ret, SnapshotData.App);
            Populate(ret, SnapshotData.Device);
            Populate(ret, SnapshotData.AppSettings);
            ret.AppendLine($"Addons: {addons}");
            ret.AppendLine();
            ret.AppendLine(logText);

            var fileName = $"{Path.GetTempFileName()}.txt";

            File.WriteAllText(fileName, ret.ToString());
            ProcessHelper.StartNoThrow(fileName);
        }
예제 #9
0
        private void ContinueStartup()
        {
            ((UI.Themes.Manager)Resources["ThemeManager"]).Load();

            var deviceManager = WindowsAudioFactory.Create(AudioDeviceKind.Playback);

            deviceManager.Loaded += (_, __) => CompleteStartup();
            CollectionViewModel   = new DeviceCollectionViewModel(deviceManager, _settings);

            _trayIcon = new ShellNotifyIcon(new TaskbarIconSource(CollectionViewModel, _settings));
            Exit     += (_, __) => _trayIcon.IsVisible = false;
            CollectionViewModel.TrayPropertyChanged += () => _trayIcon.SetTooltip(CollectionViewModel.GetTrayToolTip());

            _flyoutViewModel = new FlyoutViewModel(CollectionViewModel, () => _trayIcon.SetFocus());
            FlyoutWindow     = new FlyoutWindow(_flyoutViewModel);
            // Initialize the FlyoutWindow last because its Show/Hide cycle will pump messages, causing UI frames
            // to be executed, breaking the assumption that startup is complete.
            FlyoutWindow.Initialize();
        }
예제 #10
0
        public static bool IsMet(BaseCondition condition)
        {
            if (condition is ProcessCondition)
            {
                bool isProcessRunning = ProcessWatcher.Current.IsRunning(((ProcessCondition)condition).Text);
                switch (((ProcessCondition)condition).Option)
                {
                case ProcessStateKind.Running:
                    return(isProcessRunning);

                case ProcessStateKind.NotRunning:
                    return(!isProcessRunning);

                default:
                    throw new NotImplementedException();
                }
            }
            else if (condition is DefaultDeviceCondition)
            {
                var mgr = WindowsAudioFactory.Create((AudioDeviceKind)System.Enum.Parse(typeof(AudioDeviceKind), ((DefaultDeviceCondition)condition).Device.Kind));

                var isDeviceCurrentlyDefault = ((DefaultDeviceCondition)condition).Device.Id == mgr.Default?.Id;
                switch (((DefaultDeviceCondition)condition).Option)
                {
                case ComparisonBoolKind.Is:
                    return(isDeviceCurrentlyDefault);

                case ComparisonBoolKind.IsNot:
                    return(!isDeviceCurrentlyDefault);

                default:
                    throw new NotImplementedException();
                }
            }
            else if (condition is VariableCondition)
            {
                return(EarTrumpetActionsAddon.Current.LocalVariables[((VariableCondition)condition).Text] == (((VariableCondition)condition).Value == BoolValue.True));
            }
            throw new NotImplementedException();
        }
예제 #11
0
        void GetDevices(DeviceListKind flags)
        {
            bool isRecording = (flags & DeviceListKind.Recording) == DeviceListKind.Recording;

            if ((flags & DeviceListKind.DefaultPlayback) == DeviceListKind.DefaultPlayback)
            {
                All.Add(new DefaultPlaybackDeviceViewModel());
            }

            foreach (var device in WindowsAudioFactory.Create(AudioDeviceKind.Playback).Devices.OrderBy(d => d.DisplayName))
            {
                All.Add(new DeviceViewModel(device));
            }

            if (isRecording)
            {
                foreach (var device in WindowsAudioFactory.Create(AudioDeviceKind.Recording).Devices.OrderBy(d => d.DisplayName))
                {
                    All.Add(new DeviceViewModel(device));
                }
            }
        }
        public void OnAddonEvent(AddonEventKind evt)
        {
            if (evt == AddonEventKind.InitializeAddon)
            {
                Current = this;

                DeviceCollection  = ((App)App.Current).CollectionViewModel;
                m_hardwareManager = new HardwareManager(DeviceCollection, WindowsAudioFactory.Create(AudioDeviceKind.Playback));


                // Monitor the EarTrumpet flyout so we don't show when the flyout is showing.
                _flyoutViewModel = (FlyoutViewModel)((App)Application.Current).FlyoutWindow.DataContext;
                _flyoutViewModel.StateChanged += OnFlyoutViewModelStateChanged;

                // Create a window to use as OSD.
                _osdWindowViewModel = new OSDWindowViewModel();
                _osdWindow          = new OSDWindow(_osdWindowViewModel);
                _osdWindow.Initialize();

                // Listen to events and then present the active ViewModel to the OSD window.
                PlaybackDataModelHost.Current.AppPropertyChanged    += OnAppPropertyChanged;
                PlaybackDataModelHost.Current.DevicePropertyChanged += OnDevicePropertyChanged;
            }
        }
예제 #13
0
        public static void Invoke(BaseAction a)
        {
            Trace.WriteLine($"ActionProcessor Invoke: {a.GetType().Name}");
            if (a is SetVariableAction)
            {
                EarTrumpetActionsAddon.Current.LocalVariables[((SetVariableAction)a).Text] = (((SetVariableAction)a).Value == BoolValue.True);
            }
            else if (a is SetDefaultDeviceAction)
            {
                var mgr = WindowsAudioFactory.Create((AudioDeviceKind)System.Enum.Parse(typeof(AudioDeviceKind), ((SetDefaultDeviceAction)a).Device.Kind));

                var dev = mgr.Devices.FirstOrDefault(d => d.Id == ((SetDefaultDeviceAction)a).Device.Id);
                if (dev != null)
                {
                    mgr.Default = dev;
                }
            }
            else if (a is SetAppVolumeAction)
            {
                var action = (SetAppVolumeAction)a;
                var mgr    = WindowsAudioFactory.Create((AudioDeviceKind)System.Enum.Parse(typeof(AudioDeviceKind), ((SetAppVolumeAction)a).Device.Kind));

                var device = (action.Device?.Id == null) ?
                             mgr.Default : mgr.Devices.FirstOrDefault(d => d.Id == action.Device.Id);
                if (device != null)
                {
                    if (action.App.Id == AppRef.ForegroundAppId)
                    {
                        var app = FindForegroundApp(device.Groups);
                        if (app != null)
                        {
                            DoAudioAction(action.Option, app, action);
                        }
                    }
                    else
                    {
                        foreach (var app in device.Groups.Where(app => action.App.Id == AppRef.EveryAppId || app.AppId == action.App.Id))
                        {
                            DoAudioAction(action.Option, app, action);
                        }
                    }
                }
            }
            else if (a is SetAppMuteAction)
            {
                var action = (SetAppMuteAction)a;
                var mgr    = WindowsAudioFactory.Create((AudioDeviceKind)System.Enum.Parse(typeof(AudioDeviceKind), ((SetAppMuteAction)a).Device.Kind));

                var device = (action.Device?.Id == null) ?
                             mgr.Default : mgr.Devices.FirstOrDefault(d => d.Id == action.Device.Id);
                if (device != null)
                {
                    if (action.App.Id == AppRef.ForegroundAppId)
                    {
                        var app = FindForegroundApp(device.Groups);
                        if (app != null)
                        {
                            DoAudioAction(action.Option, app);
                        }
                    }
                    else
                    {
                        foreach (var app in device.Groups.Where(app => action.App.Id == AppRef.EveryAppId || app.AppId == action.App.Id))
                        {
                            DoAudioAction(action.Option, app);
                        }
                    }
                }
            }
            else if (a is SetDeviceVolumeAction)
            {
                var action = (SetDeviceVolumeAction)a;

                var mgr = WindowsAudioFactory.Create((AudioDeviceKind)System.Enum.Parse(typeof(AudioDeviceKind), ((SetDeviceVolumeAction)a).Device.Kind));

                var device = (action.Device?.Id == null) ?
                             mgr.Default : mgr.Devices.FirstOrDefault(d => d.Id == action.Device.Id);
                if (device != null)
                {
                    DoAudioAction(action.Option, device, action);
                }
            }
            else if (a is SetDeviceMuteAction)
            {
                var action = (SetDeviceMuteAction)a;
                var mgr    = WindowsAudioFactory.Create((AudioDeviceKind)System.Enum.Parse(typeof(AudioDeviceKind), ((SetDeviceMuteAction)a).Device.Kind));

                var device = (action.Device?.Id == null) ?
                             mgr.Default : mgr.Devices.FirstOrDefault(d => d.Id == action.Device.Id);
                if (device != null)
                {
                    DoAudioAction(action.Option, device);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }