Ejemplo n.º 1
0
 private void AddDeviceApplicationPreference(AudioInterface audioInterface, ObservableProcess process)
 {
     SharedModels.DeviceApplicationPreference deviceApplicationPreference = deviceApplicationPreferences.Devices.FirstOrDefault(x => x.Id == audioInterface.ID);
     if (deviceApplicationPreference == default)
     {
         deviceApplicationPreference = new SharedModels.DeviceApplicationPreference()
         {
             Id           = audioInterface.ID,
             Applications = new List <string>()
         };
         deviceApplicationPreferences.Devices.Add(deviceApplicationPreference);
     }
     if (!deviceApplicationPreference.Applications.Contains(process.ProcessName))
     {
         deviceApplicationPreference.Applications.Add(process.ProcessName);
     }
     jsonDataDirty = true;
 }
Ejemplo n.º 2
0
            void IMMNotificationClient.OnDeviceStateChanged(string deviceId, DeviceState newState)
            {
                AudioInterface audioInterface = GetAudioInterfaceById(deviceId);

                if (audioInterface != null)
                {
                    audioInterface.SetProperties(newState);
                }

                if (newState != DeviceState.Active)
                {
                    if (ActiveDevices.Contains(audioInterface))
                    {
                        mContext.Send(
                            x => ActiveDevices.Remove(audioInterface),
                            null);
                    }
                    return;
                }

                mContext.Send(
                    x => ActiveDevices.Add(audioInterface),
                    null);

                SharedModels.DeviceApplicationPreference deviceApplicationPreference = Instance.deviceApplicationPreferences.Devices.FirstOrDefault(x => x.Id == deviceId);
                if (deviceApplicationPreference == default)
                {
                    return;
                }

                foreach (string applicationName in deviceApplicationPreference.Applications)
                {
                    ObservableProcess[] processes = ProcessCollection.Processes.Where(x => x.ProcessName == applicationName).ToArray();
                    foreach (ObservableProcess process in processes)
                    {
                        ChangeDefaultApplicationDevice(audioInterface, process);
                    }
                }
            }
Ejemplo n.º 3
0
        private void RemoveOldApplicationDevicePreference(ObservableProcess process, AudioInterface audioInterface)
        {
            SharedModels.ApplicationDevicePreference applicationDevicePreference = applicationDevicePreferences.Applications.FirstOrDefault(x => x.Name == process.ProcessName);
            if (applicationDevicePreference == default)
            {
                return;
            }
            string previousPreferredInterface = null;

            switch (audioInterface.DataFlow)
            {
            case DataFlow.Render:
                previousPreferredInterface = applicationDevicePreference.Devices.RenderDeviceId;
                applicationDevicePreference.Devices.RenderDeviceId = null;
                break;

            case DataFlow.Capture:
                previousPreferredInterface = applicationDevicePreference.Devices.CaptureDeviceId;
                applicationDevicePreference.Devices.CaptureDeviceId = null;
                break;

            default:
                return;
            }
            if (applicationDevicePreference.Devices.RenderDeviceId == null && applicationDevicePreference.Devices.CaptureDeviceId == null)
            {
                applicationDevicePreferences.Applications.Remove(applicationDevicePreference);
            }
            SharedModels.DeviceApplicationPreference deviceApplicationPreference = deviceApplicationPreferences.Devices.FirstOrDefault(x => x.Id == previousPreferredInterface);
            if (deviceApplicationPreference == default)
            {
                return;
            }
            deviceApplicationPreference.Applications.Remove(process.ProcessName);
            if (deviceApplicationPreference.Applications.Count == 0)
            {
                deviceApplicationPreferences.Devices.Remove(deviceApplicationPreference);
            }
        }