Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/Zeroto521/Flow.Launcher into…
Browse files Browse the repository at this point in the history
… dev
  • Loading branch information
Zeroto521 committed Dec 15, 2020
2 parents 42f8bbe + 2e9d364 commit 740b3dc
Show file tree
Hide file tree
Showing 39 changed files with 698 additions and 696 deletions.
1 change: 0 additions & 1 deletion Flow.Launcher.Core/Flow.Launcher.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<ItemGroup>
<PackageReference Include="FSharp.Core" Version="4.7.1" />
<PackageReference Include="squirrel.windows" Version="1.5.2" />
<PackageReference Include="SharpZipLib" Version="1.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
169 changes: 0 additions & 169 deletions Flow.Launcher.Core/Plugin/PluginInstaller.cs

This file was deleted.

5 changes: 0 additions & 5 deletions Flow.Launcher.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,6 @@ public static void InitializePlugins(IPublicAPI api)
}
}

public static void InstallPlugin(string path)
{
PluginInstaller.Install(path);
}

public static List<PluginPair> ValidPluginsForQuery(Query query)
{
if (NonGlobalPlugins.ContainsKey(query.ActionKeyword))
Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher.Core/Resource/Internationalization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ public void ChangeLanguage(Language language)
{
language = language.NonNull();

Settings.Language = language.LanguageCode;

RemoveOldLanguageFiles();
if (language != AvailableLanguages.English)
{
LoadLanguage(language);
}
UpdatePluginMetadataTranslations();
Settings.Language = language.LanguageCode;

}

Expand Down
18 changes: 6 additions & 12 deletions Flow.Launcher.Infrastructure/Http/Http.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,12 @@ public static async Task<string> Get([NotNull] string url, string encoding = "UT
response = response.NonNull();
var stream = response.GetResponseStream().NonNull();

using (var reader = new StreamReader(stream, Encoding.GetEncoding(encoding)))
{
var content = await reader.ReadToEndAsync();
if (response.StatusCode == HttpStatusCode.OK)
{
return content;
}
else
{
throw new HttpRequestException($"Error code <{response.StatusCode}> with content <{content}> returned from <{url}>");
}
}
using var reader = new StreamReader(stream, Encoding.GetEncoding(encoding));
var content = await reader.ReadToEndAsync();
if (response.StatusCode != HttpStatusCode.OK)
throw new HttpRequestException($"Error code <{response.StatusCode}> with content <{content}> returned from <{url}>");

return content;
}
}
}
48 changes: 34 additions & 14 deletions Flow.Launcher.Infrastructure/PinyinAlphabet.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JetBrains.Annotations;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Infrastructure.Storage;
using Flow.Launcher.Infrastructure.UserSettings;
using ToolGood.Words.Pinyin;
using System.Threading.Tasks;

namespace Flow.Launcher.Infrastructure
{
Expand All @@ -27,7 +23,6 @@ public void Initialize([NotNull] Settings settings)
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
}


public string Translate(string content)
{
if (_settings.ShouldUsePinyin)
Expand All @@ -36,10 +31,40 @@ public string Translate(string content)
{
if (WordsHelper.HasChinese(content))
{
var result = WordsHelper.GetPinyin(content, ";");
result = GetFirstPinyinChar(result) + result.Replace(";", "");
_pinyinCache[content] = result;
return result;
var resultList = WordsHelper.GetPinyinList(content);

StringBuilder resultBuilder = new StringBuilder();

for (int i = 0; i < resultList.Length; i++)
{
if (content[i] >= 0x3400 && content[i] <= 0x9FD5)
resultBuilder.Append(resultList[i].First());
}

resultBuilder.Append(' ');

bool pre = false;

for (int i = 0; i < resultList.Length; i++)
{
if (content[i] >= 0x3400 && content[i] <= 0x9FD5)
{
resultBuilder.Append(' ');
resultBuilder.Append(resultList[i]);
pre = true;
}
else
{
if (pre)
{
pre = false;
resultBuilder.Append(' ');
}
resultBuilder.Append(resultList[i]);
}
}

return _pinyinCache[content] = resultBuilder.ToString();
}
else
{
Expand All @@ -56,10 +81,5 @@ public string Translate(string content)
return content;
}
}

private string GetFirstPinyinChar(string content)
{
return string.Concat(content.Split(';').Select(x => x.First()));
}
}
}
10 changes: 9 additions & 1 deletion Flow.Launcher.Infrastructure/UserSettings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ namespace Flow.Launcher.Infrastructure.UserSettings
{
public class Settings : BaseModel
{
private string language = "en";

public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}";
public string OpenResultModifiers { get; set; } = KeyConstant.Alt;
public bool ShowOpenResultHotkey { get; set; } = true;
public string Language { get; set; } = "en";
public string Language
{
get => language; set {
language = value;
OnPropertyChanged();
}
}
public string Theme { get; set; } = Constant.DefaultTheme;
public bool UseDropShadowEffect { get; set; } = false;
public string QueryBoxFont { get; set; } = FontFamily.GenericSansSerif.Name;
Expand Down
6 changes: 0 additions & 6 deletions Flow.Launcher.Plugin/IPublicAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ public interface IPublicAPI
/// </summary>
void OpenSettingDialog();

/// <summary>
/// Install Flow Launcher plugin
/// </summary>
/// <param name="path">Plugin path (ends with .flowlauncher)</param>
void InstallPlugin(string path);

/// <summary>
/// Get translation of current language
/// You need to implement IPluginI18n if you want to support multiple languages for your plugin
Expand Down
Loading

0 comments on commit 740b3dc

Please sign in to comment.