Skip to content

Commit

Permalink
feat: Support hybrid WSL and Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
KeithClinard committed Dec 22, 2021
1 parent 78ad1e9 commit 206a118
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 167 deletions.
34 changes: 20 additions & 14 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class Main : IPlugin
private PluginInitContext context;
const string ico = "Prompt.png";
const string defaultGitFolder = "C:\\git";
Exception startupException = null;
const string defaultWslGitFolder = "/git";
private readonly Exception startupException = null;

private readonly SettingsModel settings;
private readonly PluginJsonStorage<SettingsModel> storage;
Expand All @@ -22,9 +23,14 @@ public Main()
{
storage = new PluginJsonStorage<SettingsModel>();
settings = storage.Load();
if (String.IsNullOrEmpty(settings.gitFolder))
if (string.IsNullOrEmpty(settings.GitFolder))
{
settings.gitFolder = defaultGitFolder;
settings.GitFolder = defaultGitFolder;
storage.Save();
}
if (string.IsNullOrEmpty(settings.WslGitFolder))
{
settings.WslGitFolder = defaultWslGitFolder;
storage.Save();
}
}
Expand All @@ -49,8 +55,8 @@ public List<Result> Query(Query query)
list.Add(new Result
{
Title = "Devbox Plugin",
SubTitle = "Error during initialization: " + startupException.Message,
IcoPath = ico
SubTitle = "Error during initialization: " + startupException.Message,
IcoPath = ico
});
}
else if (query.ActionKeyword.Equals("db"))
Expand All @@ -65,18 +71,18 @@ public List<Result> Query(Query query)
{
return VSCode.Query(query, settings, context);
}
else if (String.IsNullOrEmpty(settings.apiToken))
else if (string.IsNullOrEmpty(settings.ApiToken))
{
list.Add(new Result
{
Title = "Set Github API Token",
SubTitle = "Set this before using this plugin",
Action = (e) =>
{
context.API.ChangeQuery("db apiToken ");
return false;
},
IcoPath = ico
SubTitle = "Set this before using this plugin",
Action = (e) =>
{
context.API.ChangeQuery("db apiToken ");
return false;
},
IcoPath = ico
});
}
else if (query.ActionKeyword.Equals("gh"))
Expand All @@ -93,7 +99,7 @@ public List<Result> Query(Query query)
list.Add(new Result
{
Title = "Error: " + e.Message,
IcoPath = ico
IcoPath = ico
});
}
return list;
Expand Down
4 changes: 2 additions & 2 deletions Models/GithubApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public static ApiResult QueryGithub(Query query, SettingsModel settings)
| SecurityProtocolType.Tls12
| SecurityProtocolType.Ssl3;

