Skip to content

Commit

Permalink
Merge pull request #604 from Flow-Launcher/dev
Browse files Browse the repository at this point in the history
Release 1.8.1
  • Loading branch information
jjw24 authored Jul 29, 2021
2 parents aeba056 + 309ee29 commit 620ed4a
Show file tree
Hide file tree
Showing 19 changed files with 348 additions and 110 deletions.
1 change: 1 addition & 0 deletions Flow.Launcher.Core/Flow.Launcher.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<ItemGroup>
<PackageReference Include="Droplex" Version="1.3.1" />
<PackageReference Include="FSharp.Core" Version="4.7.1" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.1.3" />
<PackageReference Include="squirrel.windows" Version="1.5.2" />
</ItemGroup>

Expand Down
81 changes: 67 additions & 14 deletions Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
using System.Windows.Forms;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Plugin;
using ICSharpCode.SharpZipLib.Zip;
using JetBrains.Annotations;
using Microsoft.IO;

namespace Flow.Launcher.Core.Plugin
{
Expand All @@ -33,9 +35,11 @@ internal abstract class JsonRPCPlugin : IAsyncPlugin, IContextMenu
protected abstract string ExecuteCallback(JsonRPCRequestModel rpcRequest);
protected abstract string ExecuteContextMenu(Result selectedResult);

private static readonly RecyclableMemoryStreamManager BufferManager = new();

public List<Result> LoadContextMenus(Result selectedResult)
{
string output = ExecuteContextMenu(selectedResult);
var output = ExecuteContextMenu(selectedResult);
try
{
return DeserializedResult(output);
Expand All @@ -61,12 +65,23 @@ private async Task<List<Result>> DeserializedResultAsync(Stream output)
{
if (output == Stream.Null) return null;

var queryResponseModel = await
JsonSerializer.DeserializeAsync<JsonRPCQueryResponseModel>(output, options);
try
{
var queryResponseModel =
await JsonSerializer.DeserializeAsync<JsonRPCQueryResponseModel>(output, options);

await output.DisposeAsync();

return ParseResults(queryResponseModel);
return ParseResults(queryResponseModel);
}
catch (JsonException e)
{
Log.Exception(GetType().FullName, "Unexpected Json Input", e);
}
finally
{
await output.DisposeAsync();
}

return null;
}

private List<Result> DeserializedResult(string output)
Expand All @@ -81,15 +96,14 @@ private List<Result> DeserializedResult(string output)

private List<Result> ParseResults(JsonRPCQueryResponseModel queryResponseModel)
{
var results = new List<Result>();
if (queryResponseModel.Result == null) return null;

if (!string.IsNullOrEmpty(queryResponseModel.DebugMessage))
{
context.API.ShowMsg(queryResponseModel.DebugMessage);
}

foreach (JsonRPCResult result in queryResponseModel.Result)
foreach (var result in queryResponseModel.Result)
{
result.Action = c =>
{
Expand All @@ -114,7 +128,8 @@ private List<Result> ParseResults(JsonRPCQueryResponseModel queryResponseModel)
return !result.JsonRPCAction.DontHideAfterAction;
}

var jsonRpcRequestModel = JsonSerializer.Deserialize<JsonRPCRequestModel>(actionResponse, options);
var jsonRpcRequestModel =
JsonSerializer.Deserialize<JsonRPCRequestModel>(actionResponse, options);

if (jsonRpcRequestModel?.Method?.StartsWith("Flow.Launcher.") ?? false)
{
Expand All @@ -125,9 +140,12 @@ private List<Result> ParseResults(JsonRPCQueryResponseModel queryResponseModel)

return !result.JsonRPCAction.DontHideAfterAction;
};
results.Add(result);
}

var results = new List<Result>();

results.AddRange(queryResponseModel.Result);

return results;
}

Expand Down Expand Up @@ -217,16 +235,42 @@ protected string Execute(ProcessStartInfo startInfo)

protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, CancellationToken token = default)
{
Process process = null;
bool disposed = false;
try
{
using var process = Process.Start(startInfo);
process = Process.Start(startInfo);
if (process == null)
{
Log.Error("|JsonRPCPlugin.ExecuteAsync|Can't start new process");
return Stream.Null;
}

var result = process.StandardOutput.BaseStream;
await using var source = process.StandardOutput.BaseStream;

var buffer = BufferManager.GetStream();

token.Register(() =>
{
// ReSharper disable once AccessToModifiedClosure
// Manually Check whether disposed
if (!disposed && !process.HasExited)
process.Kill();
});

try
{
// token expire won't instantly trigger the exception,
// manually kill process at before
await source.CopyToAsync(buffer, token);
}
catch (OperationCanceledException)
{
await buffer.DisposeAsync();
return Stream.Null;
}

buffer.Seek(0, SeekOrigin.Begin);

token.ThrowIfCancellationRequested();

Expand All @@ -245,7 +289,7 @@ protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, Cancellati
return Stream.Null;
}

return result;
return buffer;
}
catch (Exception e)
{
Expand All @@ -254,15 +298,24 @@ protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, Cancellati
e);
return Stream.Null;
}
finally
{
process?.Dispose();
disposed = true;
}
}

