Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(icon changer): added Enum file; refactor/style: cleanup #1380

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public interface ISoundSwitchConfiguration : IConfiguration
/// <summary>
/// What to do with the TrayIcon when changing default device
/// </summary>
IconChangerFactory.ActionEnum SwitchIcon { get; set; }
IconChangerEnum SwitchIcon { get; set; }

HashSet<ProfileSetting> ProfileSettings { get; set; }
HashSet<Profile.Profile> Profiles { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public SoundSwitchConfiguration()
AutoAddNewConnectedDevices = false;

SelectedDevices = new HashSet<DeviceInfo>();
SwitchIcon = IconChangerFactory.ActionEnum.Never;
SwitchIcon = IconChangerEnum.Never;
MigratedFields = new HashSet<string>();
}

Expand Down Expand Up @@ -105,7 +105,7 @@ public SoundSwitchConfiguration()
public bool KeepSystrayIcon { get; set; }

public bool SwitchForegroundProgram { get; set; }
public IconChangerFactory.ActionEnum SwitchIcon { get; set; }
public IconChangerEnum SwitchIcon { get; set; }

[Obsolete]
public HashSet<ProfileSetting> ProfileSettings { get; set; } = new();
Expand Down Expand Up @@ -176,7 +176,7 @@ public bool Migrate()
#pragma warning disable 612
if (!MigratedFields.Contains(nameof(KeepSystrayIcon)))
{
SwitchIcon = KeepSystrayIcon ? IconChangerFactory.ActionEnum.Never : IconChangerFactory.ActionEnum.Always;
SwitchIcon = KeepSystrayIcon ? IconChangerEnum.Never : IconChangerEnum.Always;
MigratedFields.Add(nameof(KeepSystrayIcon));
migrated = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
using SoundSwitch.Framework.Banner.Position;
using SoundSwitch.Framework.NotificationManager.Notification.Configuration;
using SoundSwitch.Localization;
using SoundSwitch.Model;
using SoundSwitch.Properties;

namespace SoundSwitch.Framework.NotificationManager.Notification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ public void NotifyProfileChanged(Profile.Profile profile, Bitmap icon, uint? pro
}
}

public void NotifyMuteChanged(string microphoneName, bool newMuteState)
{
}
public void NotifyMuteChanged(string microphoneName, bool newMuteState) { }

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

Expand Down
28 changes: 18 additions & 10 deletions SoundSwitch/Framework/TrayIcon/Icon/Changer/AbstractIconChanger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using NAudio.CoreAudioApi;
/********************************************************************
* Copyright (C) 2015-2017 Antoine Aflalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
********************************************************************/

