Skip to content

Commit e676a7e

Browse files
authored
Merge pull request #1380 from XangelMusic/dev
refactor(icon changer): added Enum file; refactor/style: cleanup
2 parents 105fe4a + 4fa9774 commit e676a7e

18 files changed

+253
-142
lines changed

SoundSwitch/Framework/Configuration/ISoundSwitchConfiguration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public interface ISoundSwitchConfiguration : IConfiguration
6363
/// <summary>
6464
/// What to do with the TrayIcon when changing default device
6565
/// </summary>
66-
IconChangerFactory.ActionEnum SwitchIcon { get; set; }
66+
IconChangerEnum SwitchIcon { get; set; }
6767

6868
HashSet<ProfileSetting> ProfileSettings { get; set; }
6969
HashSet<Profile.Profile> Profiles { get; set; }

SoundSwitch/Framework/Configuration/SoundSwitchConfiguration.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public SoundSwitchConfiguration()
6868
AutoAddNewConnectedDevices = false;
6969

7070
SelectedDevices = new HashSet<DeviceInfo>();
71-
SwitchIcon = IconChangerFactory.ActionEnum.Never;
71+
SwitchIcon = IconChangerEnum.Never;
7272
MigratedFields = new HashSet<string>();
7373
}
7474

@@ -105,7 +105,7 @@ public SoundSwitchConfiguration()
105105
public bool KeepSystrayIcon { get; set; }
106106

107107
public bool SwitchForegroundProgram { get; set; }
108-
public IconChangerFactory.ActionEnum SwitchIcon { get; set; }
108+
public IconChangerEnum SwitchIcon { get; set; }
109109

110110
[Obsolete]
111111
public HashSet<ProfileSetting> ProfileSettings { get; set; } = new();
@@ -176,7 +176,7 @@ public bool Migrate()
176176
#pragma warning disable 612
177177
if (!MigratedFields.Contains(nameof(KeepSystrayIcon)))
178178
{
179-
SwitchIcon = KeepSystrayIcon ? IconChangerFactory.ActionEnum.Never : IconChangerFactory.ActionEnum.Always;
179+
SwitchIcon = KeepSystrayIcon ? IconChangerEnum.Never : IconChangerEnum.Always;
180180
MigratedFields.Add(nameof(KeepSystrayIcon));
181181
migrated = true;
182182
}

SoundSwitch/Framework/NotificationManager/Notification/NotificationBanner.cs

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
using SoundSwitch.Framework.Banner.Position;
2424
using SoundSwitch.Framework.NotificationManager.Notification.Configuration;
2525
using SoundSwitch.Localization;
26-
using SoundSwitch.Model;
2726
using SoundSwitch.Properties;
2827

2928
namespace SoundSwitch.Framework.NotificationManager.Notification

SoundSwitch/Framework/NotificationManager/Notification/NotificationSound.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ public void NotifyProfileChanged(Profile.Profile profile, Bitmap icon, uint? pro
6969
}
7070
}
7171

72-
public void NotifyMuteChanged(string microphoneName, bool newMuteState)
73-
{
74-
}
72+
public void NotifyMuteChanged(string microphoneName, bool newMuteState) { }
7573

7674
public void OnSoundChanged(CachedSound newSound) => Configuration.CustomSound = newSound;
7775

