Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
JSON config
Browse files Browse the repository at this point in the history
  • Loading branch information
romain-perez24 committed Apr 11, 2016
1 parent 604710a commit 5e7ad3f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 25 deletions.
Binary file modified Wox.Plugin.Volume.wox
Binary file not shown.
9 changes: 9 additions & 0 deletions Wox.Plugin.Volume/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Wox.Plugin.Volume
{
class Config
{
public int step { get; set; }
public string up { get; set; }
public string down { get; set; }
}
}
64 changes: 39 additions & 25 deletions Wox.Plugin.Volume/Main.cs
Original file line number Diff line number Diff line change
@@ -1,75 +1,89 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Web.Script.Serialization;
using CoreAudioApi;
using System.IO;

namespace Wox.Plugin.Volume
{
public class Main : IPlugin
{
const int VOLUME_STEP = 5;
private PluginInitContext context;
private MMDevice PlaybackDevice;
private Config config;
private bool initialized = false;

public void Init(PluginInitContext context)
{
this.context = context;

try
{
string json = (new StreamReader(context.CurrentPluginMetadata.PluginDirectory + "\\config.json")).ReadToEnd();
config = (new JavaScriptSerializer()).Deserialize<Config>(json);
}
catch (System.Exception)
{
return;
}

try
{
PlaybackDevice = MMDeviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
initialized = true;
} catch (CoreAudioException e)
}
catch (CoreAudioException)
{
return;
}

initialized = true;
}

public List<Result> Query(Query query)
{
List<Result> results = new List<Result>();
addResult(results, query);
results.Add(GetResult(query));
return results;
}

private void addResult(List<Result> results, Query query)
private Result GetResult(Query query)
{
Result result = new Result()
{
Title = "Current volume",
SubTitle = "no info",
IcoPath = "Images\\icon.png"
};

if (!initialized)
{
results.Add(new Result()
{
Title = "Current volume",
SubTitle = "no info",
IcoPath = "Images\\icon.png"
});
return;
return result;
}

string queryString = query.ToString();
string lastChar = queryString.Substring(queryString.Length - 1);

int volume = GetVolume();
if (lastChar.Equals("+"))
if (lastChar.Equals(config.up))
{
volume += VOLUME_STEP;
volume += config.step;
}
else if (lastChar.Equals("-"))
else if (lastChar.Equals(config.down))
{
volume -= VOLUME_STEP;
volume -= config.step;
}

SetVolume(volume);
volume = GetVolume();

string volumeDesc = "[";
for (int i = 0; i < 100; i += VOLUME_STEP)
for (int i = 0; i < 100; i += config.step)
{
volumeDesc = string.Concat(volumeDesc, volume > i ? "=" : "-");
}
volumeDesc = string.Concat(volumeDesc, "]");

results.Add(new Result()
{
Title = "Current volume",
SubTitle = volumeDesc,
IcoPath = "Images\\icon.png"
});
result.SubTitle = volumeDesc;
return result;
}

public int GetVolume()
Expand Down
6 changes: 6 additions & 0 deletions Wox.Plugin.Volume/Wox.Plugin.Volume.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -51,13 +52,18 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="Main.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="config.json" />
<None Include="packages.config" />
<None Include="plugin.json" />
</ItemGroup>
<ItemGroup>
<Content Include="Images\icon.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
5 changes: 5 additions & 0 deletions Wox.Plugin.Volume/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"step": 5,
"up": "+",
"down": "-"
}

0 comments on commit 5e7ad3f

Please sign in to comment.