String url = $"https://api.github.com/search/repositories?access_token={settings.apiToken}&q={query.Search}";
string url = $"https://api.github.com/search/repositories?access_token={settings.ApiToken}&q={query.Search}";
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.ProtocolVersion = HttpVersion.Version10;
request.Method = "GET";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
WebResponse response = request.GetResponse();
using(Stream stream = response.GetResponseStream())
using (Stream stream = response.GetResponseStream())
{
StreamReader objReader = new StreamReader(stream);
var json = objReader.ReadToEnd();
Expand Down
11 changes: 5 additions & 6 deletions Models/SettingsModel.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System;

namespace Wox.Plugin.Devbox.Helpers
namespace Wox.Plugin.Devbox.Helpers
{
class SettingsModel
{
public String apiToken { get; set; }
public String gitFolder { get; set; }
public String wslName { get; set; }
public string ApiToken { get; set; }
public string GitFolder { get; set; }
public string WslGitFolder { get; set; }
public string WslDistroName { get; set; }
}
}
36 changes: 18 additions & 18 deletions Plugins/Ember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private static List<EmberImportObject> LoadImports(PluginInitContext context)
{
if (_imports == null)
{
using(StreamReader stream = new StreamReader(context.CurrentPluginMetadata.PluginDirectory + "\\mappings.json"))
using (StreamReader stream = new StreamReader(context.CurrentPluginMetadata.PluginDirectory + "\\mappings.json"))
{
var json = stream.ReadToEnd();
_imports = JsonConvert.DeserializeObject<List<EmberImportObject>>(json);
Expand All @@ -37,16 +37,16 @@ public static List<Result> Query(Query query, SettingsModel settings, PluginInit
list.Add(new Result
{
Title = "Lookup Ember Import",
SubTitle = "Lookup Ember import strings and copy to clipboard",
IcoPath = ico
SubTitle = "Lookup Ember import strings and copy to clipboard",
IcoPath = ico
});
return list;
}
List<EmberImportObject> results = imports.FindAll(result =>
{
bool found = true;
String[] searchStrings = query.Search.Split(' ');
foreach (String searchSegment in searchStrings)
string[] searchStrings = query.Search.Split(' ');
foreach (string searchSegment in searchStrings)
{
found = found && result.global.ToLower().Contains(searchSegment.ToLower());
}
Expand All @@ -57,9 +57,9 @@ public static List<Result> Query(Query query, SettingsModel settings, PluginInit
{
foreach (EmberImportObject item in results)
{
String module = item.module;
String export = item.export;
String localName = item.localName;
string module = item.module;
string export = item.export;
string localName = item.localName;
if (item.deprecated && item.replacement != null)
{
module = item.replacement.module;
Expand All @@ -74,18 +74,18 @@ public static List<Result> Query(Query query, SettingsModel settings, PluginInit
}
}

String importText = export.Equals("default") ? localName : "{ " + export + " }";
String clipboardText = "import " + importText + " from '" + module + "';";
string importText = export.Equals("default") ? localName : "{ " + export + " }";
string clipboardText = "import " + importText + " from '" + module + "';";
list.Add(new Result
{
Title = item.global,
SubTitle = clipboardText,
IcoPath = ico,
Action = (e) =>
{
Clipboard.SetText(clipboardText);
return true;
}
SubTitle = clipboardText,
IcoPath = ico,
Action = (e) =>
{
Clipboard.SetText(clipboardText);
return true;
}
});
}
}
Expand All @@ -94,7 +94,7 @@ public static List<Result> Query(Query query, SettingsModel settings, PluginInit
list.Add(new Result
{
Title = "No Results Found",
IcoPath = ico
IcoPath = ico
});
}

Expand Down
32 changes: 16 additions & 16 deletions Plugins/Github.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static class Github
{
private static readonly string ico = "Prompt.png";

private static void openUrl(String url)
private static void OpenUrl(string url)
{
Process.Start(url);
}
Expand All @@ -23,13 +23,13 @@ public static List<Result> Query(Query query, SettingsModel settings, PluginInit
list.Add(new Result
{
Title = "Open Github",
SubTitle = "...or keep typing to search for repositories",
Action = (e) =>
{
openUrl("http://github.com/");
return true;
},
IcoPath = ico
SubTitle = "...or keep typing to search for repositories",
Action = (e) =>
{
OpenUrl("http://github.com/");
return true;
},
IcoPath = ico
});
return list;
}
Expand All @@ -43,13 +43,13 @@ public static List<Result> Query(Query query, SettingsModel settings, PluginInit
list.Add(new Result
{
Title = result.full_name,
SubTitle = result.description,
IcoPath = ico,
Action = (e) =>
{
openUrl(result.html_url);
return true;
}
SubTitle = result.description,
IcoPath = ico,
Action = (e) =>
{
OpenUrl(result.html_url);
return true;
}
});
}
}
Expand All @@ -58,7 +58,7 @@ public static List<Result> Query(Query query, SettingsModel settings, PluginInit
list.Add(new Result
{
Title = "No Results Found",
IcoPath = ico
IcoPath = ico
});
}

Expand Down
Loading

0 comments on commit 206a118

Please sign in to comment.