SoundSwitch/Framework/TrayIcon/Icon/Changer/AbstractIconChanger.cs

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
using NAudio.CoreAudioApi;
1+
/********************************************************************
2+
* Copyright (C) 2015-2017 Antoine Aflalo
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; either version 2
7+
* of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
********************************************************************/
14+
15+
using NAudio.CoreAudioApi;
216
using Serilog;
317
using SoundSwitch.Audio.Manager;
418
using SoundSwitch.Audio.Manager.Interop.Enum;
@@ -10,20 +24,14 @@ public abstract class AbstractIconChanger : IIconChanger
1024
{
1125
private readonly ILogger _log;
1226

13-
protected AbstractIconChanger()
14-
{
15-
_log = Log.ForContext("IconChanger", TypeEnum);
16-
}
27+
protected AbstractIconChanger() => _log = Log.ForContext("IconChanger", TypeEnum);
1728

18-
public abstract IconChangerFactory.ActionEnum TypeEnum { get; }
29+
public abstract IconChangerEnum TypeEnum { get; }
1930
public abstract string Label { get; }
2031

2132
protected abstract DataFlow Flow { get; }
2233

23-
protected virtual bool NeedsToChangeIcon(DeviceInfo deviceInfo)
24-
{
25-
return deviceInfo.Type == Flow;
26-
}
34+
protected virtual bool NeedsToChangeIcon(DeviceInfo deviceInfo) => deviceInfo.Type == Flow;
2735

2836
public void ChangeIcon(UI.Component.TrayIcon trayIcon)
2937
{

SoundSwitch/Framework/TrayIcon/Icon/Changer/AlwaysIconChanger.cs

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1-
using NAudio.CoreAudioApi;
1+
/********************************************************************
2+
* Copyright (C) 2015-2017 Antoine Aflalo
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; either version 2
7+
* of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
********************************************************************/
14+
15+
using NAudio.CoreAudioApi;
216
using SoundSwitch.Common.Framework.Audio.Device;
317
using SoundSwitch.Localization;
418

519
namespace SoundSwitch.Framework.TrayIcon.Icon.Changer
620
{
721
public class AlwaysIconChanger : AbstractIconChanger
822
{
9-
public override IconChangerFactory.ActionEnum TypeEnum => IconChangerFactory.ActionEnum.Always;
23+
public override IconChangerEnum TypeEnum => IconChangerEnum.Always;
1024
public override string Label => TrayIconStrings.iconChanger_both;
1125

12-
protected override bool NeedsToChangeIcon(DeviceInfo deviceInfo)
13-
{
14-
return true;
15-
}
26+
protected override bool NeedsToChangeIcon(DeviceInfo deviceInfo) => true;
1627

1728
protected override DataFlow Flow => DataFlow.Render;
1829
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
using SoundSwitch.Audio.Manager.Interop.Enum;
1+
/********************************************************************
2+
* Copyright (C) 2015-2017 Antoine Aflalo
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; either version 2
7+
* of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
********************************************************************/
14+
15+
using SoundSwitch.Audio.Manager.Interop.Enum;
216
using SoundSwitch.Common.Framework.Audio.Device;
317
using SoundSwitch.Localization;
418
using SoundSwitch.Properties;
@@ -7,16 +21,11 @@ namespace SoundSwitch.Framework.TrayIcon.Icon.Changer
721
{
822
public class NeverIconIconChanger : IIconChanger
923
{
10-
public IconChangerFactory.ActionEnum TypeEnum => IconChangerFactory.ActionEnum.Never;
24+
public IconChangerEnum TypeEnum => IconChangerEnum.Never;
1125
public string Label => TrayIconStrings.iconChanger_none;
1226

13-
public void ChangeIcon(UI.Component.TrayIcon trayIcon)
14-
{
15-
trayIcon.ReplaceIcon(Resources.Switch_SoundWave);
16-
}
27+
public void ChangeIcon(UI.Component.TrayIcon trayIcon) => trayIcon.ReplaceIcon(Resources.Switch_SoundWave);
1728

18-
public void ChangeIcon(UI.Component.TrayIcon trayIcon, DeviceFullInfo deviceInfo, ERole role)
19-
{
20-
}
29+
public void ChangeIcon(UI.Component.TrayIcon trayIcon, DeviceFullInfo deviceInfo, ERole role) { }
2130
}
2231
}

SoundSwitch/Framework/TrayIcon/Icon/Changer/PlaybackIconChanger.cs

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
using NAudio.CoreAudioApi;
1+
/********************************************************************
2+
* Copyright (C) 2015-2017 Antoine Aflalo
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; either version 2
7+
* of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
********************************************************************/
14+
15+
using NAudio.CoreAudioApi;
216
using SoundSwitch.Localization;
317

418
namespace SoundSwitch.Framework.TrayIcon.Icon.Changer
519
{
620
public class PlaybackIconChanger : AbstractIconChanger
721
{
8-
public override IconChangerFactory.ActionEnum TypeEnum => IconChangerFactory.ActionEnum.Playback;
22+
public override IconChangerEnum TypeEnum => IconChangerEnum.Playback;
923
public override string Label => TrayIconStrings.iconChanger_playback;
1024
protected override DataFlow Flow => DataFlow.Render;
1125
}

SoundSwitch/Framework/TrayIcon/Icon/Changer/RecordingIconChanger.cs

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
using NAudio.CoreAudioApi;
1+
/********************************************************************
2+
* Copyright (C) 2015-2017 Antoine Aflalo
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; either version 2
7+
* of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
********************************************************************/
14+
15+
using NAudio.CoreAudioApi;
216
using SoundSwitch.Localization;
317

418
namespace SoundSwitch.Framework.TrayIcon.Icon.Changer
519
{
620
public class RecordingIconChanger : AbstractIconChanger
721
{
8-
public override IconChangerFactory.ActionEnum TypeEnum => IconChangerFactory.ActionEnum.Recording;
22+
public override IconChangerEnum TypeEnum => IconChangerEnum.Recording;
923
public override string Label => TrayIconStrings.iconChanger_recording;
1024
protected override DataFlow Flow => DataFlow.Capture;
1125
}

SoundSwitch/Framework/TrayIcon/Icon/IIconChanger.cs

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1-
using SoundSwitch.Audio.Manager.Interop.Enum;
1+
/********************************************************************
2+
* Copyright (C) 2015-2017 Antoine Aflalo
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; either version 2
7+
* of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
********************************************************************/
14+
15+
using SoundSwitch.Audio.Manager.Interop.Enum;
216
using SoundSwitch.Common.Framework.Audio.Device;
317
using SoundSwitch.Framework.Factory;
418

519
namespace SoundSwitch.Framework.TrayIcon.Icon
620
{
7-
public interface IIconChanger : IEnumImpl<IconChangerFactory.ActionEnum>
21+
public interface IIconChanger : IEnumImpl<IconChangerEnum>
822
{
923

1024
/// <summary>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/********************************************************************
2+
* Copyright (C) 2015-2017 Antoine Aflalo
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; either version 2
7+
* of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
********************************************************************/
14+
15+
namespace SoundSwitch.Framework.TrayIcon.Icon
16+
{
17+
public enum IconChangerEnum
18+
{
19+
Never = 0,
20+
Recording = 1,
21+
Playback = 2,
22+
Always = 3
23+
}
24+
}

SoundSwitch/Framework/TrayIcon/Icon/IconChangerFactory.cs

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
using SoundSwitch.Framework.Factory;
1+
/********************************************************************
2+
* Copyright (C) 2015-2017 Antoine Aflalo
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; either version 2
7+
* of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
********************************************************************/
14+
15+
using SoundSwitch.Framework.Factory;
216
using SoundSwitch.Framework.TrayIcon.Icon.Changer;
317

418
namespace SoundSwitch.Framework.TrayIcon.Icon
519
{
6-
public class IconChangerFactory : AbstractFactory<IconChangerFactory.ActionEnum, IIconChanger>
20+
public class IconChangerFactory : AbstractFactory<IconChangerEnum, IIconChanger>
721
{
8-
public enum ActionEnum
9-
{
10-
Never,
11-
Recording,
12-
Playback,
13-
Always
14-
}
15-
16-
private static readonly IEnumImplList<IconChangerFactory.ActionEnum, IIconChanger> Impl = new EnumImplList<ActionEnum, IIconChanger>()
22+
private static readonly IEnumImplList<IconChangerEnum, IIconChanger> Impl = new EnumImplList<IconChangerEnum, IIconChanger>()
1723
{
24+
new NeverIconIconChanger(),
1825
new PlaybackIconChanger(),
1926
new RecordingIconChanger(),
20-
new NeverIconIconChanger(),
2127
new AlwaysIconChanger()
2228
};
2329

0 commit comments

Comments
 (0)