public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
{
var output = await ExecuteQueryAsync(query, token);
try
{
var output = await ExecuteQueryAsync(query, token);
return await DeserializedResultAsync(output);
}
catch (OperationCanceledException)
{
return null;
}
catch (Exception e)
{
Log.Exception($"|JsonRPCPlugin.Query|Exception when query <{query}>", e);
Expand Down
4 changes: 3 additions & 1 deletion Flow.Launcher/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>

Http.API = API;
Http.Proxy = _settings.Proxy;

await PluginManager.InitializePlugins(API);
var window = new MainWindow(_settings, _mainVM);

Expand All @@ -99,6 +99,8 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
AutoStartup();
AutoUpdates();

API.SaveAppAllSettings();

_mainVM.MainWindowVisibility = _settings.HideOnStartup ? Visibility.Hidden : Visibility.Visible;
Log.Info("|App.OnStartup|End Flow Launcher startup ---------------------------------------------------- ");
});
Expand Down
5 changes: 5 additions & 0 deletions Flow.Launcher/Languages/sk.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@
<system:String x:Key="ignoreHotkeysOnFullscreen">Ignorovať klávesové skratky v režime na celú obrazovku</system:String>
<system:String x:Key="pythonDirectory">Priečinok s Pythonom</system:String>
<system:String x:Key="autoUpdates">Automatická aktualizácia</system:String>
<system:String x:Key="autoHideScrollBar">Automaticky skryť posuvník</system:String>
<system:String x:Key="autoHideScrollBarToolTip">Automaticky skrývať posuvník v okne nastavení a zobraziť ho, keď naň prejdete myšou</system:String>
<system:String x:Key="selectPythonDirectory">Vybrať</system:String>
<system:String x:Key="hideOnStartup">Schovať Flow Launcher po spustení</system:String>
<system:String x:Key="hideNotifyIcon">Schovať ikonu z oblasti oznámení</system:String>
<system:String x:Key="querySearchPrecision">Presnosť vyhľadávania</system:String>
<system:String x:Key="ShouldUsePinyin">Použiť Pinyin</system:String>
<system:String x:Key="ShouldUsePinyinToolTip">Umožňuje vyhľadávanie pomocou Pinyin. Pinyin je štandardný systém romanizovaného pravopisu pre transliteráciu čínštiny</system:String>
<system:String x:Key="shadowEffectNotAllowed">Efekt tieňa nie je povolený, kým má aktuálny motív povolený efekt rozostrenia</system:String>

<!--Setting Plugin-->
<system:String x:Key="plugin">Plugin</system:String>
Expand All @@ -48,6 +51,7 @@
<system:String x:Key="newActionKeyword">Nová akcia skratky:</system:String>
<system:String x:Key="currentPriority">Aktuálna priorita:</system:String>
<system:String x:Key="newPriority">Nová priorita:</system:String>
<system:String x:Key="priority">Priorita:</system:String>
<system:String x:Key="pluginDirectory">Priečinok s pluginmi</system:String>
<system:String x:Key="author">Autor</system:String>
<system:String x:Key="plugin_init_time">Príprava:</system:String>
Expand All @@ -70,6 +74,7 @@
<system:String x:Key="openResultModifiers">Modifikáčné klávesy na otvorenie výsledkov</system:String>
<system:String x:Key="showOpenResultHotkey">Zobraziť klávesovú skratku</system:String>
<system:String x:Key="customQueryHotkey">Vlastná klávesová skratka na vyhľadávanie</system:String>
<system:String x:Key="customQuery">Dopyt</system:String>
<system:String x:Key="delete">Odstrániť</system:String>
<system:String x:Key="edit">Upraviť</system:String>
<system:String x:Key="add">Pridať</system:String>
Expand Down
4 changes: 2 additions & 2 deletions Flow.Launcher/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Window x:Class="Flow.Launcher.MainWindow"
<Window x:Class="Flow.Launcher.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:flowlauncher="clr-namespace:Flow.Launcher"
Expand Down Expand Up @@ -93,7 +93,7 @@
</ContextMenu>
</TextBox.ContextMenu>
</TextBox>
<svgc:SvgControl Source="{Binding Image}" HorizontalAlignment="Right" Width="48" Height="48"
<svgc:SvgControl Source="{Binding Image}" HorizontalAlignment="Right" Width="42" Height="42"
Background="Transparent"/>
</Grid>
<Line x:Name="ProgressBar" HorizontalAlignment="Right"
Expand Down
81 changes: 40 additions & 41 deletions Flow.Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,54 +77,53 @@ private void OnLoaded(object sender, RoutedEventArgs _)
switch (e.PropertyName)
{
case nameof(MainViewModel.MainWindowVisibility):
{
if (_viewModel.MainWindowVisibility == Visibility.Visible)
{
Activate();
QueryTextBox.Focus();
UpdatePosition();
_settings.ActivateTimes++;
if (!_viewModel.LastQuerySelected)
if (_viewModel.MainWindowVisibility == Visibility.Visible)
{
QueryTextBox.SelectAll();
_viewModel.LastQuerySelected = true;
Activate();
QueryTextBox.Focus();
UpdatePosition();
_settings.ActivateTimes++;
if (!_viewModel.LastQuerySelected)
{
QueryTextBox.SelectAll();
_viewModel.LastQuerySelected = true;
}

if (_viewModel.ProgressBarVisibility == Visibility.Visible && isProgressBarStoryboardPaused)
{
_progressBarStoryboard.Begin(ProgressBar, true);
isProgressBarStoryboardPaused = false;
}
}

if (_viewModel.ProgressBarVisibility == Visibility.Visible && isProgressBarStoryboardPaused)
else if (!isProgressBarStoryboardPaused)
{
_progressBarStoryboard.Begin(ProgressBar, true);
isProgressBarStoryboardPaused = false;
_progressBarStoryboard.Stop(ProgressBar);
isProgressBarStoryboardPaused = true;
}
}

if (!isProgressBarStoryboardPaused)
{
_progressBarStoryboard.Stop(ProgressBar);
isProgressBarStoryboardPaused = true;
break;
}

break;
}
case nameof(MainViewModel.ProgressBarVisibility):
{
Dispatcher.Invoke(async () =>
{
if (_viewModel.ProgressBarVisibility == Visibility.Hidden && !isProgressBarStoryboardPaused)
Dispatcher.Invoke(async () =>
{
await Task.Delay(50);
_progressBarStoryboard.Stop(ProgressBar);
isProgressBarStoryboardPaused = true;
}
else if (_viewModel.MainWindowVisibility == Visibility.Visible &&
isProgressBarStoryboardPaused)
{
_progressBarStoryboard.Begin(ProgressBar, true);
isProgressBarStoryboardPaused = false;
}
}, System.Windows.Threading.DispatcherPriority.Render);

break;
}
if (_viewModel.ProgressBarVisibility == Visibility.Hidden && !isProgressBarStoryboardPaused)
{
await Task.Delay(50);
_progressBarStoryboard.Stop(ProgressBar);
isProgressBarStoryboardPaused = true;
}
else if (_viewModel.MainWindowVisibility == Visibility.Visible &&
isProgressBarStoryboardPaused)
{
_progressBarStoryboard.Begin(ProgressBar, true);
isProgressBarStoryboardPaused = false;
}
}, System.Windows.Threading.DispatcherPriority.Render);