using NAudio.CoreAudioApi;
using Serilog;
using SoundSwitch.Audio.Manager;
using SoundSwitch.Audio.Manager.Interop.Enum;
Expand All @@ -10,20 +24,14 @@ public abstract class AbstractIconChanger : IIconChanger
{
private readonly ILogger _log;

protected AbstractIconChanger()
{
_log = Log.ForContext("IconChanger", TypeEnum);
}
protected AbstractIconChanger() => _log = Log.ForContext("IconChanger", TypeEnum);

public abstract IconChangerFactory.ActionEnum TypeEnum { get; }
public abstract IconChangerEnum TypeEnum { get; }
public abstract string Label { get; }

protected abstract DataFlow Flow { get; }

protected virtual bool NeedsToChangeIcon(DeviceInfo deviceInfo)
{
return deviceInfo.Type == Flow;
}
protected virtual bool NeedsToChangeIcon(DeviceInfo deviceInfo) => deviceInfo.Type == Flow;

public void ChangeIcon(UI.Component.TrayIcon trayIcon)
{
Expand Down
23 changes: 17 additions & 6 deletions SoundSwitch/Framework/TrayIcon/Icon/Changer/AlwaysIconChanger.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
using NAudio.CoreAudioApi;
/********************************************************************
* Copyright (C) 2015-2017 Antoine Aflalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
********************************************************************/

using NAudio.CoreAudioApi;
using SoundSwitch.Common.Framework.Audio.Device;
using SoundSwitch.Localization;

namespace SoundSwitch.Framework.TrayIcon.Icon.Changer
{
public class AlwaysIconChanger : AbstractIconChanger
{
public override IconChangerFactory.ActionEnum TypeEnum => IconChangerFactory.ActionEnum.Always;
public override IconChangerEnum TypeEnum => IconChangerEnum.Always;
public override string Label => TrayIconStrings.iconChanger_both;

protected override bool NeedsToChangeIcon(DeviceInfo deviceInfo)
{
return true;
}
protected override bool NeedsToChangeIcon(DeviceInfo deviceInfo) => true;

protected override DataFlow Flow => DataFlow.Render;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using SoundSwitch.Audio.Manager.Interop.Enum;
/********************************************************************
* Copyright (C) 2015-2017 Antoine Aflalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
********************************************************************/

using SoundSwitch.Audio.Manager.Interop.Enum;
using SoundSwitch.Common.Framework.Audio.Device;
using SoundSwitch.Localization;
using SoundSwitch.Properties;
Expand All @@ -7,16 +21,11 @@ namespace SoundSwitch.Framework.TrayIcon.Icon.Changer
{
public class NeverIconIconChanger : IIconChanger
{
public IconChangerFactory.ActionEnum TypeEnum => IconChangerFactory.ActionEnum.Never;
public IconChangerEnum TypeEnum => IconChangerEnum.Never;
public string Label => TrayIconStrings.iconChanger_none;

public void ChangeIcon(UI.Component.TrayIcon trayIcon)
{
trayIcon.ReplaceIcon(Resources.Switch_SoundWave);
}
public void ChangeIcon(UI.Component.TrayIcon trayIcon) => trayIcon.ReplaceIcon(Resources.Switch_SoundWave);

public void ChangeIcon(UI.Component.TrayIcon trayIcon, DeviceFullInfo deviceInfo, ERole role)
{
}
public void ChangeIcon(UI.Component.TrayIcon trayIcon, DeviceFullInfo deviceInfo, ERole role) { }
}
}
18 changes: 16 additions & 2 deletions SoundSwitch/Framework/TrayIcon/Icon/Changer/PlaybackIconChanger.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
using NAudio.CoreAudioApi;
/********************************************************************
* Copyright (C) 2015-2017 Antoine Aflalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
********************************************************************/

using NAudio.CoreAudioApi;
using SoundSwitch.Localization;

namespace SoundSwitch.Framework.TrayIcon.Icon.Changer
{
public class PlaybackIconChanger : AbstractIconChanger
{
public override IconChangerFactory.ActionEnum TypeEnum => IconChangerFactory.ActionEnum.Playback;
public override IconChangerEnum TypeEnum => IconChangerEnum.Playback;
public override string Label => TrayIconStrings.iconChanger_playback;
protected override DataFlow Flow => DataFlow.Render;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
using NAudio.CoreAudioApi;
/********************************************************************
* Copyright (C) 2015-2017 Antoine Aflalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
********************************************************************/

using NAudio.CoreAudioApi;
using SoundSwitch.Localization;

namespace SoundSwitch.Framework.TrayIcon.Icon.Changer
{
public class RecordingIconChanger : AbstractIconChanger
{
public override IconChangerFactory.ActionEnum TypeEnum => IconChangerFactory.ActionEnum.Recording;
public override IconChangerEnum TypeEnum => IconChangerEnum.Recording;
public override string Label => TrayIconStrings.iconChanger_recording;
protected override DataFlow Flow => DataFlow.Capture;
}
Expand Down
18 changes: 16 additions & 2 deletions SoundSwitch/Framework/TrayIcon/Icon/IIconChanger.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
using SoundSwitch.Audio.Manager.Interop.Enum;
/********************************************************************
* Copyright (C) 2015-2017 Antoine Aflalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
********************************************************************/

using SoundSwitch.Audio.Manager.Interop.Enum;
using SoundSwitch.Common.Framework.Audio.Device;
using SoundSwitch.Framework.Factory;

namespace SoundSwitch.Framework.TrayIcon.Icon
{
public interface IIconChanger : IEnumImpl<IconChangerFactory.ActionEnum>
public interface IIconChanger : IEnumImpl<IconChangerEnum>
{

/// <summary>
Expand Down
24 changes: 24 additions & 0 deletions SoundSwitch/Framework/TrayIcon/Icon/IconChangerEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/********************************************************************
* Copyright (C) 2015-2017 Antoine Aflalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
********************************************************************/

namespace SoundSwitch.Framework.TrayIcon.Icon
{
public enum IconChangerEnum
{
Never = 0,
Recording = 1,
Playback = 2,
Always = 3
}
}
30 changes: 18 additions & 12 deletions SoundSwitch/Framework/TrayIcon/Icon/IconChangerFactory.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
using SoundSwitch.Framework.Factory;
/********************************************************************
* Copyright (C) 2015-2017 Antoine Aflalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
********************************************************************/

using SoundSwitch.Framework.Factory;
using SoundSwitch.Framework.TrayIcon.Icon.Changer;

namespace SoundSwitch.Framework.TrayIcon.Icon
{
public class IconChangerFactory : AbstractFactory<IconChangerFactory.ActionEnum, IIconChanger>
public class IconChangerFactory : AbstractFactory<IconChangerEnum, IIconChanger>
{
public enum ActionEnum
{
Never,
Recording,
Playback,
Always
}

private static readonly IEnumImplList<IconChangerFactory.ActionEnum, IIconChanger> Impl = new EnumImplList<ActionEnum, IIconChanger>()
private static readonly IEnumImplList<IconChangerEnum, IIconChanger> Impl = new EnumImplList<IconChangerEnum, IIconChanger>()
{
new NeverIconIconChanger(),
new PlaybackIconChanger(),
new RecordingIconChanger(),
new NeverIconIconChanger(),
new AlwaysIconChanger()
};

Expand Down
Loading
Loading