break;
}
case nameof(MainViewModel.QueryTextCursorMovedToEnd):
if (_viewModel.QueryTextCursorMovedToEnd)
{
Expand Down Expand Up @@ -230,10 +229,10 @@ private void OnPreviewMouseButtonDown(object sender, MouseButtonEventArgs e)
{
if (sender != null && e.OriginalSource != null)
{
var r = (ResultListBox) sender;
var d = (DependencyObject) e.OriginalSource;
var r = (ResultListBox)sender;
var d = (DependencyObject)e.OriginalSource;
var item = ItemsControl.ContainerFromElement(r, d) as ListBoxItem;
var result = (ResultViewModel) item?.DataContext;
var result = (ResultViewModel)item?.DataContext;
if (result != null)
{
if (e.ChangedButton == MouseButton.Left)
Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher/SettingWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<TabControl Height="auto" SelectedIndex="0">
<TabItem Header="{DynamicResource general}">
<ScrollViewer ui:ScrollViewerHelper.AutoHideScrollBars="{Binding AutoHideScrollBar, Mode=OneWay}" Margin="60,0,0,0">
<StackPanel Orientation="Vertical" Margin="0,30,0,0">
<StackPanel Orientation="Vertical" Margin="0,30,0,30">
<ui:ToggleSwitch Margin="10" IsOn="{Binding PortableMode}">
<TextBlock Text="{DynamicResource portableMode}" />
</ui:ToggleSwitch>
Expand Down
4 changes: 4 additions & 0 deletions Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<system:String x:Key="plugin_explorer_deletefilefoldersuccess">Deletion successful</system:String>
<system:String x:Key="plugin_explorer_deletefilefoldersuccess_detail">Successfully deleted the {0}</system:String>
<system:String x:Key="plugin_explorer_globalActionKeywordInvalid">Assigning the global action keyword could bring up too many results during search. Please choose a specific action keyword</system:String>
<system:String x:Key="plugin_explorer_windowsSearchServiceNotRunning">The required service for Windows Index Search does not appear to be running</system:String>
<system:String x:Key="plugin_explorer_windowsSearchServiceFix">To fix this, start the Windows Search service. Select here to remove this warning</system:String>
<system:String x:Key="plugin_explorer_alternative">The warning message has been switched off. As an alternative for searching files and folders, would you like to install Everything plugin?{0}{0}Select 'Yes' to install Everything plugin, or 'No' to return</system:String>
<system:String x:Key="plugin_explorer_alternative_title">Explorer Alternative</system:String>

<!--Controls-->
<system:String x:Key="plugin_explorer_delete">Delete</system:String>
Expand Down
Loading

0 comments on commit 620ed4a

Please sign in to comment.